Create a subclass of your servlet for your tests, where you set these 
values (in your Java code). Something like (using a Map so the pattern is 
easily reusable when you have more than one such parameter):

public class MyServletForTests extends MyServlet {
  private static final Map<String, String> INIT_PARAMETERS;
  static {
    Map<String, String> initParameters = new HashMap<String,String>();
    initParameters.put("cacheServiceLocatorClass", 
"com.myco.clearing.product.test.MockCacheServiceLocator");
    INIT_PARAMETERS = Collections.unmodifiableMap(initParameters);
  }

  @Override
  public void init(final ServletConfig config) {
    super.init(new ServletConfig() {
      public String getServletName() { return config.getServletName(); }
      public ServletContext getServletContext() { return 
config.getServletContext(); }
      public String getInitParameter(String name) {
        // you could also check if the map contains the key and fallback to 
the super implementation otherwise; it would complicate 
getInitParameterNames though
        return INIT_PARAMETERS.get(name);
      }
      public Enumeration<String> getInitParameterNames() {
        return Collections.enumeration(INIT_PARAMETERS.keySet());
      }
    }
  }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/PMhDEmDKBmoJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to