Skip to content

Instantly share code, notes, and snippets.

@mchmielarz
Last active December 14, 2019 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchmielarz/afb5fa2db3e4c7c4e61b4df4a016eda2 to your computer and use it in GitHub Desktop.
Save mchmielarz/afb5fa2db3e4c7c4e61b4df4a016eda2 to your computer and use it in GitHub Desktop.
MultimapAssert in assertj-vavr v0.2.0
// given
private static final Tuple2<String, String> FRODO = Tuple.of("hobbit", "frodo");
private static final Tuple2<String, String> SAM = Tuple.of("hobbit", "sam");
private static final Tuple2<String, String> GIMLI = Tuple.of("dwarf", "gimli");
private static final Tuple2<String, String> LEGOLAS = Tuple.of("elf", "legolas");
private static final Multimap<String, String> RACES =
HashMultimap.withSeq().ofEntries(FRODO, SAM, GIMLI);
private static final BiConsumer<String, String> OK_CONSUMER = (key, value) -> Assertions.assertThat(key).isLowerCase();
// somewhere in tests
assertThat(RACES).allSatisfy(OK_CONSUMER)
.containsAnyOf(FRODO, LEGOLAS)
.contains(FRODO)
.containsAllEntriesOf(List.of(FRODO, GIMLI))
.containsEntry("hobbit", "frodo")
.containsExactly(GIMLI, SAM, FRODO)
.containsKey("hobbit")
.containsKeys("hobbit", "dwarf")
.containsOnly(List.of(SAM, FRODO, GIMLI))
.containsOnlyKeys("hobbit", "dwarf")
.containsValue("frodo")
.containsValues("frodo", "gimli")
.doesNotContainEntry("elf", "legolas")
.doesNotContain(LEGOLAS)
.doesNotContainKey("elf")
.doesNotContainKeys("elf", "man")
.doesNotContainValue("legolas")
.doesNotContainValues("legolas", "aragorn")
.hasSameSizeAs(new String[]{"frodo", "gimli", "sam"})
.hasSameSizeAs(Array.of(FRODO, GIMLI, SAM))
.hasSize(3)
.isNotEmpty(); // and isEmpty() / isNullOrEmpty()
assertThat(RACES).hasEntrySatisfying("hobbit", new Condition<String>() {
@Override
public boolean matches(String value) {
return value.equals("sam");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment