Testing logging behaviour sans Mockito

The most popular post in this somewhat dormant blog is Testing logging behaviour in four code lines flat. The approach described there relies on everyones favourite unit testing mocking swiss army knife – Mockito. To achieve the purpose of unit testing logging Mockito is however not a required drink, some simple Log4j coding goes a long way:

import org.apache.log4j.SimpleLayout;
import org.apache.log4j.WriterAppender;
import static org.hamcrest.CoreMatchers.is;
import org.junit.Test;
import static org.junit.Assert.assertThat;

public class FooTest {

  public void testMethod() {

    StringWriter stringWriter = new StringWriter();

    Logger.getRootLogger().addAppender(new WriterAppender(new SimpleLayout(), stringWriter));


    assertThat(stringWriter.toString(), is("WARN - doh\n"));

The code is still acceptable and quite compact. However the expressive niceties Mockito provides are lost and making assertions about logging levels, timestamps and multiple logging invocations takes a lof of cruft. Hence I really see few reasons for this approach if Mockito is available.


Learning to love Finder

Let’s face it.

The venerable OS X file manager, the Finder, is not a perfect tool. Finder is probably one of the aspects of OS X I like the least. It’s good for cruising around file systems in “column mode” and for browsing media files with Coverflow but for serious file management work I tend to want to drop into the Terminal as soon as possible. Problem is that the new Terminal window will not be in the same folder as to where I’ve navigated in Finder, causing me to lose context –¬†every time.

Recently I stumbled on cdto – a little app that adds an icon to Finder that open a Terminal window. With the current working directory set to the folder shown in Finder! No context lost!

And remember, the opposite operation  Рopening a Finder window in the current working directory of a Terminal Рis trivial with the always useful open command:

$ open .

When applied together, these two small tips makes it possible to use Finder only for the tasks where it shines.

How to set a custom DNS server with Java System properties

Recently I was in the position of having to override the system default DNS server configuration with a custom DNS server for a Java app. Expecting this to be easily achievable along the line of the well-known http.proxyHost/http.proxyPort JVM parameters I whipped out Google.

Turned out to not to be so simple.

Obviously I got some search hits, but no simple recipe for the simple configuration change I was looking for. After spending some time with the leads I was able to conclude that, as a consequence of  an apparent exemple of over-engineering by Sun, the following is explicitly required just to change the JVM DNS server:

//Override system DNS setting with Google free DNS server
System.setProperty("sun.net.spi.nameservice.nameservers", "");
System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");

Mercurial tooling reaching the tipping point

The MercurialEclipse context menu certainly looks comprehensive..

A tipping point can be defined as the levels at which the momentum for change becomes unstoppable.

I’d venture to state that distributed version control system Mercurial reached its tipping point when version 1.6.0 of MercurialEclipse recently was released.¬† At least for me. ūüôā During the last years I’ve been consistently and repeatedly underwhelmed with the state of Mercurial tooling in my favoured integrated development enviroment, resorting to use hg at the command line exclusively.¬† Command line interfaces are good for many things but it’s hard to let go of the comforts of a good GUI when one is used to the brilliant Subclipse Subversion plugin.

MercurialEclipse is a quantum leap. I sincerely hope the availability of first class Eclipse support for Mercurial will be the tipping point for distributed version control systems in general and Mercurial in particular!

Top Clojure Links

On my quest to pick up Clojure during 2010 I’m¬†primarily¬†accompanied by the very solid Programming Clojure by Stuart Halloway. I’ve however also stumbled upon some interesting, cool, thought-provoking etc. Clojure resources on the web. So here goes – in no particular order:

Clojure РFunctional Programming for the JVM by R. Mark Volkmann is both a great introductory article and a handy reference. Actually a cheap aspiring functional programmers alternative to Programming Clojure!

MiGLayout: The one Java layout manager that does it all by Chris Hardin is another of the many excellent Java News Briefs by Object Computing, Inc. (OCI). MIGLayout is a Java Swing UI layout manager which is as powerful and expressive as the Clojure programming language. This makes MIGLayout an excellent choice for all your Clojure UI needs!

Full Disclojure is a series of easily digested screen casts highlighting a particular feature of Clojure in each episode. The screen casts are accompanied by clear audio and the well-paced action takes place directly at the REPL (as it should!). Full Disclojure is on an accessible level for newbies and covers, among other topics, many of the cool features introduced in Clojure 1.1.0.

Hot Code Swapping is not the exclusive domain of Erlang!

Put a Spotlight on a MacPort

OS X essentiality MacPorts has a convenient command line user interface for querying and browsing available software packages. For instance a simple "ports info pine” will net:

pine @4.64 (mail)
Variants:             darwin_9, ssl_plain
Description:          Pine is a tool for reading, sending, and managing
                      electronic messages that was designed with novice
                      users inmind.
Homepage:             http://www.washington.edu/pine/

Platforms:            darwin
License:              unknown
Maintainers:          sean@fuzzymagic.com

A more graphical option for the occasional port lookup is to use OS X built-in file indexing system Spotlight that happily provides as-you-type matching of available ports in the local ports tree.

The corresponding port file directory will typically be the top match when searching for well-known unix software.