In this post under JUnit, I will show with example the purpose of “assertThrowsExactly” method and how it is different with “assertThrows” method. I have explained with example, the purpose of “assertThrows” static method in previous posts. For recap, “assertThrows” method asserts that the test method throws the expected exception. If the test method doesn’t…… Continue reading assertThrows vs assertThrowsExactly example
IllegalRegexRule example
In this post under Passay, I will explain with example the purpose of “IllegalRegexRule” class. In one of my previous post, I have explained with example the purpose of “AllowedRegexRule” class. We will have recap of it here. When validating password, we mainly check whether the password follows a particular pattern. If the password follows…… Continue reading IllegalRegexRule example
beforeAll and afterAll annotation
In this post under JUnit, I will explain with example the purpose of “beforeAll” and “afterAll” annotations. In the previous post under JUnit, I covered about “beforeEach” and “afterEach” annotation. Similarly to “beforeEach” and “afterEach”, “beforeAll” and “afterAll” is applied to methods. But methods annotated with “beforeEach” and “afterEach” annotations are executed before and after…… Continue reading beforeAll and afterAll annotation
Custom Canonical constructor in Record
In the previous post under Java Record, I mentioned how the compiler creates a long (canonical) constructor automatically. In this post, I will explain how to create a custom canonical constructor. Now why we need to provide a custom canonical constructor when it is already provided by compiler. The canonical constructor created by compiler will…… Continue reading Custom Canonical constructor in Record
Collections checkedCollection example
In this post under Java, I will explain with example the purpose of Collections “checkedCollection” method. From Java 5 onwards, we started using Generics to ensure compile time type safety. As a result of which we were unable to add element of one data type to collections of elements of another data type. At compile…… Continue reading Collections checkedCollection example
Collections indexOfSubList method
In this post under Java Core, I will explain with example the pupose of Collections’ “indexOfSubList” method. Lets say they are two lists list1 and list2. “indexOfSubList” will search in list1 for position from where the elements of “list2” are repeated in “list1”. Once the position is found it is returned as index. In other…… Continue reading Collections indexOfSubList method
Skipping mapping of particular attribute
In this post under MapStruct, I will show with example how to configure MapStruct to skip particular attribute mapping from source to destination. For our example I will use the below pojo classes as shown below Student package package3; public class Student { private int id; private String name; private String className; public int getId()…… Continue reading Skipping mapping of particular attribute
AllowedRegexRule example
In this post under Passay, I will explain with example the purpose of “AllowedRegexRule” class. When validating password, we mainly check whether the password follows a particular pattern. If the password follows the pattern it is valid or else invalid. We use regular expressions, to create that pattern. “AllowedRegexRule” class will do the job of…… Continue reading AllowedRegexRule example
Collections replaceAll method
In this post under Java Collections, I will explain with example the purpose of Collections “replaceAll” method. This method replaces all occurrences of a particular element with its replacements. This method can be used only with “List” data structure. Below is the main class showing an example Main class 1 package core.collection; 2 3 import…… Continue reading Collections replaceAll method
Java Comparable interface
In this post under Java Collections, I will explain with example the purpose of “Comparable” interface. Before we understand “Comparable” interface we need to understand the difference between “ordered” and “sorted” collections. In Ordered collections, elements are placed in a collection according to insertion order or according to some order and the order is not…… Continue reading Java Comparable interface