From 2b658eae839e68df21617f3d8015c2246372af24 Mon Sep 17 00:00:00 2001 From: Sebastian Luna Date: Thu, 10 Sep 2020 19:55:56 -0500 Subject: [PATCH] BAEL-4387 Add AssertJ assertions --- java-collections-conversions-2/pom.xml | 6 ++++++ .../ArrayToListConversionUnitTest.java | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/java-collections-conversions-2/pom.xml b/java-collections-conversions-2/pom.xml index 0f7cdadeb202..23f20276a317 100644 --- a/java-collections-conversions-2/pom.xml +++ b/java-collections-conversions-2/pom.xml @@ -15,6 +15,12 @@ + + org.assertj + assertj-core + 3.17.2 + test + org.apache.commons commons-lang3 diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/arrayconversion/ArrayToListConversionUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/arrayconversion/ArrayToListConversionUnitTest.java index 80e7b93b0ccf..565c938d488c 100644 --- a/java-collections-conversions-2/src/test/java/com/baeldung/arrayconversion/ArrayToListConversionUnitTest.java +++ b/java-collections-conversions-2/src/test/java/com/baeldung/arrayconversion/ArrayToListConversionUnitTest.java @@ -1,5 +1,6 @@ package com.baeldung.arrayconversion; +import org.assertj.core.api.ListAssert; import org.hamcrest.CoreMatchers; import org.junit.Test; @@ -7,8 +8,7 @@ import java.util.Arrays; import java.util.List; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertArrayEquals; +import static org.assertj.core.api.Assertions.assertThat; public class ArrayToListConversionUnitTest { @@ -17,8 +17,8 @@ public void givenAnArray_whenConvertingToList_returnUnmodifiableListUnitTest() { String[] stringArray = new String[] { "A", "B", "C", "D" }; List stringList = Arrays.asList(stringArray); stringList.set(0, "E"); - assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D")); - assertArrayEquals(stringArray, new String[] { "E", "B", "C", "D" }); + assertThat(stringList).containsExactly("E", "B", "C", "D"); + assertThat(stringArray).containsExactly("E", "B", "C", "D"); stringList.add("F"); } @@ -27,9 +27,9 @@ public void givenAnArray_whenConvertingToList_returnModifiableListUnitTest() { String[] stringArray = new String[] { "A", "B", "C", "D" }; List stringList = new ArrayList<>(Arrays.asList(stringArray)); stringList.set(0, "E"); - assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D")); - assertArrayEquals(stringArray, new String[] { "A", "B", "C", "D" }); + assertThat(stringList).containsExactly("E", "B", "C", "D"); + assertThat(stringArray).containsExactly("A", "B", "C", "D"); stringList.add("F"); - assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D", "F")); + assertThat(stringList).containsExactly("E", "B", "C", "D", "F"); } }