Skip to content

Instantly share code, notes, and snippets.

@hugomarques
Last active January 2, 2019 05:49
Show Gist options
  • Select an option

  • Save hugomarques/a6d05f7154f464bb047c4803678a7781 to your computer and use it in GitHub Desktop.

Select an option

Save hugomarques/a6d05f7154f464bb047c4803678a7781 to your computer and use it in GitHub Desktop.
package com.hugodesmarques.assertJ;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Samples how to use AssertJ to test a Map.
* @author hugomarques
* 10/22/16.
*/
public class AssertJMapTest {
@Test
public void testMapsAreTheSame() {
ImmutableMap<String, String> expectedCreatureByType = ImmutableMap.of(
"Red Dragon", "Dragon",
"Vampire","undead",
"Ghoul","undead",
"Cloud Giant","Giant"
);
ImmutableMap<String, String> clonedMap = SerializationUtils.clone(expectedCreatureByType);
assertThat(expectedCreatureByType)
.containsAllEntriesOf(clonedMap);
}
@Test
public void testDifferentAssertJMatchers() {
ImmutableMap<String, String> expectedCreatureByType = ImmutableMap.of(
"Red Dragon", "Dragon",
"Vampire","undead",
"Ghoul","undead",
"Cloud Giant","Giant"
);
assertThat(expectedCreatureByType.get("Unicorn"))
.isNull();
assertThat(expectedCreatureByType.get("Vampire"))
.isNotNull();
assertThat(expectedCreatureByType.get("Vampire"))
.isEqualToIgnoringCase("UNDEAD");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment