New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optionally generate AssertJ assertions for generated Immutable types #1087
Comments
Can you show some example of assertions you want to be executed ? |
Would https://github.com/assertj/assertj-assertions-generator cover your needs instead? |
While not exactly assertions perhaps you can use Criteria generated DSL which has an expression evaluator already. One can easily write expressions (evaluators) like: Person p = ...;
assertThat(p, person
.nickName.startsWith("prefix")
.age.greaterThan(21));
// a nicer option (which is not supported yet) would be
assertThat(person).nickName.startsWith("prefix"); That DSL has already many "assertions" (we call them Matchers) |
I generated custom assertj assertions myself for AST matcher tests. |
Currently no. But Probably you can write your own evaluator which would print nice messages (it has all context information). Or, assuming AssertJ allows creating assertions programmatically, one can convert criteria expression into AssertJ assertion and let it be evaluated by AssertJ. |
Thanks for the pointer to the evaluator. It should indeed be possible to enhance that for assertJ like expressive messages. From what I remember from the assertj inner workings it's more comparable to the let's say builder code generated by immutables. There is no "runtime system" or "evaluator" that can be "programmed". |
It would be really cool, if at the same time as generating the immutable classes, custom assertions could be generated. AssertJ has an implementation which could be run from the annotation processor. This would mean clean tests when using in the same project or downstream.
Not sure how it would work. Maybe the processor could detect the presence of an assertion generator (AssertJ/Google Truth etc) and then generate.
There could be a an
assertion
flag on@Style?
or a new annotation?Many ways to do it.
The text was updated successfully, but these errors were encountered: