Is it possible to add expectation after having mock object replayed?
Asked
Active
Viewed 8,635 times
10
-
As @Tom says, you can reset the mock but it might be helpful to give more context to the larger problem you're trying to solve. – jhericks Aug 27 '11 at 22:41
-
Mock object is defined and configured in parent abstract class. I receive it in my chuld class and want to add some expectations. Reset will clear the stack. – Konstantin Milyutin Aug 27 '11 at 23:30
-
Why do you have to call replay before your child class receives it? – jhericks Aug 28 '11 at 05:25
1 Answers
9
It is possible to reset a mock object and apply new expectations to it before replaying it again.
EasyMock.reset(myMock)
See the EasyMock documentation for more information.

Tom
- 4,742
- 25
- 32
-
1Mock object is defined and configured in parent abstract class. I receive it in my chuld class and want to add some expectations. Reset will clear the stack. – Konstantin Milyutin Aug 27 '11 at 23:29
-
1In which case, the answer is no. Perhaps you could define a method in the abstract class that returns the mock with its expectations set up but not in replay mode. You could then call this from your subclass and add the expectations. Alternatively, the abstract superclass could call an abstract method which you override. – Tom Aug 28 '11 at 07:50