Tags » Mockito

Verifying the order of multiple method invocations in a single instance

When multiple methods of single instance are invoked in an order in a class. We can verify the order of those method invocations using Mockito’s InOrder functionality. 200 more words

Mockito

Different ways of using thenReturn

This post shows 3 different ways of using thenReturn.

1) First way involves configuring the mock object to return only one return value as shown below… 194 more words

Mockito

Verifying the order of multiple instances method invocation

This post explains how to verify the order in which multiple instances are called. For example lets consider the below class

Class2


package package5;

public class Class2 {
    public void method1() {
        System.out.println("Class2 method1");
    }
}
… 244 more words
Mockito

Mocking a void method to throw an exception

This post will explain how to mock a public void method to throw an exception. Consider the below code

Class1


package package1;

public class Class1 {
    public void method1() {
        
    }
}
… 104 more words
Mockito

Improved matching error messages in Extended-Mockito

I’ve recently made some improvements to Extended-Mockito in the area of failure messages.

In early versions, messages from a failure to match in a verify() 161 more words

Unit Tests

Capturing multiple method arguments (using ArgumentCaptor) passed to a method in a consecutive call

This post explains how to capture multiple arguments passed to a method in a consecutive calls. Consider the below code

Class2


package package10;

public class Class2 {
    private int val;

    public void method2(int val) {
        this.val = val;
    }
}
… 272 more words
Mockito

Code Coverage

We all want to achieve 100% code coverage.  If we have 100% of our code executed in tests, we can feel confident that we are testing our code well. 529 more words

Code Quality