title: EasyMock - changing behavior for equals() and other Object methods
body: <p>The EasyMock documentation is pretty clear that</p>
  
  <blockquote>
    <p>The behavior for the three object methods equals(), hashCode() and toString() cannot be changed for Mock Objects created with EasyMock, even if they are part of the interface for which the Mock Object is created.</p>
  </blockquote>
  
  <p>The code that I'm trying to test uses equals() to compare my mock object to something else. I'd like to do something like</p>
  
  <pre><code>expect(mock.equals(obj)).andReturn(false);
  </code></pre>
  
  <p>When I do that, I get an IllegalStateException. No surprise there, given what the documentation says.</p>
  
  <p>Does anyone have any suggestions for an alternate approach? Is there another way to control what the mock object will return when equals() is called on it? I suppose that I can create a subclass that overrides equals()</p>
  
  <pre><code>class FooImplOverrideEquals extends FooImpl {
      public boolean equals;
      public boolean equals(Object obj) { return equals; }
  }
  FooImplOverrideEquals mock = createMock(FooImplOverrideEquals.class);
  mock.equals = false; // instead of expect(mock.equals(obj)).andReturn(false);
  </code></pre>
  
  <p>but this seems inelegant. I feel like I'm missing something important (like the reason why EasyMock doesn't let you override those object methods). Is there a better solution?</p>