In the following article, apart from providing two solutions to the title problem, we will also talk about a few side topics. I find them worth discussing as they explain the specific behavior of SpringBoot and the H2 database when running JUnit tests.
In the first part of the guide you get know the right solution to implement thread safe singleton in Java. Then I'm going to explain to you what's wrong with the most common singleton implementation and why it is not thread safe.
Have you ever wondering how to make your application travel in time? If you have, let me tell you that’s great because in the following tutorial I’m going to show you in the real examples how to manage time for all of three test layers - unit tests, integration tests and end-to-end testing.
Let's build a coffee machine and then find out what happened if you inject a smaller scope bean into a larger scope bean. Spoiler: In the last part I'll tell you how to fix the coffee machine.
The following guide explains how to use mock in Spock Testing Framework in a proper way to get rid of unnecessary problems like NullPointerExceptions and InvalidSpecException when you try stubbing instead of mocking.
From the following guide you will learn how to configure maven project to work with Spock Testing Framework in both cases: standard Java maven project and SpringBoot maven project.
Both @PostConstruct and @PreDestroy annotations (often used in spring applications) are located in java.xml.ws.annotation package which is a part of Java EE module. J2EE has been deprecated in Java 9 and it’s scheduled to be removed…