joel-costigliola/assertj-core — pull request #106 by brianlaframboise (2013-09-01 20:21:55+00:00)
Title: Add SoftAssertions

Adds a "soft assertion" capability (like that of TestNG's as described [here](http://beust.com/weblog/2012/07/29/reinventing-assertions/)) to AssertJ.

Currently a test case will only get as far as the first failed assertion. So, assuming goes awry at your dinner party, as test of:
```java
@Test
public void host_dinner_party_where_nobody_dies() {
Mansion mansion = new Mansion();
mansion.hostPotentiallyMurderousDinnerParty();
assertThat(mansion.guests()).as("Living Guests").isEqualTo(7);
assertThat(mansion.kitchen()).as("Kitchen").isEqualTo("clean");
assertThat(mansion.library()).as("Library").isEqualTo("clean");
assertThat(mansion.revolverAmmo()).as("Revolver Ammo").isEqualTo(6);
assertThat(mansion.candlestick()).as("Candlestick").isEqualTo("pristine");
assertThat(mansion.colonel()).as("Colonel").isEqualTo("well kempt");
assertThat(mansion.professor()).as("Professor").isEqualTo("well kempt");
}
```
will yield the less-than-ideal exception message of `org.junit.ComparisonFailure: [Living Guests] expected:<[7]> but was<[6]>`.

Using soft assertions you can collect all the failed assertions together like so:

```java
@Test
public void host_dinner_party_where_nobody_dies() {
Mansion mansion = new Mansion();
mansion.hostPotentiallyMurderousDinnerParty();
SoftAssertions softly = new SoftAssertions();
softly.assertThat(mansion.guests()).as("Living Guests").isEqualTo(7);
softly.assertThat(mansion.kitchen()).as("Kitchen").isEqualTo("clean");
softly.assertThat(mansion.library()).as("Library").isEqualTo("clean");
softly.assertThat(mansion.revolverAmmo()).as("Revolver Ammo").isEqualTo(6);
softly.assertThat(mansion.candlestick()).as("Candlestick").isEqualTo("pristine");
softly.assertThat(mansion.colonel()).as("Colonel").isEqualTo("well kempt");
softly.assertThat(mansion.professor()).as("Professor").isEqualTo("well kempt");
softly.assertAll();
}
```
When the collected assertions are all asserted together they yield a more descriptive error message:
```
org.assertj.core.api.SoftAssertionError: The following 4 assertions failed:
1) [Living Guests] expected:<[7]> but was:<[6]>
2) [Library] expected:<'[clean]'> but was:<'[messy]'>
3) [Candlestick] expected:<'[pristine]'> but was:<'[bent]'>
4) [Professor] expected:<'[well kempt]'> but was:<'[bloodied and disheveled]'>
```

See the SoftAssertions javadoc for the full details.

Note: This does add an optional Maven dependency on `cglib-nodep 2.2.2`.