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>
|
||||||
|
@ -102,10 +102,10 @@
|
||||||
<!-- persistence -->
|
<!-- persistence -->
|
||||||
<hibernate.version>4.3.0.Final</hibernate.version>
|
<hibernate.version>4.3.0.Final</hibernate.version>
|
||||||
<mysql-connector-java.version>5.1.27</mysql-connector-java.version>
|
<mysql-connector-java.version>5.1.27</mysql-connector-java.version>
|
||||||
|
|
||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<jackson.version>2.3.0</jackson.version>
|
<jackson.version>2.3.0</jackson.version>
|
||||||
|
|
||||||
<!-- logging -->
|
<!-- logging -->
|
||||||
<org.slf4j.version>1.7.5</org.slf4j.version>
|
<org.slf4j.version>1.7.5</org.slf4j.version>
|
||||||
<logback.version>1.0.11</logback.version>
|
<logback.version>1.0.11</logback.version>
|
||||||
|
|
|
@ -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…
Reference in New Issue