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.

Revisions

  1. hugomarques revised this gist Jan 2, 2019. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions AssertJMapTest.java
    Original file line number Diff line number Diff line change
    @@ -7,13 +7,14 @@
    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 testAssertMap() {
    public void testMapsAreTheSame() {
    ImmutableMap<String, String> expectedCreatureByType = ImmutableMap.of(
    "Red Dragon", "Dragon",
    "Vampire","undead",
    @@ -27,7 +28,7 @@ public void testAssertMap() {
    }

    @Test
    public void testAssertRandom() {
    public void testDifferentAssertJMatchers() {
    ImmutableMap<String, String> expectedCreatureByType = ImmutableMap.of(
    "Red Dragon", "Dragon",
    "Vampire","undead",
  2. hugomarques created this gist Oct 23, 2016.
    46 changes: 46 additions & 0 deletions AssertJMapTest.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    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;

    /**
    * @author hugomarques
    * 10/22/16.
    */
    public class AssertJMapTest {

    @Test
    public void testAssertMap() {
    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 testAssertRandom() {
    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");
    }

    }