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
Junit @TempDir annotation
In this post under Junit, I will show with example the purpose and how to use @TempDir annotation. Lets say you have written class that zip the input file as shown below FileZip package package20; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class FileZip { public void zip(File inputFile) throws Exception…… Continue reading Junit @TempDir annotation
Using @InjectMocks annotation
In this post under Mockito, I will show with example the purpose of “@InjectMocks” annotation. In the previous post, I showed with example, the purpose of “@Mock” annotation. For recap “@Mock” annotation is used to instruct Mockito framework to create a mock of an object and assign it to variable. We write unit test class…… Continue reading Using @InjectMocks annotation
Using @Mock annotation
In my previous post under Mockito, I showed you with example how to manually create a mock. In this post under Mockito, I will show with example how to tell Mockito to create a mock and assign the reference to a variable. To tell Mockito framework to create a mock of a class and assign…… Continue reading Using @Mock annotation
Calling custom mapping method from another mapper interface code
In this post under MapStruct, I will show with example how to call custom mapping method from another mapper interface code. In previous post, I showed you how to add custom mapping method to a mapper interface. But what if the same custom mapping method is also required by another mapper interface, we cannot copy…… Continue reading Calling custom mapping method from another mapper interface code
Creating a mock
In this post under Mockito, I will show with example how to create a mock of a class. For our example I will use the “Calculator” class with below structure. Calculator package package1; public class Calculator { public int add(int x, int y) { return x + y; } public int multiple(int x, int y)…… Continue reading Creating a mock
Custom Compact constructor in Record
In this post under Java Record, I will explain with example what is custom compact constructor, what is the use and how to add them in Record. In the previous post under Java Record, I showed what is canonical constructor, what is custom canonical constructor and what is the purpose of it. Below are the…… Continue reading Custom Compact constructor in Record
Text Block With Indentation
In this post under Java Core, I will show you with example how indentation is calculated in Text Block. Below is the main class with three variety of text block. Example3 package core.string; public class Example3 { public static void main(String[] args) { String textBlock1 = """ <html> <head> <title>TextBlock1<title> </head> <body>Body of TextBlock1</body> </html>…… Continue reading Text Block With Indentation
Text Block simple example
In this post under Java Core, I will introduce you to newly added “Text Block” feature. This feature was added as part of Java 15. Pre Java 15, if we have to declare a multiline string we used to declare it as shown below String result = "Since Java 15, text blocks are \n" +…… Continue reading Text Block simple example