I already managed to stub update():
@Test
public void updateStubbed() {
UpdatableRecordTest updatableRecordTest = spy(new UpdatableRecordTest());
doReturn(1).when(updatableRecordTest).update();
}
However, when I try to stub store():
@Test
public void storeStubbed() {
UpdatableRecordTest updatableRecordTest = spy(new UpdatableRecordTest());
doReturn(1).when(updatableRecordTest).store();
}
I get the error:
org.mockito.exceptions.misusing.WrongTypeOfReturnValue:
Integer cannot be returned by fieldsRow() fieldsRow() should return Row
If you're unsure why you're getting above error read on. Due to the nature of the syntax above problem might occur because:
- This exception might occur in wrongly written multi-threaded tests. Please refer to Mockito FAQ on limitations of concurrency testing.
- A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
How to stub store() method?