Stubbing a default interface method

In this post under Mockito, I will explain how to change a default interface method implementation for testing purposes with an example. For testing purposes I have created an interface as shown below Interface1 package package6; public interface Interface1 { public default int method1(int value) { return value * 2; } } The test case…… Continue reading Stubbing a default interface method

Stubbing void methods to do nothing

This post explains how to change the implementation of void methods to do nothing for testing purposes. Below is the example Classes to be tested package package13; public class Class2 { public void method2(String value) { value = value + ” World”; } } package package13; public class Class1 { private Class2 class2; public String…… Continue reading Stubbing void methods to do nothing

Stubbing a void method to throw an exception

This post will explain how to stub a public void method to throw an exception. Consider the below code Class1 package package1; public class Class1 { public void method1() { } } Class1Test package package1; import static org.junit.Assert.fail; import org.junit.Test; import org.mockito.Mock; import org.mockito.Mockito; public class Class1Test { private Class1 class1; @Test public void testMethod1()…… Continue reading Stubbing a void method to throw an exception