コード例 #1
0
 /**
  * Initialize feature with currenct mocked environment
  *
  * @param feature the feature
  */
 private void initializeFeature(Environment.Feature feature) {
   switch (feature) {
     case FACTORIES:
       environment.withFactories();
       break;
     case APPLICATION:
       environment.withApplication();
       break;
     case EL_CONTEXT:
       environment.withELContext();
       break;
     case EXTERNAL_CONTEXT:
       environment.withExternalContext();
       break;
     case RENDER_KIT:
       environment.withRenderKit();
       break;
     case RESPONSE_WRITER:
       environment.withResponseWriter();
       break;
     case SERVLET_REQUEST:
       environment.withServletRequest();
       break;
     default:
       break;
   }
 }
コード例 #2
0
 /**
  * Tries to get mock for given type.
  *
  * <p>Before injecting, it initializes all dependencies needed by given mock type by initializing
  * given feature.
  *
  * @param type the JSF class type to initialized and inject
  * @return the injection or null if given type ais unknown
  */
 private Object getInjection(Class<?> type) {
   if (type == MockFacesEnvironment.class) {
     return environment;
   }
   if (type == FacesContext.class) {
     initializeFeature(FACES_CONTEXT);
     return environment.getFacesContext();
   }
   if (type == Application.class) {
     initializeFeature(APPLICATION);
     return environment.getApplication();
   }
   if (type == ELContext.class) {
     initializeFeature(EL_CONTEXT);
     return environment.getElContext();
   }
   if (type == ApplicationFactory.class) {
     initializeFeature(FACTORIES);
     return environment.getApplicationFactory();
   }
   if (type == ServletContext.class) {
     initializeFeature(SERVLET_REQUEST);
     return environment.getServletContext();
   }
   if (type == ExceptionHandlerFactory.class) {
     initializeFeature(FACTORIES);
     return environment.getExceptionHandlerFactory();
   }
   if (type == ExternalContext.class) {
     initializeFeature(EXTERNAL_CONTEXT);
     return environment.getExternalContext();
   }
   if (type == ExternalContextFactory.class) {
     initializeFeature(FACTORIES);
     return environment.getExternalContextFactory();
   }
   if (type == FacesContextFactory.class) {
     initializeFeature(FACTORIES);
     return environment.getFacesContextFactory();
   }
   if (type == LifecycleFactory.class) {
     initializeFeature(FACTORIES);
     return environment.getLifecycleFactory();
   }
   if (type == PartialViewContextFactory.class) {
     initializeFeature(FACTORIES);
     return environment.getPartialViewContextFactory();
   }
   if (type == RenderKit.class) {
     initializeFeature(RENDER_KIT);
     return environment.getRenderKit();
   }
   if (type == RenderKitFactory.class) {
     initializeFeature(FACTORIES);
     return environment.getRenderKitFactory();
   }
   if (type == HttpServletRequest.class) {
     initializeFeature(SERVLET_REQUEST);
     return environment.getRequest();
   }
   if (type == HttpServletResponse.class) {
     initializeFeature(SERVLET_REQUEST);
     return environment.getResponse();
   }
   if (type == ResponseStateManager.class) {
     initializeFeature(RENDER_KIT);
     return environment.getResponseStateManager();
   }
   if (RecordingResponseWriter.class.isAssignableFrom(type)) {
     initializeFeature(RESPONSE_WRITER);
     return environment.getResponseWriter();
   }
   if (type == TagHandlerDelegateFactory.class) {
     initializeFeature(FACTORIES);
     return environment.getTagHandlerDelegateFactory();
   }
   if (type == ViewHandler.class) {
     initializeFeature(APPLICATION);
     return environment.getViewHandler();
   }
   return null;
 }
コード例 #3
0
 /**
  * Run after each test
  *
  * @param target the target test instance
  */
 protected void runAfter(Object target) {
   environment.release();
   environment = null;
 }