-
Notifications
You must be signed in to change notification settings - Fork 88
Add transformers Map<K,V>.havingKeys()
and Map<K,V>.havingValues()
#557
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
base: main
Are you sure you want to change the base?
Conversation
Do any other "having"-style functions also perform an implicit assertion? Really my only criticism of this approach is that there's something pure in the "having" suite of functions being purely transformational in contrast to actual validation functions. There's nothing strictly wrong with doing |
I did find some examples, such as |
@JakeWharton I admittedly was on the fence here (and I'm definitely open to removing the assertion). |
This seems analogous to #546 (function names in that PR notwithstanding). |
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.
One comment and the rest is LGTM
@Test | ||
fun havingValues_empty_list_fails() { | ||
val error = assertFailsWith<AssertionError> { | ||
assertThat(emptyMap<String, String>()).havingKeys() |
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.
Should it be havingValues()
?
This adds some transformers allowing you to utilize
Collection
asserts on parts of a map.Example for keys:
Example for values:
Given that there is already a
Map<K,V>.isNotEmpty()
I thought it made sense to have these transformers throw an error if their corresponding parts have no values.fixes #527