Cleanly handle exceptions in tests with Lambdas

If you have been writing tests for some time then the following construct should be pretty familiar to you for handling test cases: @Test public void myTest() { // Test something here... try { // Test something that will throw SomeException Assert.fail("Test did not throw expected exception."); } catch (SomeException e) { // Expected } // Test something here... } This has annoyed me some time already as it makes a clean looking test just plain ugly and I have been looking for a way to clean this mess up. You might at this point now argue that you could split the test up in smaller »