Stubbing a non-static void method to throw an exception

In this post under Mockito, I will show with example how to stub a non-static void method to throw an exception. For our example I will use the below classes. PersonDAO package package10; import java.sql.SQLException; public class PersonDAO { public void save() throws SQLException { System.out.println("Data is saved"); } } PersonManager package package10; import java.sql.SQLException;…… Continue reading Stubbing a non-static void method to throw an exception

Stubbing a non-static void method to do nothing

In this post under Mockito, I will show with example how to stub a non-static void method to do nothing. For our example, I will use the below class MyCustomLogger package package9;public class MyCustomLogger { public void info() { System.out.println("adding a and b"); } } Calculator package package9;public class Calculator { private MyCustomLogger myCustomLogger; public…… Continue reading Stubbing a non-static void method to do nothing

Stubbing a non-static void method to do something

In this post under Mockito, I will show with example how to stub a void method to execute code other than real code. For our example, I will use the below classes MyCustomLogger package package8; public class MyCustomLogger { public void info() { System.out.println("adding a and b"); } } Calculator package package8; public class Calculator…… Continue reading Stubbing a non-static void method to do something

how to call real non-static non-void method using mock object

In this post under Mockito, I will show with example how to configure Mockito to call mock object’s real non-static non-void method instead of stubbed one. For our example, we will use below classes IndianCash package package7; public class IndianCash { public double getCash() { return 10; } } IndianCash package package7; public class IndiaToUSACashConverter…… Continue reading how to call real non-static non-void method using mock object

Stubbing a non-static non-void method to return something

In this post under Mockito, I will show with example how to stub a non-static non-void method of a mock object to return a hardcoded value. For our example, we will use the below classes IndianCash package package6; public class IndianCash { public double getCash() { return 10; } } IndiaToUSACashConverter package package6; public class…… Continue reading Stubbing a non-static non-void method to return something