Java Archive

Language Agnostic: Unit Test Principles

After spending a few days churning out unit tests for a recent project of mine, I took a step back and asked myself: What are the properties of good unit tests? Tests are seen as something of a burden that devs have to do to keep business happy, but in reality they can save countless

Read More…

JUnit: Testing Private Methods and Fields

I’m working with somewhat legacy code at the moment which needs to be tested. Unfortunately with most legacy code, changing it is something that is not within my current scope…even though the visibility of some fields need to be changed or getter/setters put in place to allow for testing. Found yourself in this situation? There

Read More…

JUnit Assert: Which One to Choose?

Unit tests, the bane of any engineers day, but a necessity and something that has proven itself to me over time to be invaluable if done correctly. For any developer that has just sat down to write their first test they may be confronted with the following problem when trying to use JUnit’s Assert functionality.

Read More…

@Inject vs @Autowired

The annotation @Inject (javax.inject.Inject) is part of the Java CDI standard introduced in Java EE 6 (JSR-299), which Spring has choosen to support using @Inject synonymously with their own @Autowired annotation. The annotation @Autowired is springs own (legacy) annotation. @Inject is part of a new Java technology called CDI that defines a standard for dependency

Read More…

Spring Autowiring using @Qualifier

In Spring, the annotation @Qualifier specifies which bean is autowired on a field. The following scenario shows an instance where using @Autowired alone is not sufficent. Autowiring Example See below example, it will autowired a “person” bean into customer’s person property. But, two similar beans “ie.markreddy.Person” are declared in bean configuration file. Will Spring know

Read More…

Unit Test Hanging During Sonar Analysis (JMockit, Maven, Sonar, JaCoCo and Jenkins)

Recently I  deployed a new batch of unit tests based on the JMockit framework in our new Jenkins + Sonar environment and after building successfully the tests were hanging during sonar analysis. Even the tests that don’t use JMockit (simple JUnit) stopped to work. It was strange that during the build phase with test there was no problem

Read More…

Plan for the New Year

As the New Year approaches I’m posting my ‘programming resolutions’, I’m defiantly looking to learn a new language…plenty of choice out there thats for sure. What else could I pick up or improve, a framework, database theory/design, some new tools of the trade etc. No time like the present, so here is my list: The big one: Scala 

Read More…

Converting Java Properties File into XML

Many developers may not aware that the java.util.Properties class comes with a storeToXML() method to convert existing properties data into a XML file. The above example will write the properties detail into a XML file “c:/email-configuration.xml“

Read More…

Know your tools!

There is a huge number of tools specialising in different disciplines like: requirements management, software & database design, software configuration management, build & deploy, continuous integration, development, debugging, profiling, code analysis or testing. A software engineer can’t know all tools in detail, but he/she should know the key concepts and underlying technologies. Knowing the right

Read More…

Book Review: Spring In Action, 3rd Edition

After working with Spring on a daily basis for over a year I felt myself learning the framework though repetition rather than understanding, hence I bought this book to give me the background to what I was doing, I wanted to know what happened when I declared beans, how I was able to inject them,

Read More…