3 Replies Latest reply on Sep 24, 2013 6:12 PM by Brian Leathem

    How to mock addMessage

    Juraj Balaz Newbie

      Hi there,


      I'm using jsf-mockito for testing purpose. Actually I deal with issue where I need to call real method

      addMessage instead of empty stub in MockFacesContext. Does somebody help me with this?



      thanx a lot

        • 1. Re: How to mock addMessage
          Brian Leathem Master

          How would this approach be different from creating any other mock?  Is there something special about mocking the FacesContext#addMessage method that's blocking you?

          • 2. Re: How to mock addMessage
            Juraj Balaz Newbie

            Hi Brian maybe I badly named a topic.


            what's my problem ... I created mock of FacesContext which returns MockFacesContext instance. when addMessage method is called nothing happens

            because in the MockFacesContext is this method only stubbed and it is empty.


            I tried to manage it by calling doCallRealMethod ... something like

            doCallRealMethod().when( facesContext).addMessage( facesContext.getClientId("someId"), mockedMessage );


            but this approach was unsuccessful

            • 3. Re: How to mock addMessage
              Brian Leathem Master

              I can't tell you off-hand how to use mockito to mock the FacesContext add message - perhaps someone else will chime in.


              However I can recommend that you test in a real container using Arquillian + Graphene/Warp.  The RichFaces 5 "integration" tests are good examples of how to test in a real container.  With modern/fast appservers and headless browsers like PhantomJS, these "real tests" can be quite reasonable to run both locally in your dev environment as well as in CI.