In this post under Spring Caching, I will show with example how to enable and use caching at class level in Spring application. For our example, we will use “Calculator” class which has “calculate” method which will perform heavy calculation. It will perform summation from 1 to 1000000. We cannot perform the calculation every time,…… Continue reading Spring Caching Simple (@Cacheable) Example Class Level Part 1
Full masking of email address including delimiter
In this post under DataMask, I will show with example how to mask a email address including the delimiter. Below is the complete main class for your reference Example2 package core; import io.github.freewarelabs.datamask.core.DataFormatType; import io.github.freewarelabs.datamask.core.DataMaskManager; import io.github.freewarelabs.datamask.core.MaskInformationDTO; import io.github.freewarelabs.datamask.core.MaskType; import io.github.freewarelabs.datamask.core.exception.DataMaskException; public class Example2 { public static void main(String[] args) throws DataMaskException { MaskInformationDTO maskInformationDTO…… Continue reading Full masking of email address including delimiter
Spring Caching Simple (@Cacheable) Example Method Level
In this post under Spring Caching, I will show with example how to enable and use caching in Spring application. For our example, we will use “Calculator” class which has “calculate” method which will perform heavy calculation. It will perform summation from 1 to 1000000. We cannot perform the calculation every time, so we have…… Continue reading Spring Caching Simple (@Cacheable) Example Method Level
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
Full masking of simple text
In this post under DataMask, I will show with example how to mask a full text. Below is the complete main class for your reference Example1 package core; import io.github.freewarelabs.datamask.core.DataFormatType; import io.github.freewarelabs.datamask.core.DataMaskManager; import io.github.freewarelabs.datamask.core.MaskInformationDTO; import io.github.freewarelabs.datamask.core.MaskType; import io.github.freewarelabs.datamask.core.exception.DataMaskException; public class Example1 { public static void main(String[] args) throws DataMaskException { MaskInformationDTO maskInformationDTO = MaskInformationDTO.builder() .maskType(MaskType.FULL_MASKING)…… Continue reading Full masking of simple text
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
Junit @TempDir cleanup mode
In this post under JUnit, I will show with example how to use @TempDir different cleanup mode and what they are. Clean up mode basically tells JUnit whether to clean up the temp directory or not, at what event to cleanup etc. Out of the box, the following cleanup modes are available1) ALWAYS –> always…… Continue reading Junit @TempDir cleanup mode
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
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