Embracing the Messiness in Search of Epic Solutions

Category: Programming Language

  • Java: Promoting Testability by Having Enum Implementing an Interface

    OVERVIEW This post illustrates how we can easily write a better test case without polluting our production code with non-production code by performing a minor refactoring to the production code. PROBLEM Let’s assume we have a simple Data Reader that reads all the lines of a given algorithm data file and returns them:- This API Read More…

  • Spock: Reading Test Data from CSV File

    Following up on my recent post about creating a Spock specification to read the test data from a CSV file without loading all the data into the memory, I created a CSVReader that implements Iterable that allows me to pull this off. You may download the source code here. With this implementation, I can now Read More…

  • Maven: Plugin Execution Not Covered by Lifecycle Configuration

    PROBLEM When running a Maven project in Eclipse or Spring Tool Suite (STS), we get an exception that is similar to this:- SOLUTION This problem stems from m2eclipse (m2e) plugin, which provides Maven support in Eclipse-based IDEs. STEP 1: Suppress the Error Message The simplest solution is to instruct m2e to silently ignore the plugin Read More…

  • Spring: Invoking Stored Procedure

    PROBLEM There are many ways to skin a cat… so is invoking a stored procedure using Spring. Let’s assume we want to invoke the following stored procedure that accepts 3 arguments (person ID, start date, end date):- This stored procedure returns a result set where each row contains a person ID, a date and a Read More…

  • Maven: Unable to Execute Spock Specs

    PROBLEM When running mvn clean test, Maven Surefire Plugin doesn’t pick up *Spec.groovy test files. SOLUTION By default, Maven Surefire Plugin is configured to execute test files with the following patterns: **/Test*.java, **/*Test.java and **/*TestCase.java. To fix this, we need to modify the inclusion list for this plugin. Since both Java and Groovy files get Read More…

  • Spring Security: Forcing URLs to use HTTPS

    PROBLEM Your web application supports both HTTP and HTTPS. You want to force all URLs to use HTTPS. SOLUTION Spring Security has a simple configuration that allows us to redirect all HTTP-based URLs to HTTPS. All we have to do is to set requires-channel=”https” on <security:intercept-url/> tag. For example:- With this configuration, when the user Read More…