Category: Programming Language
-
Spring: Choosing the Right Dependency Injection Approach
There are many different ways to perform dependency injection (DI) in Spring. As Spring evolves over time, the DI configuration also changes over time, which may contribute to some confusion to those who are just learning Spring. Scenario Let’s assume we have this scenario: We have Team Awesome that consists of one awesome member, called Read More…
-
Spring MVC: Centralizing Common Configurations using @ControllerAdvice
Handling Exceptions using HandlerExceptionResolver Once upon a time, Spring 2.0 introduced HandlerExceptionResolver to handle thrown exceptions. While this approach works, it is like throwing a big net to catch all types of fish. If we are only interested in catching piranhas and clownfish, this approach becomes a little tedious because we need to weed out Read More…
-
Mockito: Effective Partial Mocking
Sometimes, we may only want to partially mock an object to unit test our code. There are several ways to skin this cat, but I’ll show two straightforward approaches that allow you to obtain the cat fur. PROBLEM Let’s assume we want to test this service class:- Basically, getComputedValue() sums up getFirstValue() and getSecondValue() and Read More…
-
Java: Programmatically Compile and Unit Test Generated Groovy Source Code
My previous post shows how you can programmatically compile and unit test the generated Java source code. In this example, we will programmatically compile and unit test the generated Groovy source code. Let’s assume we have the following service class that generates Groovy source code as one big String:- To unit test the generated Groovy Read More…