Posts

Showing posts from 2017

JUnit 5 meets AssertJ

JUnit 5 brings a lot of improvements in the assertions library, mainly thanks to Java 8 and Lambda Expression support and thanks to the presence of the new assertions like assertAll, assertTimeout orassertThrows. Although I really like JUnit 5 I believe that AssertJ is still a must in production grade unit tests and I will continue using it. But I think there are potential scenarios of mixing both JUnit 5 and AssertJ in single unit test: one of them is mixing JUnit assertAll with AssertJ assertThat.

Asynchrouns and Transactional Event Listeners in Spring

The built-in event publication functionality exists from the early Spring versions and it is still useful for handling basic communication between Spring components in the same application context. In general, the application can generate application events (that can be arbitrary objects) and listen to them. The whole mechanism is really simple: using ApplicationPublisher you publish events and using EventListener you handle them. What I find especially useful is asynchronous and transactional event listeners.

JUnit 5 - Quick Tutorial

JUnit 5 is the next generation unit testing framework for Java equipped with many interesting features including nested tests, parameterized tests, new extension API or Java 8 support to mentioned a few. This article shows basic concepts of JUnit 5 including test lifecycle, parameter injection and assertions (basic, timeout and exception).

Spring Boot - spring.config.name - Case Study

Externalizing Spring Boot application properties is useful when the same application code must be used with different configuration. If the configuration is to be kept away from the source code (which is considered a best practice anyways)spring.config.location environment property can be used to point the directory location with properties files for example. On the other hand, spring.config.name can be used to change the base name of the properties file which defaults to application. The documentation reads: if you don’t like application.properties as the configuration file name you can switch to another. But in what scenario spring.config.name could be used?

Get started quickly with Spring 5 using Spring MVC Archetype

Spring 5 GA got released so I released the new version of Spring MVC Archetype.

Lombok - you should definitely give it a try

Lombok is not a new thing in a Java ecosystem, but I must admit I always underestimated its value until I tried it or I was “convienced” to try it. I did not see much value in adding a library that generates code that can be easily generated by any modern IDE these days. So I ignored the library and I have been writing or generating tons of boilerplate code. Not anymore. In 2016 I joined a Spring-based project where project Lombok was already in place. And since then I can’t work without Lombok anymore… Why?

Remote debugging Wildfly application in IntelliJ

Image
Remote debugging a Java application means connecting to the remotely running application using your local development environment. Java supports remote debugging out of the box: the target application must be executed with -agentlib:jdwp[=options] option which loads Java Debug Wire Protocol (jdwp) library that allows remote debugging using for example socket connection. In this short article you will learn how to get started with debugging web application deployed to Wildfly server by using IntelliJ.

Cleaner parameterized tests with JUnit 5

The general idea of parameterized unit tests is to run the same test method for different data.
Creating parameterized tests in JUnit 4 is far from being perfect. There are many issues with the existing architecture: parameters are defined as class fields and constructor is needed to create them, parameterized and non-parameterized tests cannot be mixed in one test class and built-in data sources are very limited. Fortunately, all of this is improved in JUnit 5!

Testing exceptions with JUnit 5

JUnit 5 brought pretty awesome improvements and it differs a lot from its predecessor. JUnit 5 requires Java 8 at runtime hence Lambda expressions can be used in tests, especially in assertions. One of those assertions is perfectly suited for testing exceptions.

Thymeleaf 3 Standard Layout System Improvements

Thymeleaf 3 improved Standard Layout System so that creating layouts is more flexible as ever before.

Spring Boot and Security Events with Actuator

Spring Boot Actuator provides auditing capabilities for publishing and listening to security related events in a Spring Boot application with Spring Security enabled. The default events are authentication success, authentication failure and access denied, but they can be extended with custom events.

Getting started with Thymeleaf 3 text templates

Text ((org.thymeleaf.templatemode.TemplateMode#TEXT)) templates in Thymeleaf allow creating templates with no markup. Such templates can be used to genere non-HTML content like e.g. source code, markdown files or text emails. See how easy it is to utilize text templates with Thymeleaf.

Spring Boot - Configure Log Level in runtime using actuator endpoint

As of Spring Boot 1.5 a new loggers actuator endpoint allows viewing and changing application logging levels in runtime.