CollectionSizeAssertion¶
Issue ID CollectionSizeAssertion ·
Severity Warning ·
Category Productivity ·
Default on
Flags assertThat(collection.size).isEqualTo(n) where assertk's hasSize
should be used instead.
Why¶
hasSize is purpose-built for collection length assertions. The failure
message names the collection rather than just reporting a mismatched integer,
and the call reads more naturally. The detector specifically looks for .size
reads on subtypes of java.util.Collection followed by an isEqualTo
assertion from assertk.assertions.AnyKt.
Example¶
The detector also catches indirect reads:
Quick fix¶
Yes — the IDE rewrites the subject from collection.size to
collection, replaces isEqualTo(n) with hasSize(n), and adds the
assertk.assertions.hasSize import.