Middle masking of delimited text without configuring delimiter

In this post under DataMask, I will show with example how to do middle masking of delimited text including masking of delimiter. So if the text is “1111-2222-3333-4444”, the output should be “111**********3-4444”. The delimiter “-” is also masked, it is not excluded. Below is the complete main class Main class package core; import io.github.freewarelabs.datamask.core.DataFormatType;…… Continue reading Middle masking of delimited text without configuring delimiter

Creating custom cache key using KeyGenerator interface

In all my previous posts under Spring Caching, I have used Java primitive types and String as cache key. In this post under Spring Caching, I will show with example how to create custom cache key. To create a custom cache key we need to implement Spring interface “KeyGenerator” and provide the logic that creates…… Continue reading Creating custom cache key using KeyGenerator interface

var variable value can change but not datatype

In this post under Java language, I will introduce you to one of the restrictions that apply to var variable. In the previous post under Java language, I introduce you guys to var variable (local variable type inference variable) and also covered some restrictions to remember when declaring var variable. But didn’t covered this restriction…… Continue reading var variable value can change but not datatype

Local Variable Type Inference (var) example

In this post under Java language, I will introduce you to Local Variable Type Inference (also called var variable) added in Java 10. Before java 10, any variable declared should be accompained with the data type as shown below int sum; float salary; String name; As shown in the above code, the “int” is the…… Continue reading Local Variable Type Inference (var) example

Stubbing a non-static non-void method to return multiple values for consecutive calls

In this post under Mockito, I will show with example how to stub a mock object’s non-static non-void method to return different values when called consecutively. For our example, we will use the below class MyRandom package package11; import java.util.Random; public class MyRandom { private Random random; public MyRandom() { random = new Random(); }…… Continue reading Stubbing a non-static non-void method to return multiple values for consecutive calls

Accessing return value of method execution while vetoing caching using SpEL

In the previous post under Spring Caching, I have shown how to veto caching but didn’t mention that we can also access the method return value or result in making that decision. In this post under Spring Caching, I will show how to do that. For our example, I will use the below class Calculator…… Continue reading Accessing return value of method execution while vetoing caching using SpEL

Side masking of delimited text without configuring delimiter

In this post under DataMask, I will show with example how to do side masking of delimited text including masking of delimiter. So if the text is “1111-2222-3333-4444”, the output should be “***1-2222-333******”. The delimiter “.” is also masked, it is not excluded. Below is the complete main class Main class package core; import io.github.freewarelabs.datamask.core.DataFormatType;…… Continue reading Side masking of delimited text without configuring delimiter

Vetoing caching using SpEL

In this post under Spring Caching, I will show with example how to veto caching using SpEL. In previous posts I showed you how to use “@Cacheable” annotation. In that annotation itself there is an attribute that we can use to vetoing caching. That attribute name is “unless” and it takes as SpEL expression as…… Continue reading Vetoing caching using SpEL

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