Embracing the Messiness in Search of Epic Solutions

Tag: Java

  • 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…

  • 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…

  • Java: Programmatically Compile and Unit Test Generated Java Source Code

    In one of the projects I’m currently working on, I have to write a parser to translate a scripting language into Java code. This tutorial shows how you can unit test the generated Java code. Let’s assume we have JavaCodeGeneratorService that looks something like this:- This service class generates Java source code as one big… Read More…

  • Java: Properly Indenting XML String

    PROBLEM Let’s assume we want to perform a pretty print on the following XML string:- We have the following code to create a formatted XML string:- However, the generated output looks like just the original XML string:- Why? SOLUTION You may think the above code is wrong, but it is not. Based on the DOM… Read More…