Monday, 31 October 2011

Maintaining Separation of Concerns when using a JSP Front Strategy MVC Pattern.

My last MVC blog tried to add a little depth into exactly what the MVC pattern is in relation to web-applications, and in writing it I highlighted the problems and pitfalls of using a JSP Front Strategy as an MVC front controller pattern. To sum this up, although favoured by some organisations, it seems to me that using JSP Front Strategy makes it all too easy to mix the controller logic, view information together with the model in the wrong place, which results in nothing more than a plate of indecipherable spaghetti code.

So, I thought that I’d investigate a technique for implementing the JSP front strategy without creating a dog’s dinner and try to sort out a few rules that can be applied if you ever find yourself working on, what is after all, obsolete technology.

Friday, 28 October 2011

Autowiring Property Values into Spring Beans

Most people know that you can use @Autowired to tell Spring to inject one object into another when it loads your application context. A lesser known nugget of information is that you can also use the @Value annotation to inject values from a property file into a bean’s attributes.

Wednesday, 26 October 2011

Everybody Knows About MVC...

From a recent blog, you may have gathered that I’ve recently been conducting some interviews and as they were for web application developers a question I asked was “can you explain what the MVC pattern is?”, and to their credit, every candidate knew the answer.

Monday, 24 October 2011

Testing an Object's Internal State with PowerMock

Most unit testing focuses on testing an object’s behaviour in order to prove that it works. This is achieved by writing a JUnit test that calls an object’s public methods and then testing that the return values from these calls match some previously defined set of expected values. This is a very common and successful technique; however, it shouldn't be forgotten that objects also exhibit state; something that is, by virtue of the fact that it’s hidden, often overlooked.

Friday, 21 October 2011

Intermittent ORA-12519 error on 10g XE

There’s an Oracle error that seems to raise its ugly head every now and again and it occurs on Oracle 10g Express Edition running under 32 bit Windows (which in my case was XP). It happened to me after transferring my test Oracle database from a real to a virtual copy of Windows XP, and when running a series of unit tests on a database module.

The error manifests itself as an ORA-12519 connection refusal error as highlighted by the following partial stack trace:

java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.T4CConnection.logon(
at oracle.jdbc.driver.PhysicalConnection.(

The suggested fix, and this was written two years ago, is to increase the number of available processes by logging on as SYS and issuing the following command:


…which doesn’t seem like a real fix to me as it just pushes the problem further away.

Yes, I know that Oracle 10g is obsolete and the 11g Express Edition is freely available, but 11g adds yet another layer of unwanted complexity to my requirement for a simple Oracle database.

Wednesday, 19 October 2011

Why Use PowerMock to Mock Private Methods?

So far I’ve written a couple of blogs on PowerMock covering some of what I think are its most useful features. Today’s blog takes a look at PowerMock’s ability to mock private methods. At first this struck me as a pretty useless idea. The PowerMock documentation says that you can use it to mock private methods that are called many times during your build process so that you only test them once. My first reaction was does it matter whether or not you execute a piece of code once or a thousand times during a set of unit tests? Usually the answer will be ‘no’ and this feature will be pretty superfluous. However, there is a scenario where is come come in very handy...

Monday, 17 October 2011

Using PowerMock to Mock Constructors

In my opinion, one of the main benefits of dependency injection is that you can inject mock and/or stub objects into your code in order to improve testability, increase test coverage and write better and more meaningful tests. There are those times, however, when you come across some legacy code that doesn’t use dependency injection and held together by composition rather than aggregation.

Friday, 14 October 2011

Top Trumps in God Objects

If we were playing the children’s game Top Trumps with Java interface definitions I think that I’d win every time. That’s because I’ve just found an interface, which is part of a prestigious company’s public API with with 167 methods. Trump that! Imagine, if the interface definition contains 167 methods, how big is the implementation class? In the words of a texting teenager “OMG”.

You’ll probably know that objects that are as out of control as this are usually called God Objects or Monster Objects and there’s an anti-pattern of the same name which explains it all. If you look on at various definitions of the God Object Anti-Pattern, they usually say a god object is an object that “knows too much or does too much”1, words which seem to crop up all too often if you dig around the internet. In modern programming speak this generally means that a god object:

Wednesday, 12 October 2011

Using PowerMock to Mock Static Methods

In a recent blog, I tried to highlight the benefits of using dependency injection and expressing the idea that one of the main benefits of this technique is that it allows you to test your code more easily by providing a high degree of isolation between classes, and coming to the conclusion that lots of good tests equals good code. But, what happens when you don’t have dependency injection and you’re using a third party library that contains classes of a certain vintage that contains static methods?

Monday, 10 October 2011

The Benefits Of Dependency Injection

Dependency Injection is the way to go, so say the Guys at Spring, and who am I to argue with them, after all it sounds like a sensible idea. But, how many developers have ever stopped to figure out why?

Friday, 7 October 2011

Installing the EGit component in Eclipse

The ever increasing popularity of Git seems to know no bounds, which is not bad for something that’s named after a British English insult that’s only slightly more venomous than “idiot”1. Being popular, there is an eclipse plug in available and this short blog covers how to install it.

Thursday, 6 October 2011

Looking into the Magic of Dependency Injection Using Annotations - Part 4

This is the fourth and last in a short series of blogs that looks into implementing dependency injection using annotations. The previous three blogs on this subject have covered:
Today’s blog ties up all the loose ends and does produce a limited, but fully functional, dependency injection factory class based upon annotations.

Wednesday, 5 October 2011

Flash, flowplayer and nyroModal Overlays

It doesn’t take me to tell you that in today’s world Flash is a very popular way of presenting video content to your users, and almost as common is the use of overlays to present your users with alternative content or messages. This is usually supported by some javascript library such as the nyroModal JQuery plugin.

Unfortunately, sometimes the two don’t mix with the flash video appearing to “show through” the overlay, but is this really the case. The blog examines what’s really happening.

Tuesday, 4 October 2011

Looking into the Magic of Dependency Injection Using Annotations - Part 3

This is the third in a short series of blogs that looks into implementing dependency injection using annotations.If you’re familiar with Spring or EJB3, you’ll know the sort of thing I’m talking about: you write you class; add a few annotations, for example @Autowired or @Ejb; deploy it to your web-server and then et volia it’s all glued together and works, as if by magic...