title: JavaEE: Unit test custom request wrapper
body: <p>I have a custom wrapper class around an httpServletRequest object. The purpose of the wrapper is to validate the parameters against whitelists before sending the request on through the filterChain. </p>
  
  <p>The issue I'm having is that I have overridden the getParameter method of the standard request object in the wrapper; It checks if the parameter is in a hashmap, and if so it will perform validation on the parameter using an instance of another class. How can I unit test the getParameter method, considering i cant set the query string or set parameters onto the object? I have created unit tests for the actual object(Class that utilises Esapi.Validator()) that checks if the parameter value is valid input and returns a boolean value back to the wrapper, so is it even worth my time testing the wrapper?</p>
  
  <p>TestRequestWrapper.java</p>
  
  <pre><code>public class TestRequestWrapper extends HttpServletRequestWrapper{
      private static HashMap&lt;String, EsapiParameterValidator&gt; validationMap = new HashMap&lt;String, EsapiParameterValidator&gt;();
      static{
         /* esapiParameterValidator takes the param name, 
          * name of regex in Esapi.properties, field length 
          * and boolean indicating if the parameter can be null
          */
          validationMap.put("lob", new EsapiParameterValidator("lob", "REG.lob", 3, false));
         // number of other entries
      }
  
      public TestRequestWrapper(HttpServletRequest request){
          super(request);
      }
  
      public String getParameter(String parameter){
          String value = super.getParameter(parameter);
          if(validationMap.containsKey(parameter)){
              EsapiParameterValidator epv = validationMap.get(parameter);  
              value = epv.getValidatedParam(value) ? value : "";
          }
          return value;
      }
  </code></pre>