Coverage Report - org.seasar.cubby.unit.MockFilterConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
MockFilterConfig
58%
7/12
50%
1/2
1.167
 
 1  
 /*
 2  
  * Copyright 2004-2010 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 
 17  
 package org.seasar.cubby.unit;
 18  
 
 19  
 import java.util.Enumeration;
 20  
 import java.util.Properties;
 21  
 
 22  
 import javax.servlet.FilterConfig;
 23  
 import javax.servlet.ServletContext;
 24  
 
 25  
 import org.junit.Assert;
 26  
 
 27  
 /**
 28  
  * {@link FilterConfig} のモック。
 29  
  * 
 30  
  * @author baba
 31  
  */
 32  
 class MockFilterConfig implements FilterConfig {
 33  
 
 34  
         private final ServletContext servletContext;
 35  
 
 36  
         private final String filterName;
 37  
 
 38  5
         private final Properties initParameters = new Properties();
 39  
 
 40  
         /**
 41  
          * Create a new MockFilterConfig.
 42  
          * 
 43  
          * @param servletContext
 44  
          *            the ServletContext that the servlet runs in
 45  
          */
 46  
         public MockFilterConfig(ServletContext servletContext) {
 47  5
                 this(servletContext, "");
 48  5
         }
 49  
 
 50  
         /**
 51  
          * Create a new MockFilterConfig.
 52  
          * 
 53  
          * @param servletContext
 54  
          *            the ServletContext that the servlet runs in
 55  
          * @param filterName
 56  
          *            the name of the filter
 57  
          */
 58  5
         public MockFilterConfig(ServletContext servletContext, String filterName) {
 59  5
                 this.servletContext = (servletContext != null ? servletContext
 60  
                                 : new MockServletContext());
 61  5
                 this.filterName = filterName;
 62  5
         }
 63  
 
 64  
         /**
 65  
          * {@inheritDoc}
 66  
          */
 67  
         public String getFilterName() {
 68  0
                 return filterName;
 69  
         }
 70  
 
 71  
         /**
 72  
          * {@inheritDoc}
 73  
          */
 74  
         public ServletContext getServletContext() {
 75  0
                 return servletContext;
 76  
         }
 77  
 
 78  
         /**
 79  
          * {@inheritDoc}
 80  
          */
 81  
         public String getInitParameter(String name) {
 82  0
                 Assert.assertNotNull(name, "Parameter name must not be null");
 83  0
                 return this.initParameters.getProperty(name);
 84  
         }
 85  
 
 86  
         /**
 87  
          * {@inheritDoc}
 88  
          */
 89  
         @SuppressWarnings("unchecked")
 90  
         public Enumeration getInitParameterNames() {
 91  0
                 return this.initParameters.keys();
 92  
         }
 93  
 
 94  
 }