Blog

Jacoco code coverage with Gradle

Posted by on Jun 3, 2013 in Gradle, Groovy | 0 comments

One of the new features of Gradle 1.6, the Groovy based build tool, is Jacoco support. Jacoco is one of the few (only?) Open Source code coverage tools still in active development, and starting from Gradle 1.6, it’s now a supported plugin. Enabling the task is easy, just add apply plugin: 'jacoco' to your build.gradle, and run ./gradlew jacocoTestReport and it.. does nothing. For those running into the same issues, this might save you a bit of time: After a bit of searching, it turns out the jacoco plugin is a bit broken. When using it...

read more

Creating projects with Gradle

Posted by on Apr 16, 2013 in Gradle, Groovy | 2 comments

Coming from a Maven background (Maven 1, 2, 3), I find it a bit strange that Gradle doesn’t provide archetypes like Maven does. There’s a template plugin, which helps a little, but besides that, you’re out of luck. Or are you? I found a pretty neat Gradle script in their Jira system, which can create a directory structure for you even when working on a Groovy or Scala project. The easiest way to do so is to add the following ‘initProject’ task to the Gradle build.gradle: apply plugin: 'java' apply plugin:...

read more

Reviving Groovy in Action

Posted by on Apr 13, 2013 in Groovy | 2 comments

Some time ago, Dierk Koenig decided to write Groovy in Action, THE bible for learning the Groovy language and some libraries around it. The book was written for Groovy 1.0, and it was a great reference (I learned my first Groovy from that book), and though outdated, it still is a great book. Then, some years later, Groovy 1.5 came out. So it was time for an updated version of the Groovy in Action book, now the second edition. So, the musketeers got back together and investigated what the new features were, made some split who would write...

read more

Adding an alarm to Android Alarm clock

Posted by on Apr 3, 2013 in Android | 0 comments

If you need to set an alarm from within your application, you might be guided to the android AlarmManager. While it’s possible to use the AlarmManager to fire an alarm, sometimes you want to use the alarm application the user has installed himserver. To do so, you can use AlarmClock. This can be done in the following way: Intent openNewAlarm = new Intent(AlarmClock.ACTION_SET_ALARM); openNewAlarm.putExtra(AlarmClock.EXTRA_HOUR, 0); openNewAlarm.putExtra(AlarmClock.EXTRA_MINUTES, 20); startActivity(openNewAlarm); You’ll need...

read more

Introduction to Hamcrest Collection Matchers

Posted by on Jan 22, 2013 in Java | 2 comments

Another post in the series of Hamcrest Matchers, a framework for writing test matcher objects. This week we’ll dive into collections and iterables, and we’ll see how we can use Hamcrest for making those asserts even more readable. In many software projects I encounter code like the following: assertEquals("Collection size doesn't match", 4, reds.size()); Or, even worse: assertTrue(greens.size() == 0); The second loses context by not knowning the expected value and the actual value; it knows only that they are not equal. So,...

read more

Introduction to Hamcrest String Matchers

Posted by on Jan 15, 2013 in Java | 0 comments

Another week, another blogpost. For those catching on just now, or finding this post using a search engine; I’m writing a series of posts about Hamcrest, a framework for writing test matcher objects, and showing you how to use Hamcrest. While the previous post was about the Core Matchers, the topic of this week is Hamcrest String Matchers. The Hamcrest String Matchers are the following: containsString, startsWith, endsWith, equalToIgnoringCase, equalToIgnoringWhitespace, isEmpty, isEmptyOrNull and stringContainsInOrder Also in this post,...

read more

Generate a toString using Guava Objects.toStringhelper with IntelliJ

Posted by on Jan 10, 2013 in Java | 0 comments

In IntelliJ it’s possible to generate a toString using Alt+Insert (Windows) or Ctrl+N (Mac). In this dialog, you can choose to use different implementations, like a StringBuffer, a StringBuilder, Apache Commons ToStringBuilder, and more. But if you’re using Google Guava, you can create your own template in IntelliJ. To do so, do the following: Open a class file Press Alt + Insert or Ctrl + N to popup the ‘Generate’ menu Choose toString() Click the button named ‘Settings’ Go to the ‘Templates’...

read more

Introduction to Hamcrest Core Matchers

Posted by on Jan 8, 2013 in Java | 0 comments

In our previous post, we got a small introduction into Hamcrest, a framework for writing test matcher objects, and why you should use them. This post will dive deeper into Hamcrest Matchers. A Matcher is a ‘match’ rule to be defined declaratively. The Hamcrest library comes with numerous matchers included, and it’s of course possible to write your own Matcher. The topic of this week: the Core Matchers. The common Matchers of Hamcrest are the following: is, equalTo, not, anything, instanceOf, any, isA, nullValue,...

read more

Hamcrest Matchers in JUnit tests

Posted by on Jan 6, 2013 in Java | 2 comments

With JUnit being the dominant Test framework, chances are high that during your career as a software engineer, you’ve encountered the JUnit framework in one or more projects. Therefor, code like this: assertEquals("Result doesn't match hello", "hello", result.getValue()) Should not be unfamiliar to you. This blogpost is on improving the example above. There are good alternatives in writing your tests, like Spock, but these take a little more effort to setup, since it’s mostly used in Groovy projects. The goal of this blogpost...

read more

Reloading Log4j Configuration in Tomcat

Posted by on Oct 22, 2012 in Java | 0 comments

When you’re in production environment and you want to diagnose some problems, it’s often handy to have some more logging available. So, when you’re using Log4j, and you want to have your log4j.xml reloaded, you can use Log4jWebConfigurer to make this happen. To use it, you need to add a listener your web.xml. Be careful to place this before the ContextLoaderListener entry. Also important is to add a log4jRefreshInterval (in milliseconds), else Log4j won’t start it’s deamon thread. web.xml <context-param> ...

read more