Guide to Testing Controllers in Spring Boot

Guide to Testing Controllers in Spring Boot

There are different ways to test your Controller (Web or API Layer) classes in Spring Boot, some provide support to write pure Unit Tests and some others are more useful for Integration Tests. Within this post, I’ll cover the main three test approaches available for Spring: using MockMVC in standalone mode, MockMVC together with SpringRunner, and using SpringBootTest.

read more

How Spring Boot auto-configuration works

How Spring Boot auto-configuration works

In this post, we’ll create a basic Spring Boot application that includes the Web dependency. Then, we’ll analyze it to see how we got an embedded Tomcat web server in our application. This way, we’ll get to know how the magic, or better the auto-configuration, works in Spring Boot.

read more

Shebang script files with Java and Docker

Shebang script files with Java and Docker

The implementation of the JEP 330: Launch Single-File Source-Code Programs available from Java 11 allows us to write a script in Java and run it as a shebang file. This is very useful for developers like me, who are not very familiar with scripting with other languages like bash or python.

In this post, I’ll show you how to write a single-file script in Java and run it from the command line. As an extra topic, you’ll learn how to put this file in a Docker image for even easier distribution of your script.

read more

Java 12’s Switch Expressions in 5 minutes

Java 12’s Switch Expressions in 5 minutes

The version 12 of Java comes with a new preview feature (amongst others): Switch Expressions. Let’s see how this feature can simplify some of our daily tasks.

Java 12 Switch Expressions
Java 12 Switch Expressions

read more