BAEL-4387 Change module

This commit is contained in:
Sebastian Luna 2020-09-02 07:46:50 -05:00
parent 68154fa540
commit 8d07e8fab9
1 changed files with 9 additions and 6 deletions

View File

@ -1,21 +1,24 @@
package com.baeldung.arrayconversion;
import org.hamcrest.CoreMatchers;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
public class ArrayToListConversionUnitTest {
@Test(expected = UnsupportedOperationException.class)
public void givenAnArray_whenConvertingToList_returnUnmodifiableListUnitTest() {
String[] stringArray = new String[] { "A", "B", "C", "D" };
List<String> stringList = Arrays.asList(stringArray);
System.out.println(stringList);
stringList.set(0, "E");
System.out.println(stringList);
System.out.println(Arrays.toString(stringArray));
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D"));
assertArrayEquals(stringArray, new String[] { "E", "B", "C", "D" });
stringList.add("F");
}
@ -23,10 +26,10 @@ public class ArrayToListConversionUnitTest {
public void givenAnArray_whenConvertingToList_returnModifiableListUnitTest() {
String[] stringArray = new String[] { "A", "B", "C", "D" };
List<String> stringList = new ArrayList<>(Arrays.asList(stringArray));
System.out.println(stringList);
stringList.set(0, "E");
System.out.println(stringList);
System.out.println(Arrays.toString(stringArray));
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D"));
assertArrayEquals(stringArray, new String[] { "A", "B", "C", "D" });
stringList.add("F");
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D", "F"));
}
}