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
Month: May 2026
Conditional mapping example
In this post under MapStruct, I will show with example how to achieve conditional mapping. Till now in all my previous example, I used to configure which source property should be mapped to which target property and MapStruct would follow that. What if we want to tell MapStruct, do the mapping only if a particular…… Continue reading Conditional mapping example
Junit @TempDir method level scope
In this post under JUnit, I will show with example how applying “@TempDir” to a non-static field creates a temporary directory having method level scope. When “@TempDir” is applied to a non-static field, for every test method present in the test class, JUnit will creates different temporary directory and attaches its reference to non-static field…… Continue reading Junit @TempDir method level scope
Junit @TempDir class level scope
In this post under JUnit, I will show with example how applying “@TempDir” to a static field creates a temporary directory having class level scope. When “@TempDir” is applied to a static field, JUnit creates temporary directory and attaches its reference to static field and it exists for the entire test class lifecycle. In other…… Continue reading Junit @TempDir class level scope
Mocking Interface
In this post under Mockito, I will show with example how to create mock of an interface. For our example we will use below interface DaoI package package5; public interface DaoI { public int insert(Object object); } Below is the test class where we create a mock of “DaoI” interface Test class package package5; import…… Continue reading Mocking Interface
Mocking Abstract classes
In this post under Mockito, I will show with example how to create mock of an abstract class For our example we will use below abstract class Shape package package4; public abstract class Shape { public abstract int calculateArea(); public void display() { System.out.println("Area is:" + calculateArea()); } } Below is the test class where…… Continue reading Mocking Abstract classes