Softwire Blog


Frege – Haskell for the JVM


29 June 2016, by

In the programming world we like an interesting challenge, and one of the more challenging concepts in our profession is that of functional languages. With more functional languages gaining lots of traction (Softwire have done several projects in python and Scala, as well as other functional oriented languages) there are some interesting projects going on.

(more…)

Java: auto-generated POJO builders


6 April 2015, by

Any of you that have worked for a while with Java have undoubtedly come across code similar to this, usually in unit tests:

public SomeEntity createEntityWithFoo(String foo) {
    SomeEntity entity = new Entity();
    entity.setFoo(foo);
    return entity;
}

public SomeEntity createEntityWithFooAndBar(String foo, String bar) {
    SomeEntity entity = new Entity();
    entity.setFoo(foo);
    entity.setBar(bar);
    return entity;
}

(more…)

Lunch and Learn: Speedcoding in Scala


19 December 2014, by

As with last time’s lunch and learn. This post is best watched while eating your lunch.

In this video you’ll be learning how I took Rupert’s solution to the last speed coding challenge and re-wrote it in a more functional manner.

Find out the java testing libraries that will make your life easier


22 August 2014, by

Unit testing is generally considered a good thing, but a worker is only as good as their tools. The tools that immediately spring to mind when writing java unit tests are JUnit, and HamCrest. But are these the best tools for the job? This post explores a couple of alternatives. Depending on the task you are trying achieve, these may be better or worse alternatives, but it’s always good to know your options.

JarSpec

This library is a neat way of writing more descriptive unit tests. It was created by Softwire’s Harry Cummings as a solution which enables Java unit tests to be coded in a manner similar to RSpec:

@RunWith(JarSpecJUnitRunner.class)
public class MinimalSpec implements Specification {
  @Override
  public SpecificationNode root() {
    return describe("addition", () ->
      describe("of 1+1", () -> {
        int result = 1 + 1;
        return by(
          it("should equal 2", () -> assertEquals(2, result)),
          it("should equal 3", () -> assertEquals(3, result))
        );
      })
    );
  }
}

The code to JarSpec is on GitHub.

AssertJ

AssertJ is a matcher library that is set up to allow good integration with IDEs.
Rather than typing:

assertContains(list, value)

which could match several different types other that List, you type:

assertThat(list).contains(value)

Not only is this nicer to read, after typing the period, your IDE can immediately suggest all of the assertions that can be performed on the list. When trying to do code completion in the first example, you have to pick your method from all of the assertions that exist.

The code to AssertJ is on GitHub.

Mean Bean


4 November 2013, by

Recently, on one of Softwire’s projects, we were tasked with retrofitting a test suite to a codebase. The use of Hibernate on the project had resulted in a large number of getters and setters, and we wanted an easy way to check for obvious bugs in this code. MeanBean:

  • Tests that the getter and setter method pairs of a JavaBean/POJO function correctly.
  • Verifies that the equals and hashCode methods of a class comply with the Equals Contract and HashCode Contract respectively.
  • Verifies property significance in object equality.

(more…)

Book review round-up: Java and Spring


7 December 2012, by

There are plenty of Java books out there, and I’ve read quite a few of them! Here are some of the ones I found most useful:

Effective Java (Joshua Bloch)

This book is definitely worth a read if you want to make good use of Java. It’s not a manual for the language in the manner of the ‘in a Nutshell’ books or Core Java (below). Compared to these kinds of books, it concerns itself with “why”s rather than “how”s, seems to sink in better, and is surprisingly concise. There is a great deal more useful, memorable content in its 300-odd pages than in many programming books that are twice as long.

Recommended chapters: All of them (it’s very good and not a very big book)

(more…)

Testing and JavaScript: Useful Libraries


19 November 2012, by

previous article in series

It can be difficult to find useful JavaScript testing-related libraries, to provide lots of the extra functionality that’s typically necessary to make automated testing practical. This is necessarily a very broad topic, but there’s a few key components that almost all testing requires, so I’ve skimmed through some of the options in each.

(more…)

Load testing: Why use tools when you can use Ruby?


15 October 2012, by

I recently found myself dealing with a problem that had been identified in load testing on one of our customer’s sites. Specifically, when the site was being hit with requests for mobile pages while also handling a background noise on the desktop versions, one of those desktop pages would, every so often, throw a 500 error. The mobile pages in isolation worked fine, and the desktop pages in isolation worked fine.

This kind of bug is one of those ones that I feel is allowed to happen during dev, so I didn’t feel too bad about it. In order to actually diagnose and fix the issue, however, I was clearly going to need to generate some load of my own so I could work out the problem rather than merely the symptoms.

(more…)

Spring Roo


1 October 2012, by

Spring Roo is a tool for rapid Java application development. It claims to offer industry standard solutions to common problems. It’s been gaining popularity and we have trialled it on a number of our projects with mixed success. Here’s a quick set of answers to questions that you might find yourself asking when starting a new Spring project.

What can I do with Roo?

Roo offers you scaffolding features similar to those found in web frameworks such as Rails. You describe an entity with fields and from this it will create CRUD (Create Replace Update Delete) views and controllers using standard Spring conventions. These are kept in sync so if you update the fields on your entity then it will update the rest of the application. With this you can create fully functional web sites from scratch in a very short period of time.

(more…)

Apache Bench (ab) stalls after 16000 requests


2 September 2012, by

I’ve been doing some trivial benchmarking of Play 2 with ab (Apache Bench) just to get an idea of its raw capabilities for serving simple requests – and because it’s what I always do when picking up a new framework so I know what I’m dealing with. In doing so I ran into a bit of a puzzler that had me thinking Play 2 was bugged – but my spidey sense soon kicked in and told me it was more likely to be an OS or ab issue. I had done approximately the following, using Play 2.0.1 on OS X 10.7.3, and I’m pretty certain you’ll see the same results if you do this on a Mac:

(more…)