I have a strange problem with EasyMock
This is the call I'm making which throws an IllegalStateException : Matcher expected
as expected
expect(this.mock.expectedOperation(gt(0l), MyClass.class)).andReturn(createClassObject());
If I replace the above call with
expect(this.mock.expectedOperation(gt(0l), createClass(MyClass.class))).andReturn(createClassObject());
@SuppressWarnings("unchecked")
public static <T> Class<T> createClass(Class<T> clazz)
{
return (Class<T>) EasyMock.anyObject();
}
Most times i don't get an error, but sometimes I do. It stays IllegalStateException : Matcher expected ..
Sometimes I get the IllegalStateException : 2 Matchers expected 1 recorder
error for doing this:
MyClass object = createClassObject();
expect(this.mock.expectedOperation(anyLong(), anyLong()).andReturn(object);
public MyClass createClassObject() {
// Actually sets properties and then returns
return new MyClass();
}
But it runs when I do this:
expect(this.mock.expectedOperation(anyLong(), anyLong()).andReturn(createClassObject());
In the above example, sometimes the former runs and latter fails.
Sometimes this fails :
MyClass object = createClassObject();
expect(this.mock.expectedOperation(1, MyClass.class)).andReturn(object);
I have quadruple checked the reset, replay, verify calls. These tests run sometimes and sometimes fail.
If i run my unit test, it randomly fails at least once in one of the above listed situations. Why? How do I get it running?
EDIT : I'm using EasyMock version 3.1 and
MockedClass mock = EasyMock.createMock(MockedClass.class);