2 Replies Latest reply on Mar 9, 2006 8:52 PM by Sebastien Guimont

    Have FacesMessages implements an interface

    Sebastien Guimont Newbie

      It is possible to have the FacesMessages class implements an interface because I want to make unit test on my bean with EasyMock (http://www.easymock.org/) library and this library can only mock an interface.

      Code to test:

      @Name("action")
      @Interceptors(SeamInterceptor.class)
      public class Action implements IAction {
       @In(create = true)
       private FacesMessages facesMessages;
      
       public void addErrorMessage(String aMessageKey) {
       this.facesMessages.add(FacesMessage.SEVERITY_INFO, "${" + aMessageKey + "}");
       }
      
       protected void setFacesMessages(FacesMessage aFacesMessages) {
       this.facesMessages = aFacesMessages;
       }
      


      Test code.
      public class ActionUnitTest extends TestCase {
      
       private Action classUnderTest;
       private FacesMessages mockFacesMessages;
      
       public void testAddErrorMessage() {
       // Setup
       expect(this.mockFacesMessages.add("${test.key}"));
       replay(this.mockFacesMessages);
      
       // Execute test
       this.classUnderTest.addErrorMessage("test.key");
      
       // Verify
       verify(this.mockFacesMessages);
       }
      
       protected void setUp() throws Exception {
       this.mockFacesMessages = createMock(FacesMessages.class); // EXCEPTION Cause an exception because the class is not an interface
       this.classUnderTest = new Action();
       this.classUnderTest.setFacesMessages(this.mockEntityManager);
       }
      }
      


      Thanks,