I'm a bit fan of Google's Truth.dev library. I have a large domain model in Java, and want to add several little custom assertions for them in my own Subject files. It's a bit of pain though to create the boiler plate for the Subjects every time though, and there are lot's obvious / straight forward assertions that I'd like to have by default.
Something similar to AssertJ's generator project.
For example, given the following simple model (mine is much more complicated):
@lombok.Value
public class Car {
String name;
Make make;
int colourId;
public enum Make {PLASTIC, METAL}
}
I would like to be able to do the following without coding anything myself:
assertThat(car).hasMakeEqualTo(PLASTIC);
assertThat(car).hasColourId().isAtLeast(5);
assertThat(car).hasName().ignoringTrailingWhiteSpace().equalTo("sally");
or
assertThat(person).hasAddress().hasStreet().ignoringCase().endsWith('Rd')
Upon my discovery of the lovely Google Truth, I was an instant convert from AssertJ. However I didn't like the boiler plate required to the get the full potential out of it. I also had just found AssertJ's code generator. So I made one for Google Truth.
You can find out everything about it on it's GitHub page.
Assertion failures for the assertions in the stated question with Truth look like:
To achieve the above, you simply add it to your build.
It is very powerful and flexible. Very keen to get feedback and implement more ideas.