Merge pull request #9967 from Sebassllr/feature/BAEL-4387
Sebassllr/sebaslunasllr@gmail.com
This commit is contained in:
commit
60b789111a
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue