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 the Answer interface (Advanced)

In some edge cases, it might be impossible or impractical to create the mocks by simply using the PowerMockito.when().thenReturn() syntax. In such cases, the generic Answer interface could be very handy.

In this recipe, we will learn how to make use of the Answer interface to create some unusual mocking strategies.

Getting ready

Remember the EmployeeController.findEmployeeByEmail method we saw in the previous recipe? We are going to write one more test for that method in this recipe.

How to do it...

  1. The requirement is as follows:
    • A valid employee would be found if the e-mail starts with deep
    • Or, if the e-mail address ends with packtpub.com
  2. We can certainly use a custom argument matcher to write this test, ...

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