0

I've got the following method

public void myMethod(final MyObject myObject) {
   if (myObject.isDownload()) {
      // Do something
   } else {
      super.myMethod();
   }
}

I want to verify now in a JUnit test, that the super implementation has been called.

I also want to abort the test, if the super call has been performed, since the underlying implementation is very complicated and hard to test respectively mock.


I'm using Mockito as a mocking framework.

1 Answers1

0

That sounds like a perfect use case for a mocking framework. Just mock your implementation of super in a way that it does nothing on a call to myMethod(). Verify that myMethod() was called on your mock in the unit test.

You could give Mockito a try. But there are several other good mocking frameworks for Java.

tobiasbayer
  • 9,921
  • 4
  • 42
  • 64