Embracing the Messiness in Search of Epic Solutions

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…

  • Mac OS X: Setting Default Java Version

    Let’s assume we have installed JDK 7 or JDK 8, and we want to set the default Java version. There are several ways to set default Java version. This is by far the easiest way without the need to look for the installed path or mess around with symlinks. First, let’s make sure we are 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…

  • Puppet: Installing Multiple Java Versions On Single Node

    PROBLEM I couldn’t find an existing Puppet module that allows me to install multiple Java versions on a single node. The reason for multiple Java versions is to allow Jenkins’s jobs to choose what Java version to compile with. So, I will show you how to create a Puppet module that will do just that. 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…