Monday, March 18, 2019

jUnit Fun

jUnit and Mockito Fun

More Interesting Elements of Unit Testing and Mocking


  • Verify that a method was called on a mock

    • Verify the parameters the method was called with
  • Return a custom response from a method called on a mock, response based on the parameters of the call
    Mockito.when(myMock.save(any(Person.class))).thenAnswer(i -> {
        Person person = (MyClass) i.getArguments()[0];
        return "Hello, " + person.getFirstName();
    });

No comments: