Embracing the Messiness in Search of Epic Solutions

Month: February 2014

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