Unit Testing Spring apps with @RunWith(SpringJUnit4ClassRunner.class)

Thursday, June 24th, 2010

The Problem

I love Spring, who doesn’t?

One thing however that I found, until recently, a bit awkward was Unit Testing objects which were constructed and initiated via the Spring context and injected into other objects that consumed them. I have seen and used many and varied “bespoke” ways to do this, none of which I found satisfying.

This was until a collegue introduced me to the wonder that is SpringJUnit4ClassRunner. I know, I know, I should have been aware of this ages ago but as they say on millionaire “it’s easy if you know the answer”!

Read More »

Tags: , ,
Posted in Examples | No Comments »

Ibatis TypeHandlerCallback Enum Example

Friday, June 11th, 2010

Problem

You need Ibatis to perform custom processing before parameters are set on a Prepared Statement or after the results are retrieved from the result set. Maybe to convert Y/N to boolean, map results to custom objects etc

Solution

You probably want to look at implementing Ibatis’ TypeHandlerCallBack, the API docs for which are here

Read More »

Tags: ,
Posted in Examples | No Comments »

Java 5 Enum Example

Thursday, June 10th, 2010

Description

This simple example of a Java 5 Enum models a PREV/NEXT you might commonly see in a web app.

package foo.bar;

public enum PagingCriteriaDirection {
    NEXT("Next"), PREV("Previous");

    private String description;

    private PagingCriteriaDirection(String desc){
        description = desc;
    }

    public String getDescription() {
    	return description;
    }

    @Override
    public String toString() {
    	return description;
    }
}

Tags:
Posted in Development, Examples | 1 Comment »

JUnit 4 Test Class with annotations

Tuesday, June 8th, 2010

A simple example of a JUnit 4 Test class marked up with annotations.

Read More »

Tags: , ,
Posted in Examples | No Comments »

JAXB @XmlAnyElement example

Monday, June 7th, 2010

The problem

I was recently working on a JAXB centric app which was required to capture “arbitary” xml. e.g.

<a>
   <b></b>
   <c></c>
   <d>
       <!-- "Unknown" XML here -->
       <maybee></maybee>
       <maybef></maybef>
       <!-- etc etc -->
   <d />
</d></a>

How could I ever capture the contents of if they could be “anything”?

Read More »

Tags: , , ,
Posted in Development, quick tips | No Comments »