Assertj-core: Feature request: mechanism to raise exception on malformed assertions

Created on 10 Oct 2018  路  3Comments  路  Source: assertj/assertj-core

Summary

I wonder if there is a way to implement a clever mechanism that makes malformed assertions raise an exception. Juniors sometimes struggle with the syntax. I think that would lower the entry barrier for beginners.

Example

List<String> list = Arrays.asList("Alice", "Bob");
assertThat(list.contains("Alice")); // incorrect (malformed - no assertion happens here)
assertThat(list).contains("Alice"); // correct
duplicate

All 3 comments

Static code inspection tools like ErrorProne, SpotBugs and Findbugs can detect these kind of errors.

See discussion in https://github.com/joel-costigliola/assertj-core/issues/979 for details.

As @PascalSchumacher said it's a job static code analysis for.
There's not much more AssertJ can do about it unfortunately, using SpotBugs addresses your example BTW.

We installed SpotBugs for Eclipse and got orange bugs. :-)
Thank you both @joel-costigliola and @PascalSchumacher.

Was this page helpful?
0 / 5 - 0 ratings