-
Notifications
You must be signed in to change notification settings - Fork 39
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
Introduce AssertThatMapContainsOnlyKeys
Refaster rule
#576
Conversation
Looks good. No mutations were possible for these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a small commit and tweaked the suggested commit message. Nice:)
@BeforeTemplate | ||
AbstractAssert<?, ?> before(Map<K, V> map, Set<K> keys) { | ||
return assertThat(map.keySet()).hasSameElementsAs(keys); | ||
} | ||
|
||
@AfterTemplate | ||
@UseImportPolicy(STATIC_IMPORT_ALWAYS) | ||
AbstractAssert<?, ?> after(Map<K, V> map, Set<K> keys) { | ||
return assertThat(map).containsOnlyKeys(keys); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change the return types to make clear that what we're doing here (like with many of the other rules) potentially breaks some code.
Looks good. No mutations were possible for these changes. |
@@ -131,7 +131,7 @@ MapAssert<Integer, Integer> testAbstractMapAssertHasSameSizeAs() { | |||
} | |||
|
|||
AbstractAssert<?, ?> testAssertThatMapContainsOnlyKeys() { | |||
return assertThat(ImmutableMap.of(1, 2).keySet()).hasSameElementsAs(ImmutableSet.of(1)); | |||
return assertThat(ImmutableMap.of(1, 2).keySet()).hasSameElementsAs(ImmutableSet.of(3)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 🚀
I have seen this pattern everywhere but I cant fully understand the reasning behind this.
Why arent we using correct expected values ? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I wouldn't say we're fully consistent in this respect. But in new code I try to use distinct values, so that we properly validate that Refaster correctly "shuffles things around". (And since the code isn't executed anyway... 🙃.)
399f7d4
to
fca2848
Compare
Looks good. No mutations were possible for these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM! Nice, another contribution @mohamedsamehsalah 🚀!
@werli do you want to take a look as well 😄?
fca2848
to
23fe7c6
Compare
Looks good. No mutations were possible for these changes. |
containsOnlyKeys
when asserting keySets of a mapAssertThatMapContainsOnlyKeys
Refaster rule
Original suggestion here.
Suggested commit message: