A Practical Guide to Project Lombok

A Practical Guide to Project Lombok

Java is a powerful language but often criticized for being too verbose (aka boilerplate – term used to describe code that is repeated in many parts of an application with little alteration). Project Lombok came to help the lazy coder in you. It basically generates code for you. But instead of adding code to your non-compiled classes, like an IDE generally does, Lombok works during the build process by modifying the Java bytecode of your class files.

It’s very simple to configure it, their project page has all you need to help you to add it in your projects.

Lombok Annotations

1. @Getter and @Setter

The @Getter and @Setter annotations are used to generate accessor methods for fields, @Getter annotation respects the convention if the field is a boolean property. Both @Getter and @Setter take an optional parameter to specify the access level for the generated method:

Lombok code:

Equivalent Java native code:

Continue reading »

Introduction to Spock Framework

introduction spock framework

What is Spock Framework anyway?

Spock Framework is an open source testing and specification framework for Java and Groovy applications. It lets you write concise, expressive tests, Behaviour Driven Development (BDD) like form, what makes your test more clear. Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock is inspired from JUnit, jMock, RSpec, Groovy, Scala.

Understanding How the Spock Framework Works

Suppose we have a Publisher class that sends messages to its Subscribers:

And the respective unit test class:

In Spock Framework we don’t have tests, we have specifications. A specification is represented as a Groovy class that extends from “spock.lang.Specification”, which is actually a JUnit class.

Continue reading »