O'Reilly logo

Instant Mock Testing with PowerMock by Deep Shah

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding argument matchers (Medium)

Asserting that correct arguments are being passed to the method calls is as important as asserting that the correct method was invoked. PowerMock verifies the argument values using the equals method. But sometimes, we need some extra flexibility to assert that correct arguments are being passed. We can achieve this by using argument matchers. In this recipe, we will look at the effective use of argument matchers to assert that methods are invoked with correct arguments.

This is another example of how PowerMock does not reinvent the wheel. It simply uses this functionality from the underlining mocking frameworks (EasyMock and Mockito).

Getting ready

We want to add two new methods in EmployeeController:

  • findEmployeeByEmail ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required