2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.test.mock.MockServletConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
MockServletConfig
100%
6/6
N/A
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.shale.test.mock;
 19  
 
 20  
 import java.util.Enumeration;
 21  
 import java.util.Hashtable;
 22  
 
 23  
 import javax.servlet.ServletConfig;
 24  
 import javax.servlet.ServletContext;
 25  
 
 26  
 /**
 27  
  * <p>Mock implementation of <code>ServletConfig</code>.</p>
 28  
  *
 29  
  * $Id$
 30  
  */
 31  
 
 32  
 public class MockServletConfig implements ServletConfig {
 33  
 
 34  
 
 35  
     // ------------------------------------------------------------ Constructors
 36  
 
 37  
 
 38  
     /**
 39  
      * <p>Construct a default instance.</p>
 40  
      */
 41  
     public MockServletConfig() {
 42  
     }
 43  
 
 44  
 
 45  
     /**
 46  
      * <p>Construct an instance associated with the specified
 47  
      * servlet context.</p>
 48  
      *
 49  
      * @param context The associated ServletContext
 50  
      */
 51  18
     public MockServletConfig(ServletContext context) {
 52  18
         setServletContext(context);
 53  18
     }
 54  
 
 55  
 
 56  
     // ----------------------------------------------------- Mock Object Methods
 57  
 
 58  
 
 59  
     /**
 60  
      * <p>Add a servlet initialization parameter.</p>
 61  
      *
 62  
      * @param name Parameter name
 63  
      * @param value Parameter value
 64  
      */
 65  
     public void addInitParameter(String name, String value) {
 66  
 
 67  
         parameters.put(name, value);
 68  
 
 69  
     }
 70  
 
 71  
 
 72  
     /**
 73  
      * <p>Set the servlet context for this application.</p>
 74  
      *
 75  
      * @param context The new servlet context
 76  
      */
 77  
     public void setServletContext(ServletContext context) {
 78  
 
 79  18
         this.context = context;
 80  
 
 81  18
     }
 82  
 
 83  
 
 84  
     // ------------------------------------------------------ Instance Variables
 85  
 
 86  
 
 87  
     private ServletContext context;
 88  18
     private Hashtable parameters = new Hashtable();
 89  
 
 90  
 
 91  
     // --------------------------------------------------- ServletConfig Methods
 92  
 
 93  
 
 94  
     /** {@inheritDoc} */
 95  
     public String getInitParameter(String name) {
 96  
 
 97  
         return (String) parameters.get(name);
 98  
 
 99  
     }
 100  
 
 101  
 
 102  
     /** {@inheritDoc} */
 103  
     public Enumeration getInitParameterNames() {
 104  
 
 105  
         return parameters.keys();
 106  
 
 107  
     }
 108  
 
 109  
 
 110  
     /** {@inheritDoc} */
 111  
     public ServletContext getServletContext() {
 112  
 
 113  
         return this.context;
 114  
 
 115  
     }
 116  
 
 117  
 
 118  
     /** {@inheritDoc} */
 119  
     public String getServletName() {
 120  
 
 121  
         return "MockServlet";
 122  
 
 123  
     }
 124  
 
 125  
 
 126  
 }