Unstable Terrain

Software development in the real world

Archive for the ‘Software Development’ Category

Efficient Singletons in legacy code

leave a comment »

The app I’m maintaining is not Spring-enabled so I am faced with the possibility of writing code for singleton objects. To my mild surprise, I discovered that Java 5 has made singleton creation considerably less bug-prone. There’s also better practices for double-checked locking, if your code (attempts to) swing that way.

Advertisements

Written by Trent

August 30, 2011 at 11:25 am

Posted in Software Development

Tagged with , ,

Separating Unit tests from Acceptance tests in maven

leave a comment »

Have been playing with Maven a lot in the last week and a half. One thing I liked about Ant was the control over whether various classes of test would run in which target.

Found a post by Abhi which demonstrates that a judicious use of profiles will accomplish this.

Written by Trent

August 25, 2011 at 3:33 pm

Maven: Not as terrible as it seems

leave a comment »

I once read a quote about Maven, that

it makes the simple things effortless, and the difficult things impossible

After working with it full-time for, wow, has it been a year already? I still believe that statement is true for beginners. Eventually, though, you learn how to work with Maven rather than against it, but still get it to do what you want.

Written by Trent

August 24, 2011 at 3:43 pm

Posted in Software Development

Tagged with

Document base /path/to/exploded/war/ does not exist or is not a readable directory

leave a comment »

I discovered the easy technique where one can point Tomcat at a directory instead of copying stuff into the /webapps dir.

So, I created $CATALINA_HOME/conf/Catalina/localhost/ma.xml like so:

<Context path="/ma" docBase="/workspace/ma/target/ma" reloadable="true" />

After a few false starts (turns out that Tomcat on Windows doesn’t accept cygwin-style paths even when started from sygwin), I thought I had it sorted.

<Context path="/ma" docBase="d:\workspace\ma\target\ma" reloadable="true" />

but Tomcat was having none of it.

16/06/2011 5:04:23 PM org.apache.catalina.core.StandardContext resourcesStart
 SEVERE: Error starting static Resources
 java.lang.IllegalArgumentException: Document base D:\workspace\ma\target\ma does not exist or is not a readable directory

Turns out I was being stupid and forgot the trailing slash in the docBase.

Derp.

Written by Trent

June 16, 2011 at 6:04 pm

Posted in Software Development, Tools

Tagged with

Office Politics

leave a comment »

It took me many years to realise this...

Written by Trent

May 7, 2011 at 2:09 pm

Passwords

leave a comment »

Standard passwords:

vs more easily-remembered ones:

Graph (and awesome article) from Baekdal.

Written by Trent

April 16, 2011 at 9:09 pm

Testing JUnit 4 Exception Messages

leave a comment »

In previous years, I have tested exceptions in JUnit tests using variations on the

try {
  doSomething();
  fail();
} catch (Exception expected) {
  assertEquals("Invalid Number of Foos", expected.getMessage());
}

pattern. Various upgrades such as codifying it into an AssertThrows class and checking the correct exception type have helped but it was a pretty ordinary solution.

Changing to JUnit 4 allowed for the annotation below:

@Test(expected=IllegalArgumentException.class)

… but testing the exception message remained ugly.

JUnit 4.7 has a neat upgrade: testing that thrown exceptions have particular messages.

For example:

public class BuilderTest {
  @Rule
  public ExpectedException thrown = ExpectedException.none();

  @Test
  public void invalidMessagesShouldThrowAutoPopulateException() {
    thrown.expect(InternalAssertionError.class);
    thrown.expectMessage("too many autopopulate errors");

    builder.build(createGroupWithTooManyAutoPopulateAnnotations());
  }
}

It also accepts a Hamcrest-style matcher if you want to do something more complicated.

Written by Trent

February 18, 2011 at 4:19 pm

Posted in Software Development, Tools

Tagged with , ,