JSF & Java Blog

Discussion on Java and JSF, including Spring, Maven, Eclipse and Jenkins

Posts Categorized / Frameworks

Guava ImmutableMap Spring bean

I previously had some maps defined as Spring beans in my applicationContext.xml file. An example of a basic Map is shown below: I wanted to make these all immutable and so Guava’s ImmutableMap seeemed the logical Map type to use. However, ImmutableMap is abstract so you can’t just do the following: Instead, thanks to help […]

0

Spring MVC 406 status code from AJAX requests

Recently after upgrading from Spring MVC 3.1.2.RELEASE to 3.2.0.RELEASE, all of our AJAX requests stopped working, and instead returned a 406 status code (see here for status code meanings). We were using Jackson 2.1.2, the following snippet from the pom.xml file shows the two dependencies: There were some changes made with the 3.2.0.RELEASE in regards […]

0

Mocking Statics and IllegalStateException: no last call on a mock available

If you use PowerMock to mock a static object e.g. and encounter the following error: Check that you have prepared the Class for test using the @PrepareForTest annotation. e.g. An excellent article discussing mocking statics by one of the PowerMock developers can be found here: http://blog.jayway.com/2009/05/17/mocking-static-methods-in-java-system-classes/ Note that you also need to @PrepareForTest any classes […]

1

Cobertura code coverage with Maven and PowerMock

If you use Powermock for unit testing with Maven and Cobertura for code coverage, you are likely to be affected by the following issue noted on the PowerMock issue tracker. If you did not have the maven-surefire-plugin forkmode configured to ‘pertest’, you would find that any tests annotated with @RunWith(PowerMockRunner.class) had zero percentage code coverage […]

3

Chaining EasyMock’s expectation return values

Recently I discovered quite a handy feature of EasyMock’s IExpectationSetters andReturn method. You are able to chain the return values so that you can return different values each time that expectation is called. Chaining Easymock’s expectation return values becomes useful if you consider the following method, where Voucher is an object that cannot be instantiated […]

0