Category Archives: java

Avoid branches in test code

Tests should describe a linear story, as opposed to production code. What things we start with, what we do with them, and what we get. Some call this the Given/When/Then pattern, others the Arrange/Act/Assert pattern. This means that the code … Continue reading

Posted in java | Leave a comment

Name test methods with underscores

In production code, common coding standards for Java recommend writing method names in CamelCase. retrieveUserDetails() createABankAccount() This makes sense when those methods are called from our own code. It feels as if requests are being made to these objects (dear … Continue reading

Posted in java | Leave a comment

Default JDK file encoding and Eclipse, running on Mac OS X

File encoding is notoriously a difficult problem for developers to fully grok. Development environments and IDEs do not always help. I recently had a test failing under Eclipse, whereas the same test was passing fine in the command line using … Continue reading

Posted in java | Leave a comment

A classic case of Data Envy

TL;TD: Refactoring classes that have data envy is easy. Do it. Here is a snippet extracted from the last project I worked on: // somewhere in a class asset.setHasAssociatedImage(!StringUtils.isBlankOrNull(imageName)); asset.setImageName(imageName); // in another class if (asset.hasAssociatedImage()) { image.setUrl(categoryName + “/” … Continue reading

Posted in java | 4 Comments

Avoid annotations with Mockito

On the Mockito mailing list and on Stackoverflow, there are a significant number of questions that actually reveal that the person asking did not perfectly understand what the Mockito annotations do. Indeed, the annotations are rather magical and their behavior … Continue reading

Posted in java | 8 Comments

Refactoring to Fantom

This post in an introduction to Fantom via the refactoring of Java code. TL; DR: Fantom is basically a better Java with a very similar syntax, but with lots of little simplifications and some powerful features such as functions.

Posted in java | 1 Comment

Create hidden files in Apache VFS with the RAM filesystem type

Apache VFS is a great way to access different file systems in the same way. I particularly like the custom RAM filesystem in my unit tests in order to check code that eventually accesses the actual file system. For example: … Continue reading

Posted in java, test | Leave a comment

Cleaning up test code

My former colleague David just posted an example of verbose test code on his blog (the parts in French have been translated to English by myself): /** * */ @Test public void testGetCustomerOK() {“======= testGetCustomerOK starting…”); try { CustomerDTO … Continue reading

Posted in java | 3 Comments

More data on productivity of small teams

“Adding manpower to a late software project makes it later”. The so-called Brooks’s Law on productivity of software project is well known, since Fred Brooks’ seminal work The Mythical Man-Month, first published in 1975. That is one of the reasons … Continue reading

Posted in java | 3 Comments

Worse than static methods or final classes?

Do you know what’s worse that static methods or classes marked as final? I’ll tell you what’s worse: static methods that return final classes. That only provides private constructors. Here I was, merrily testing my way through a piece of … Continue reading

Posted in java, tdd | 4 Comments

I avoid method variables in my test methods

Here is a typical example of a test method @Test public void should_search_by_path() { Searcher searcher = new Searcher(); Path location = new Path(“somewhere”); String data = “data”; searcher.putAt(data, location); assertThat(searcher.findAt(location), is(data)); } It seems that many developers consider this … Continue reading

Posted in java | 5 Comments

Java’s varargs are for unit tests

At Devoxx last week, Joshua Bloch argued during his talk “The Evolution of Java: Past, Present, and Future” that varargs are only “somewhat useful”. I think he is overlooking some usages, particularly in tests. Here is my case.

Posted in conferences, java, tdd | 2 Comments

Play Framework and Guice: use providers in Guice modules

Play Framework has a Guice module. Unfortunately, its use is fairly limited compared to what Guice can do. In this post, I describe how it is configured on my current personal project.

Posted in java, test | Tagged , , | 1 Comment

CITCON London 2010

I’m returning from CITCON London 2010. What a great conference (and I’m not just saying that just because I helped organize it)! In fact, I feel it has been the best CITCON so far. I was a bit afraid of … Continue reading

Posted in citcon, java | Leave a comment

Mock objects at CITCON Paris 2009

The session on mock objects, mostly lead by Steve Freeman, was a bit messy but interesting. My colleague David got to show some of our code on the screen, which was scary and exciting (he felt the urge to fix some of the … Continue reading

Posted in citcon, java | 5 Comments