collections work
This commit is contained in:
parent
d9b9c30aa2
commit
22ebf4a218
@ -64,7 +64,7 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>jackson</finalName>
|
<finalName>core-java</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
|
@ -1,7 +1,45 @@
|
|||||||
package org.baeldung.java;
|
package org.baeldung.java;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.ListUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
public class CoreJavaUnitTest {
|
public class CoreJavaUnitTest {
|
||||||
|
|
||||||
// tests -
|
// tests -
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenUsingTheJdk_whenArrayListIsSynchronized_thenCorrect() {
|
||||||
|
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||||
|
final List<String> synchronizedList = Collections.synchronizedList(list);
|
||||||
|
System.out.println("Synchronized List is: " + synchronizedList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
|
public final void givenUsingTheJdk_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
|
||||||
|
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||||
|
final List<String> unmodifiableList = Collections.unmodifiableList(list);
|
||||||
|
unmodifiableList.add("four");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
|
public final void givenUsingGuava_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
|
||||||
|
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||||
|
final List<String> unmodifiableList = ImmutableList.copyOf(list);
|
||||||
|
unmodifiableList.add("four");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
|
public final void givenUsingCommonsCollections_whenUnmodifiableListIsCreatedFromOriginal_thenNoLongerModifiable() {
|
||||||
|
final List<String> list = new ArrayList<String>(Arrays.asList("one", "two", "three"));
|
||||||
|
final List<String> unmodifiableList = ListUtils.unmodifiableList(list);
|
||||||
|
unmodifiableList.add("four");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user