Last active
January 2, 2019 05:49
-
-
Save hugomarques/a6d05f7154f464bb047c4803678a7781 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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