0

I have a method returning void and I know how to verify if the method has been called:

MyValidator validator = createMock(MyValidator.class);      
expect(validator.validate());
replay(validator);
classUnderTest.submit(); //this will call validator.validate()
verify(validator);

But I also want the real method MyValidator.validate() to be executed. How can I achieve this?

user1414745
  • 1,317
  • 6
  • 25
  • 45

1 Answers1

0

I've never used it, but andDelegateTo() seems to be exactly what you want:

MyValidator realValidator = new MyValidator();
MyValidator mockedValidator = createMock(MyValidator.class);
expect(mockedValidator.validate()).andDelegateTo(realValidator);
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255