-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved keys assertions in ObservationContextAssert (#3266)
The first part of this change adds two assertions around keys (considering both low cardinality and high cardinality KeyValues). It is currently possible to individually assert specific keys are present, either focusing on the key itself being there or specifying the expected key and value pair. For example `hasLowCardinalityKeyValueWithKey("k")` or `hasHighCardinalityKeyValue("k", "v")`). But it isn't possible to quickly also make sure that no other keys are present outside of the ones asserted via these methods. Let's imagine my `actual` has 3 keys "A", "B" and "C" but I only expect "A" and "B": without having prior knowledge of "C", its absence cannot be asserted. Adding `hasKeyValuesCount` is a good complement for this: in the example having `hasKeyValuesCount(2)` would fail with a message indicating 3 keys are present instead of 2. Adding `hasOnlyKeys` could also serve the same purpose if the only concern is having the keys, whatever the values are. As such `hasOnlyKeys("A", "B")` in the example would fail with a message saying that extraneous key "C" was found. `hasOnlyKeys("A", "B", "C", "D")` would also fail with a message stating that key "D" is missing. The second part of this change fixes a counterintuitive behaviour of the `doesNotHave[High|Low]LevelKeyValue(String, String)` assertions: if the key is present with another value than the one specified, the assertion currently fails by complaining the key is present. But if both a key _and a value_ are specified then only that specific pair should be undesirable. So for that same key we should accept values that do not match the one specified. (for a similar example in AssertJ core, see `Map`'s `containsEntry` assertion).
- Loading branch information
1 parent
21d450b
commit 512b1de
Showing
2 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters