Author Archives: mostlymagic

Unit testing default methods in interfaces

Java 8 has introduced a nice feature, default (so-called “defender”) methods in interfaces. These methods are implemented in the interface, but can be overridden. Now how can we unit-test these default methods? A naive approach would be: in your unit test … Continue reading

Posted in Uncategorized | Leave a comment

How to compare types in Java

Here’s an overview of the different methods to identify a type or Object in Java. There are three basic cases I want to detect if two variables point to Objects of the same type I want to detect if two … Continue reading

Posted in Uncategorized | Tagged , , | 2 Comments

Two Guava Collections

Today I wrote two different Guava Collections as answer to two different StackOverflow Questions: Java data Structure and Comparator and equals() The first requested a Map where the keys are Enums and the values are sorted collections. In my answer, … Continue reading

Posted in Guava, Java | Leave a comment

Add system properties through spring XML configuration.

If you want to set system properties through XML configuration, here is a solution (inspired by this question): Use two MethodInvokingFactorybeans, one to statically access System.getProperties() and one to call properties.putAll(map) on these properties. Here’s the configuration: <bean class=”org.springframework.beans.factory.config.MethodInvokingFactoryBean”>   … Continue reading

Posted in Java, Spring | 2 Comments

Wicket behavior to guard changed form.

Triggered by the StackOverflow Question Wicket : Notify if page model has been changed., here is a wicket behavior that you can attach to a form and that will stop the user from leaving the site once he has changed … Continue reading

Posted in Java, Wicket | Leave a comment

Compile .less files to .css in maven (again using GMaven)

I have recently come across LessCSS, a CSS meta-language that introduces code re-usability. I have been looking for a solution like this for some years now, as I hate having to write the same stuff over and over again. So … Continue reading

Posted in CSS, Groovy, JavaScript, Maven | 10 Comments

Deploy a folder hierarchy to a maven repository

Again, prompted by a Stackoverflow question, here is a means to deploy an entire directory including subdirectories to a maven repository. I am using GMaven (groovy scripts embedded in maven), a great way to script and interact with maven without … Continue reading

Posted in Groovy, Maven | 1 Comment