I have built a mock object using EasyMock, and I'm trying to have the object return another object after a method call. The method call does not cause any exception to be thrown, but it returns null, though I am certain the andReturn()
call had a non-null argument.
Asked
Active
Viewed 6,515 times
1 Answers
19
The problem here was that I had not called replay()
on the mock object after specifying the behavior. For some reason, this caused it to allow some of the expected behaviors, but always return null for when a return value was expected. Remember to call replay()
before using the mock.

Zach
- 1,263
- 11
- 25
-
2note also that when you just say `andReturn()` that is only good for one call of the mocked method. You can specify the number of calls you want to return the value for using, for example, `andReturn(...).anyTimes()` – grinch Apr 15 '14 at 19:09
-
can you describe it by giving an example. I am new to spring boot – Giriraj Jan 28 '20 at 12:44