Using Expected Exceptions in UnitTests


Apr 22, 2013 1 minutes read

Sometimes, reviewing code, I see misunderstanding of using Expected Exception concept in unit tests.

Let’s consider following test class:

There are two test methods here and only first one is not correct. When service throws SomeException, Mockito.verifyZeroInteraction(bar) is not invoked, although expected exception is catched and test framework reports test passed.

The Rule of Thumb is: You may use ExpectedException only if call of the method under test is the last operator of test method.

See Also

Configuring Protobuf to Java compiler in maven

Here are few steps to configure protobuf-to-java compilation in your maven project:

Install google protobuf compiler on your computer.

Java-protobuf-format: Easy Protobuf-to-JSON Serialization in Java

If you need Google Protobuf-to-JSON serialization (and vice versa) there is quick solution. Protobuf-java-format library provides serialization of protobuf-generated java classes to number of formats: JSON, XML, HTML, Java property file format, Smile, CoachDB.

Here is a step-by-step instruction.

GWT is about to add Native JSON function support in version 2.1

GWT 2.1 has reached Milestone 2. One of the new features in version 2.1 is support for browser’s native JSON function in JSONParser class.

logo   Never miss a story, subscribe to our newsletter