In this post under JUnit, I will explain with example the purpose of “TestInstance” annotation. By default when we execute a test class, for each test method, a separate instance of test class is created. Lets see an example. For our example I will create the below “Calculator” class that has to be tested. Calculator…… Continue reading @TestInstance example
Author: sumanthprabhakar
AssertAll Example
In this post under JUnit 5, I will show with example the purpose of “assertAll” method. Pre JUnit 5, If a testcase had multiple assert statements, the testing of that testcase would stop immediately at the first assert statement that fails. So for example if we have below test method public void testMethod() { assert1…… Continue reading AssertAll Example
Object Pool addObject method example
In this post under Apache Pool, I will explain with example the purpose of “addObject” method in Apache Pool. In Apache Pool we can create three types of object Pool1) GenericObjectPool2) GenericKeyedObjectPool3) SoftReferenceObjectPool All these classes support “addObject” method. Now lets understand the purpose of this method. If you refer to all my previous post,…… Continue reading Object Pool addObject method example
Configuring Generic Object Pool
In this post under Apache Pool, I will show how to create GenericObjectPool instance with custom configuration In all post under Apache Pool, I showed how to create GenericObjectPool using default configuration. When we use the below code snippet, we are creating an object pool with default configuration. GenericObjectPool<Thread> genericObjectPool = new GenericObjectPool<Thread>(threadPooledObjectFactory); To change…… Continue reading Configuring Generic Object Pool
Creating a soft reference object pool
In this post under Apache Pool, we will explain with example how to create soft reference object pool. For our example we will create the below thread factory class that extends Apache Pool framework’s “BasePooledObjectFactory” class. package package6;import org.apache.commons.pool2.BasePooledObjectFactory;import org.apache.commons.pool2.PooledObject;import org.apache.commons.pool2.impl.DefaultPooledObject;public class ThreadPooledObjectFactory extends BasePooledObjectFactory<Thread> { private int count = 0; @Override public Thread create()…… Continue reading Creating a soft reference object pool
Getting number of active and idle objects in object pool
In this post under Apache Pool, I will explain with example how to retrieve number of active and idle objects in object pool. For our example I will create the below factory class which extends Apache Pool’s “BasePooledObjectFactory” class. package package5;import org.apache.commons.pool2.BasePooledObjectFactory;import org.apache.commons.pool2.PooledObject;import org.apache.commons.pool2.impl.DefaultPooledObject;public class ThreadPooledObjectFactory extends BasePooledObjectFactory<Thread> { private int count = 0; @Override…… Continue reading Getting number of active and idle objects in object pool
Setting startup timeout
In this post under TestContainers, I will show with example how to setup startup timeout. Whenever we start a container whether through programmatically or through Docker Desktop or any other container management software, it takes time to start. TestContainers to figure out whether a container has started or not, it waits for 60 sec so…… Continue reading Setting startup timeout
Retrieve environment values present in file
In previous posts under DotEnv, whenever we called static “load” method on “DotEnv” class it used to load system environment values in addition to environmentvalues present in .env or .env file with custom name. What if we want only the environment values present in the file and not the system environment values. There is way…… Continue reading Retrieve environment values present in file
Accessing an non existing environment key
In this post under DotEnv, I will show with example how to handle retrieving values of environment keys that doesn’t exist. Below is the main class for your reference. Main class 1 package defaultPackage;2 3 import io.github.cdimascio.dotenv.Dotenv;4 5 public class Example6 {6 public static void main(String[] args) {7 Dotenv dotenv = Dotenv.load();8 String value =…… Continue reading Accessing an non existing environment key
Using @Value example
In all my previous posts under Lombok, I used Pojo classes as an example. All these Pojo classes are mutable since they have setter and getter method. In this post, I will show with example how to create an immutable class. To create an immutable class, we annotate a Pojo class with “@Value” annotation and…… Continue reading Using @Value example