KeySetPresentAssertion¶
Issue ID KeySetPresentAssertion ·
Severity Warning ·
Category Usability ·
Default on
Flags assertThat(map.keys).contains(k) — checking key presence by
materialising the key set. Use Assert<Map<K, V>>.key(k) directly.
Why¶
assertThat(map.keys).contains(k) produces a generic "expected to contain X"
failure on a Set<K>. key(k) is purpose-built for the same intent and gives
a message that names the map. It also transforms the subject to the value
type, so you can chain further assertions if you want them.
Example¶
Quick fix¶
Yes — the IDE rewrites the entire assertThat(map.keys).contains(k)
expression to assertThat(map).key(k) and adds assertk.assertions.key.