Tarin Gamberini

A software engineer and a passionate java programmer

Testing with the appropriate injection

Times ago I added some new functionalities to a Spring-based web application.

After some changes a unit test failed. The cause was a missing bean which stopped the auto-wiring process while Spring was loading the application context.

The test declared its own application contest, by using the annotation @Configuration on a static inner class; there were some mocked beans, so I added the missing bean:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class MyClassTest {

    ...

    @Configuration
    static class ContextConfiguration {

        @Bean
        public MissingBean missingBean() {
            return new MockMissingBean();
        }

        @Bean
        public ThatBean thatBean() {
            return new MockThatBean();
        }

        @Bean
        public ThisBean thisBean() {
            return new MockThisBean();
        }

        ...
    }

}

Then I changed other classes adding other auto-wired beans, new methods, and the like, till when the same test that had failed before failed again!

ThoughtWorks Technology Radar in Italian

I have always been enthusiastic about the ThoughtWorks Technology Radar both because of the idea in itself and because of its implementation in the form of radar.

The Technology Radar is a document which gathers substantial changes in IT technologies of interest to various ThoughtWorks teams. The Radar is written by the ThoughtWorks Technology Advisory Board (TAB), made up of senior technologists at ThoughtWorks, which regularly meet themselves to talk about technology trends that significantly impact our industry.

The implementation in the form of radar is characterized by four quadrants: techniques, platforms, tools, languages & framework; and four concentric levels (from outside to inside): hold, assess, trial, adopt. The various moving technologies appear on the Radar as blips: the closer the blip is to the center, the more it is qualified to be of worth by ThoughtWorks.

The ThoughtWorks Radar contents summarise the essence of the TAB meetings, and its format effectively communicate contents to a wide range of stakeholders, from CIOs to developers.

Over the years the Thoughtworks Radar has evolved in the contents, in the graphic layout, and in the distribution in various languages; but it hasn’t been available in Italian yet. Last year, when I discovered that ThoughtWorks has an office in Bologna, the city where I work in, I wrote an email asking if I might have contributed to the Italian translation of the ThoughtWorks Radar. I received a reply from Matteo Vaccari:

Method parameters and TOCTOU

I have always been fascinated by the Design by Contract approach:

Software always had bugs and always will”. Tired of this defeatist attitude? With Design by Contract, invented by Eiffel Software and one of the most widely recognized breakthroughs in the history of software engineering, you can write complex software and not wake up at night fearing that something, somewhere will go wrong. Design by Contract brings science to the construction of correct and robust software.

From this point of view, unfortunately, Java is not Eiffel. Therefore, even if I would have follow this Bertrand Meyer valuable concept, I had to cope with the language itself. I know in the past years some Java frameworks which implement Design by Contract have been proposed, but I have never had the chance to try them seriously. So what I do is simply checking input method parameters.

Functional Programming in Java book review

Last January I was selected from Manning as one of the technical reviewers of the book “Functional Programming in Java” by Pierre-Yves Saumont. In these days the book has been released to the public therefore I can publish this post without violating the reviewer agreement.

The book teaches functional concepts by lots of examples and exercises which develop in the reader both a knowledge background and a natural instinct to functional programming paradigm.

Code Templates For Logging

When I want to log a message, a variable, or an exception I would like to write it quickly. Therefore I’ve created some templates which generate logging instruction based on slf4j.

Netbeans IDE

I have created the following code template:

1
private static final ${LOGGER_TYPE type="org.slf4j.Logger" default="Logger" editable=false} LOGGER = ${LOGGER_FACTORY type="org.slf4j.LoggerFactory" default="LoggerFactory" editable=false}.getLogger(${CLASS editable="false" currClassName}.class);

and I have associated it to the abbreviation log. Than at the cursor:

1
2
3
public class MyClass {
    |
    ...

I type log + TAB and NetBeans expands the text:

1
2
3
4
5
6
7
8
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

...

public class MyClass {
    private static final Logger LOGGER = LoggerFactory.getLogger(MyClass.class);
    ...

I have also defined the shortcuts:

  • logd + TAB
  • logw + TAB
  • logi + TAB
  • loge + TAB

defined as:

  • ${LOGGER_CONST default="LOGGER" editable=false}.debug("${logMessage}");
  • ${LOGGER_CONST default="LOGGER" editable=false}.warn("${logMessage}");
  • ${LOGGER_CONST default="LOGGER" editable=false}.info("${logMessage}");
  • ${LOGGER_CONST default="LOGGER" editable=false}.error("${logMessage}", ex);

which generate:

1
2
3
4
LOGGER.debug("logMessage");
LOGGER.warn("logMessage");
LOGGER.info("logMessage");
LOGGER.error("logMessage", ex);

The first time I have used Vim at work

Some time has passed since I started learning Vim. I didn’t wanted to use it at work because I don’t think I’m as productive as I’m with the editor I usually use… till this morning.