1 Reply Latest reply on Nov 17, 2011 1:58 PM by lfryc

    JSFMock and ExternalContext

    oranheim

      What's the right approach in getting MockFacesEnvironment to return ExternalContext for the current FacesContext. I know that that it is possible to call createEnvironment().withExternalContext(), but my goal is not to obtain a reference to the ExternalContext from the MockFacesEnvironment directly.

       

      To make JSFMock work with Seam Faces and CDI it's required to have an instance returned from FacesContext, and not from MockFacesEnvironment.

       

      MockFacesEnvironment env = MockFacesEnvironment.createEnvironment().withExternalContext();
      Assert.assertNotNull(env.getFacesContext().getExternalContext());
      

       

      I have tried this without  success:

       

      MockFacesEnvironment env = MockFacesEnvironment.createEnvironment();
      FacesContext facesContext = env.getFacesContext();
      ExternalContext externalContext = Environment.createMock(ExternalContext.class);
      EasyMock.expect(facesContext.getExternalContext()).andReturn(externalContext);
      

       

      The facesContext.getExternalContext() returns null.

       

      It would be great to make this happen, because it'd be really helpful when using it for CDI and Arquillian testing.