BAEL-4387 Change module
This commit is contained in:
parent
68154fa540
commit
8d07e8fab9
@ -1,21 +1,24 @@
|
|||||||
package com.baeldung.arrayconversion;
|
package com.baeldung.arrayconversion;
|
||||||
|
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
public class ArrayToListConversionUnitTest {
|
public class ArrayToListConversionUnitTest {
|
||||||
|
|
||||||
@Test(expected = UnsupportedOperationException.class)
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
public void givenAnArray_whenConvertingToList_returnUnmodifiableListUnitTest() {
|
public void givenAnArray_whenConvertingToList_returnUnmodifiableListUnitTest() {
|
||||||
String[] stringArray = new String[] { "A", "B", "C", "D" };
|
String[] stringArray = new String[] { "A", "B", "C", "D" };
|
||||||
List<String> stringList = Arrays.asList(stringArray);
|
List<String> stringList = Arrays.asList(stringArray);
|
||||||
System.out.println(stringList);
|
|
||||||
stringList.set(0, "E");
|
stringList.set(0, "E");
|
||||||
System.out.println(stringList);
|
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D"));
|
||||||
System.out.println(Arrays.toString(stringArray));
|
assertArrayEquals(stringArray, new String[] { "E", "B", "C", "D" });
|
||||||
stringList.add("F");
|
stringList.add("F");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,10 +26,10 @@ public class ArrayToListConversionUnitTest {
|
|||||||
public void givenAnArray_whenConvertingToList_returnModifiableListUnitTest() {
|
public void givenAnArray_whenConvertingToList_returnModifiableListUnitTest() {
|
||||||
String[] stringArray = new String[] { "A", "B", "C", "D" };
|
String[] stringArray = new String[] { "A", "B", "C", "D" };
|
||||||
List<String> stringList = new ArrayList<>(Arrays.asList(stringArray));
|
List<String> stringList = new ArrayList<>(Arrays.asList(stringArray));
|
||||||
System.out.println(stringList);
|
|
||||||
stringList.set(0, "E");
|
stringList.set(0, "E");
|
||||||
System.out.println(stringList);
|
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D"));
|
||||||
System.out.println(Arrays.toString(stringArray));
|
assertArrayEquals(stringArray, new String[] { "A", "B", "C", "D" });
|
||||||
stringList.add("F");
|
stringList.add("F");
|
||||||
|
assertThat(stringList, CoreMatchers.hasItems("E", "B", "C", "D", "F"));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user