IllegalStateException: incompatible return value type
Brought to you by:
tammofreese
The following code leads to an "java.lang.IllegalStateException: incompatible return value type"
in the second expect call.
public static class MockTestGetLong {
public Long getLong() { return 1l; }
}
public void testEasyMock() {
MockTestGetLong mock1 = createMock(MockTestGetLong.class);
expect(mock1.getLong()).andReturn(2l);
expect(mock1.toString()).andReturn("foo");
}
The cause is that the first call (getLong()) sets the return type of the state object for the last call to Long. But the second call (toString()) does not set the return type of the state object thus causing the second call to andReturn fails to fail since it expects a Long but gets a String.
This is because toString can't be mocked. So EasyMock in fact is seeng this
expect(mock1.getLong()).andReturn(2l).andReturn("foo");
because the second expect is ignored. However, I might be able to throw an error when an expect is called on something wrong.
see http://jira.codehaus.org/browse/EASYMOCK-36