KentBeck/junit — pull request #377 by pettermahlen (2012-02-08 16:22:53+00:00)
Title: Enable ExpectedException to match causes more easily

When working especially with third-party libraries, it's common to deal with checked exceptions in a way similar to this:

```java
try {
collaborator.something();
}
catch (CheckedException e) {
throw new MyRuntimeException("failed to do something", e);
}
```

It's common for different instances of MyRuntimeException to be thrown from many possible execution branches, so when testing this, I would like to do something like:

```java
@Rule
ExpectedException thrown= ExpectedException.none();

@Test
public void aTest() throws Exception {
CheckedException expected = new CheckedException("expected");

Mockito.when(collaborator.something()).thenThrow(expected);

thrown.expect(MyRuntimeException.class);
thrown.expectMessage("failed to do something");
thrown.expectCause(expected);

myObject.method();
}
```

The change in this pull request makes that possible. I realise you can do that with a custom matcher as well, but it feels like this is (at least nearly) as fundamental as matching on the message, so it should perhaps be a part of the core framework?