title: java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage("title")
body: <p>I'm using EasyMock(version 2.4) and TestNG for writing UnitTest.</p>
  
  <p>I have a following scenario and I cannot change the way class hierarchy is defined.</p>
  
  <p>I'm testing ClassB which is extending ClassA.</p>
  
  <p><strong>ClassB look like this</strong></p>
  
  <pre><code>public class ClassB extends ClassA  {
  
    public ClassB()
      {
          super("title");
      }
  
      @Override
      public String getDisplayName() 
      {
          return ClientMessages.getMessages("ClassB.title");
      }
  
  }
  </code></pre>
  
  <p><strong>ClassA code</strong></p>
  
  <pre><code>public abstract class ClassA {
      private String title;
  
      public ClassA(String title)
      {
          this.title = ClientMessages.getMessages(title);
      }
  
      public String getDisplayName()
      {
          return this.title;
      }
  }
  </code></pre>
  
  <p><strong>ClientMessages class code</strong></p>
  
  <pre><code>public class ClientMessages {
      private static MessageResourse messageResourse;
  
      public ClientMessages(MessageResourse messageResourse) 
      {
          this.messageResourse = messageResourse;
      }
      public static String getMessages(String code) 
      {
          return messageResourse.getMessage(code);
  
      }
  }
  </code></pre>
  
  <p><strong>MessageResourse Class code</strong></p>
  
  <pre><code>public class MessageResourse {
      public String getMessage(String code) 
      {
          return code;
      }
  }
  </code></pre>
  
  <p><strong>Testing ClassB</strong></p>
  
  <pre><code>import static org.easymock.classextension.EasyMock.createMock;
  
  import org.easymock.classextension.EasyMock;
  import org.testng.Assert;
  import org.testng.annotations.Test;
  
  public class ClassBTest
  {
      private MessageResourse mockMessageResourse = createMock(MessageResourse.class);
      private ClassB classToTest;
      private ClientMessages clientMessages;
  
  
      @Test
      public void testGetDisplayName()
      {
  
      EasyMock.expect(mockMessageResourse.getMessage("ClassB.title")).andReturn("someTitle");
  
          clientMessages = new ClientMessages(mockMessageResourse);
  
          classToTest = new ClassB();
  
          Assert.assertEquals("someTitle" , classToTest.getDisplayName());
          EasyMock.replay(mockMessageResourse);
      }
  }
  </code></pre>
  
  <p>When I'm running this this test I'm getting  following exception:</p>
  
  <p><strong><em>java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage("title")</em></strong></p>
  
  <p>While debugging what I found is, it's not considering the mock method call
  <strong><em>mockMessageResourse.getMessage("ClassB.title")</em></strong> as it has been called from the construtor (ClassB object creation).</p>
  
  <p>Can any one please help me how to test in this case.</p>
  
  <p>Thanks.</p>