assertj
describedAs
assertThat(false).describedAs("Message to help with passing test").isTrue();custom asssertions
public class CoffeeAssert extends AbstractAssert<CoffeeAssert, Coffee> {
public CoffeeAssert(Coffee actual) {
super(actual, CoffeeAssert.class);
}
public static CoffeeAssert assertThat(Coffee actual) {
return new CoffeeAssert(actual);
}
public CoffeeAssert hasType(Coffee.Type type) {
isNotNull();
if (actual.getType() != type) {
failWithMessage("Expected the coffee type to be <%s> but was <%s>", type, actual.getType());
}
return this;
}
// hasStrength(Strength) omitted ...
public CoffeeAssert isNotDecaf() {
isNotNull();
if (actual.getStrength() == Coffee.Strength.DECAF) {
failWithMessage("Expected a coffee but got decaf!");
}
return this;
}
}Last updated