Java Rehabilitation Clinic

Posted by James Mead Mon, 17 Mar 2008 09:23:26 GMT

Not long after Ben persuaded me to join the fledgling Reevoo, we got our first big ReevooMark partners (Dixons & Currys) live. To celebrate this event and my having left Java behind at Thoughtworks, Ben bought me a Java Rehabilitation Clinic mug. The mug has recently developed a crack. I wonder if it’s trying to tell me it’s time to learn another language…

java-rehab-clinic-mug

Java Rehabilitation Clinic mug

Tags , , , ,  | 1 comment

Mocking in Java using Mocha

Posted by James Mead Sun, 17 Feb 2008 18:10:01 GMT

Ola Bini one of the JRuby guys has released the JtestR tool which allows you to write tests for Java code in Ruby! Ola has bundled a number of Ruby libraries – Mocha, RSpec, Dust, Test::Unit & ActiveSupport – together with JRuby to allow you to write Ruby test cases that test Java code.

He has a couple of examples in the Mock documentation of how to use Mocha...

The first one demonstrates using Mocha to mock an interface (Map).

  import java.util.Map
  import java.util.Iterator
  import java.util.Set
  import java.util.HashMap

  functional_tests do 
    test "that a new HashMap can be created based on another map" do 
      map = Map.new

      map.expects(:size).returns(0)

      iter = Iterator.new
      iter.expects(:hasNext).returns(false)

      set = Set.new
      set.expects(:iterator).returns(iter)

      map.expects(:entrySet).returns(set)

      assert_equals 0, HashMap.new(map).size
    end
  end

The second example demonstrates using Mocha to setup expectations on a real (non-mock) instance (HashMap)...

  import java.util.Iterator
  import java.util.Set
  import java.util.HashMap

  functional_tests do 
    test "that a new HashMap can be created based on another map" do 
      map = mock(HashMap)

      map.expects(:size).returns(0)

      iter = Iterator.new
      iter.expects(:hasNext).returns(false)

      set = Set.new
      set.expects(:iterator).returns(iter)

      map.expects(:entrySet).returns(set)

      assert_equals 0, HashMap.new(map).size
    end
  end

Tags , , , ,  | no comments

Escape from the Enterprise - London Rails Jobs

Posted by James Mead Wed, 25 Apr 2007 04:12:00 GMT

If you’re looking to escape the “Enterprise” world of Java and .NET for the shiny new world of Ruby on Rails, take a look at Ben’s blog post and 37Signals job advert.

Things are really starting to hot up here at Reevoo. When you’re in the middle of it all, it’s easy to forget the progress we’ve been making. In recent months, we’ve…

I work with a talented and friendly bunch of developers…

We’re heavily into Test-Driven Development, Continuous Integration/Deployment and Open Source. It’s an exciting and fun place to work.

If you’re interested, send Ben (ben_at_reevoo_dot_com) your CV and mention you saw the job here.

Tags , , , , , , ,  | no comments

Hellish XML

Posted by James Mead Tue, 17 Oct 2006 03:26:00 GMT

So now you can write test cases for ANT in XML using AntUnit.

You can even write assertions in XML

  <!-- the actual test case -->
  <target name="testTouchCreatesFile">
    <au:assertFileDoesntExist file="${foo}"/>
    <touch file="${foo}"/>
    <au:assertFileExists file="${foo}"/>
  </target>

... but why?

Perhaps the time is ripe for an XML mocking library ;-)

Tags , , , , , , ,  | 1 comment

Mocha in Java using bytecode manipulation

Posted by James Mead Sat, 16 Sep 2006 14:43:00 GMT

My former colleague and bytecode maestro Stacy Curl has an interesting article explaining how it would be possible to implement Mocha in Java using experience from his PicoUnit project.

It’s good to be reminded that meta-programming is possible in Java, but just a bit more effort.

Tags , , , , , , , , , ,  | no comments