I\'d like to use hamcrest to assert that two maps are equal, i.e. they have the same set of keys pointing to the same values.
My current best guess is:
a
If you need to compare a set of results with expectations and if you choose to use assertj library, you can do this:
// put set of expected values by your test keys
Map expectations = ...;
// for each test key get result
Map results = expectations.keySet().stream().collect(toMap(k -> k, k -> getYourProductionResult(k)));
assertThat(results).containsAllEntriesOf(expectations);
Note that containsAllEntriesOf
does not compare maps for equality. If your production code returns actually a Map
you may want to add a check for keys assertThat(results).containsOnlyKeys((K[]) expectations.keySet().toArray());