@ParameterizedTest with null values in @CvsSource

Writing parameterized tests in JUnit 4 was pretty cumbersome. JUnit 5 introduced several useful improvements to the framework and running the same test with different arguments is much simpler than in the previous version. However, there is one small issue with passing null values in such arguments.

In this post, I’m going to show you how to pass null in @CvsSource and @ValueSource for @ParametrziedTest in JUnit 5.

Continue reading “@ParameterizedTest with null values in @CvsSource”

How to bind @RequestParam to object in Spring

Do you have multiple parameters annotated with @RequestParam in a request mapping method and feel it isn’t readable?

The annotation looks pretty straightforward when there’s one or two input parameters expected in a request but when the list gets longer you might feel overwhelmed.

You cannot use the @RequestParam annotation inside objects but it doesn’t mean you’re left with no other solution. In this post, I’m going to show you how to replace multiple @RequestParams with an object.

Continue reading “How to bind @RequestParam to object in Spring”

JavaScript runtime environment

Have you just started learning JavaScript?

Or maybe you already have some language experience but want to understand JavaScript runtime in more details?

Whatever reason brought you here, there are a few elements of JavaScript runtime that you should get to know.

In this article, I’m going to show you how the JavaScript runtime environment works under the hood. You’ll learn about its elements, their responsibilities, and the way they interact with each other.

Are you ready?

If so, let’s start with the first element of the puzzle.

Continue reading “JavaScript runtime environment”

Feature toggle in Spring Boot 2

Whether you like it or not, software development is a collaborative activity. Integration work has always been demonized and treated as necessary evil. There are several approaches which try to solve the challenge of effective integration. The feature toggle belongs to that group. In this article, you’ll see in practice how feature toggles, also known as feature flags, can be used in your Spring Boot application.

Continue reading “Feature toggle in Spring Boot 2”

Java 8 Optional use cases

It’s been almost two years since Java 8 was officially released and many excellent articles about new enhancements and related best practices have been written through that time. Surprisingly, one of the more controversial topics amongst all the added features is the Optional class. The type is a container, which can be either empty or contain a non-null value. Such construction reminds the user of an Optional object that the situation when there’s nothing inside must be handled appropriately. Although the definition of the type on Javadoc is quite descriptive, when it comes to identifying valid use cases it’s getting more problematic.

Continue reading “Java 8 Optional use cases”

Sending HTML email with Spring Boot and Thymeleaf

Sending an email from the backend application part is a quite common use case in the world of enterprise applications. Although HTML content isn’t standardized message format, numerous mail clients support at least a subset of the markup language. In this post you will learn how to send an HTML email using Spring Boot standard modules and prepare an HTML content for a message using Thymeleaf template engine.

Continue reading “Sending HTML email with Spring Boot and Thymeleaf”

Custom validation annotation in Spring

Although built-in validation support in Spring is largely sufficient for standard use cases, sooner or later you will run into a situation when the sets of validation annotations provided by JSR 303 or Hibernate Validator aren’t enough. In this post you will learn how to create a simple constraint annotation served by a custom validator with access to the Spring context of a Spring Boot application.

Continue reading “Custom validation annotation in Spring”

Faster Spring Boot startup

As software developers, we always look for opportunities to improve our efficiency at work and optimize repeatable activities. One of them is application startup. Even if you cover your production code with unit tests and follow TDD, from time to time checking how the whole application works is inevitable. The more often you run it, the more time is wasted on waiting until the application is ready to operate.

Although the fast restart provided by Spring Boot DevTools is helpful for library class loading, it doesn’t solve the issue with the long startup of your own application code. From this post you will learn how to decrease the total number of coffee breaks in daily work by configuring faster Spring Boot startup in your local development environment.

Continue reading “Faster Spring Boot startup”

Why developers don’t use TDD

Although the total number of acronyms in the programing industry has probably already exceeded the number of stars observable on the moonless night sky, only a subset has gained popularity and recognition. TDD definitely belongs to this group. Judging by numerous conference lectures, books, podcasts, and blog posts, the fact that Test Driven Development is a widely known technique is rather undeniable. Yet, when you consider its adoption and actual usage the reality might look a bit different. In this article we will take a look at the different reasons for avoiding TDD that have been presented by candidates during several conducted technical interviews and try to disprove if they are real obstacles.

Continue reading “Why developers don’t use TDD”