Andrez Segovia

TIL (6)

The @DirtiesContext Spring Annotation

In some test scenarios, a Spring Bean can become corrupted, causing other test scenarios to fail. To prevent this, we can annotate a test class or test method with @DirtiesContext, which tells the Spring Framework that the ApplicationContext is dirty, forcing the rebuilding of the Spring container and creating a new bean instances.

Working with Beans in Spring Framework

A JavaBean is a standard Java class with getter/setter methods, a no-arg constructor, and is serializable. And a Spring Bean is any Java object managed by Spring and can be automatically injected into other components. The Spring Dependency injection allows Spring to manage and inject beans where needed.

Validate the arguments passed to a method

The Mockito framework has the ArgumentCaptor class that can be use to validate the arguments passed to a mocked method.

Formatting JSON returned by cURL in the terminal

Install the jq package:

macOS:

brew install jq

Linux:

sudo apt-get install jq

How to use it:

The differences between List.of and Arrays.asList

This StackOverflow answer explains the different between List.of and Arrays.asList.

Find All Letters Event Grave And Acute Ones With a Regular Expression

String value = "a Á á É é Í 8 . - ? í Ó ó Ú ú ü / ! ¿";  
  
Stream.of(value.split("")).filter(s -> s.matches("\\p{L}"))  
        .forEach(System.out::printf);

//ÁaáÉeéÍiíÓóoOÚúü

The regular expression uses a Unicode character class escape with a General category property for filter only the letters.