StrictMocks in Mockito

Posted by & filed under Java.

Today someone asked how to verify that only your stubbed interactions occur, and no others (when using Mockito). I have heard this asked this quite often, especially by people used to JMock where mocks are strict by default. I’d be interested in knowing if there’s an out of the box way of doing this. The… Read more »

InstanceOf “Smart Casts” with Java 8 Lambdas

Posted by & filed under Java.

As with try-as-expression, there are many other language features we can simulate with Lambdas. Another example is removing the cast commonly needed with instanceof. Kotlin has a nice feature called smart casts, which allows you to do if (x instanceof Duck) { x.quack(); } if (x instanceof Duck) { x.quack(); } Where x is “casted”… Read more »

Try as Expression in Java 8

Posted by & filed under Java.

I’ve been familiarising myself with the new Java 8 language features. It’s great how much easier it is to work around language limitations now that we have lambdas. One annoyance with Java is that try blocks cannot be used as expressions. We can do it with “if” conditionals using the ternary operator. String result =… Read more »

Pair Programming

Posted by & filed under XP.

There was a thread about pair programming on the London Java Community mailing list last week. I tried to contribute to the discussion there, but the mailing list doesn’t receive my replies. So I’ll post my thoughts here instead. I have been pair programming most days in an XP team for the past 3 years…. Read more »

JavaScript shell scripting with Nashorn

Posted by & filed under Java.

One of the nice features of Nashorn is that you can write shell scripts in JavaScript. It supports #!s, #comments, reading arguments, and everything there’s a Java library for (Including executing external processes obviously) Here’s an example #!/home/benji/nashorn7/bin/nashorn #this is a comment   print(’I am running from ‘ + __FILE__);   var name = arguments.join(’… Read more »

JavaScript tests with JUnit

Posted by & filed under Java.

This weekend I have been playing with Nashorn, the new JavaScript engine coming in Java 8. As an exercise I implemented a JUnit runner for JavaScript unit tests using Nashorn. Others have implemented similar wrappers, we even have one at work. None of the ones I have found do everything I want, and it was… Read more »

Steam on openSUSE

Posted by & filed under openSUSE, Uncategorized.

The steam linux beta is now open to everyone. I just installed it on my openSUSE PC. Here’s how. Update Andrew Wafaa pointed out that there’s an rpm package providing a much easier installation option that I could have found myself ¬_¬ It wasn’t entirely straightforward as there is only an Ubuntu package. These steps… Read more »

Webpinstant – Package Name Search

Posted by & filed under openSUSE, webpin.

I have added support for searching by package names only. This was one of the most requested features. I would like to make the normal search “just work” as much as possible and rank relevant search results highly. However, there do seem to be some good use cases for only searching package names. You can… Read more »

MultiCatch in c# and old java

Posted by & filed under c#, Java.

Someone on IRC was asking whether it was possible to do catch multiple types of exceptions at the same time in c#. In Java 7 there’s a feature from project coin called multi catch that enables the following syntax: public class MultiCatch { public static void main(String… args) { try { throw new ExceptionA(); }… Read more »

Webpinstant Update 1

Posted by & filed under openSUSE, webpin.

Thanks to everyone who has been sending me bug reports and suggestions for webpinstant This evening I Fixed an indexing bug that meant searches for some exact-match filenames returned no results. This will require re-indexing all repositories at some point. Here’s a search that wasn’t working and is now fixed Thanks cb400f. Fixed linking to… Read more »