diff options
Diffstat (limited to 'guava-tests/test/com/google/common/collect/ImmutableListTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/collect/ImmutableListTest.java | 76 |
1 files changed, 23 insertions, 53 deletions
diff --git a/guava-tests/test/com/google/common/collect/ImmutableListTest.java b/guava-tests/test/com/google/common/collect/ImmutableListTest.java index e53fabf..ced0635 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableListTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableListTest.java @@ -28,6 +28,7 @@ import com.google.common.collect.testing.Helpers; import com.google.common.collect.testing.ListTestSuiteBuilder; import com.google.common.collect.testing.MinimalCollection; import com.google.common.collect.testing.MinimalIterable; +import com.google.common.collect.testing.TestStringListGenerator; import com.google.common.collect.testing.features.CollectionFeature; import com.google.common.collect.testing.features.CollectionSize; import com.google.common.collect.testing.google.ListGenerators.BuilderAddAllListGenerator; @@ -48,7 +49,6 @@ import junit.framework.TestSuite; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -65,53 +65,56 @@ import java.util.concurrent.CopyOnWriteArrayList; */ @GwtCompatible(emulated = true) public class ImmutableListTest extends TestCase { - + @GwtIncompatible("suite") public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(ListTestSuiteBuilder.using(new ImmutableListOfGenerator()) .named("ImmutableList") .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES) .createTestSuite()); suite.addTest(ListTestSuiteBuilder.using(new BuilderAddAllListGenerator()) .named("ImmutableList, built with Builder.add") .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES) .createTestSuite()); suite.addTest(ListTestSuiteBuilder.using(new BuilderAddAllListGenerator()) .named("ImmutableList, built with Builder.addAll") .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES) .createTestSuite()); suite.addTest(ListTestSuiteBuilder.using(new BuilderReversedListGenerator()) .named("ImmutableList, reversed") .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, + CollectionFeature.ALLOWS_NULL_QUERIES) + .createTestSuite()); + suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() { + @Override protected List<String> create(String[] elements) { + return SerializableTester.reserialize( + ImmutableList.copyOf(elements)); + } + }) + .named("ImmutableList, reserialized") + .withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES) .createTestSuite()); suite.addTest(ListTestSuiteBuilder.using( new ImmutableListHeadSubListGenerator()) .named("ImmutableList, head subList") .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES) .createTestSuite()); suite.addTest(ListTestSuiteBuilder.using( new ImmutableListTailSubListGenerator()) .named("ImmutableList, tail subList") .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES) .createTestSuite()); suite.addTest(ListTestSuiteBuilder.using( new ImmutableListMiddleSubListGenerator()) .named("ImmutableList, middle subList") .withFeatures(CollectionSize.ANY, - CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES) .createTestSuite()); suite.addTest(ListTestSuiteBuilder.using( @@ -194,7 +197,7 @@ public class ImmutableListTest extends TestCase { } // Varargs versions - + public void testCreation_twelveElements() { List<String> list = ImmutableList.of( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"); @@ -244,7 +247,7 @@ public class ImmutableListTest extends TestCase { String[] array = new String[] { "a" }; List<String[]> list = ImmutableList.<String[]>of(array); assertEquals(Collections.singletonList(array), list); - } + } public void testCopyOf_emptyArray() { String[] array = new String[0]; @@ -262,7 +265,7 @@ public class ImmutableListTest extends TestCase { try { ImmutableList.copyOf((String[]) null); fail(); - } catch(NullPointerException expected) { + } catch(NullPointerException expected) { } } @@ -333,7 +336,7 @@ public class ImmutableListTest extends TestCase { } catch (NullPointerException expected) { } } - + public void testCopyOf_iteratorNull() { try { ImmutableList.copyOf((Iterator<String>) null); @@ -341,7 +344,7 @@ public class ImmutableListTest extends TestCase { } catch(NullPointerException expected) { } } - + public void testCopyOf_concurrentlyMutating() { List<String> sample = Lists.newArrayList("a", "b", "c"); for (int delta : new int[] {-1, 0, 1}) { @@ -392,44 +395,10 @@ public class ImmutableListTest extends TestCase { Collection<String> c = ImmutableList.of("a", "b", "c"); assertSame(c, ImmutableList.copyOf(c)); } - - public void testBuilderAddArrayHandlesNulls() { - String[] elements = {"a", null, "b"}; - ImmutableList.Builder<String> builder = ImmutableList.builder(); - try { - builder.add(elements); - fail ("Expected NullPointerException"); - } catch (NullPointerException expected) { - } - ImmutableList<String> result = builder.build(); - - /* - * Maybe it rejects all elements, or maybe it adds "a" before failing. - * Either way is fine with us. - */ - if (result.isEmpty()) { - return; - } - assertTrue(ImmutableList.of("a").equals(result)); - assertEquals(1, result.size()); - } - - public void testBuilderAddCollectionHandlesNulls() { - List<String> elements = Arrays.asList("a", null, "b"); - ImmutableList.Builder<String> builder = ImmutableList.builder(); - try { - builder.addAll(elements); - fail ("Expected NullPointerException"); - } catch (NullPointerException expected) { - } - ImmutableList<String> result = builder.build(); - assertEquals(ImmutableList.of("a"), result); - assertEquals(1, result.size()); - } } - + @GwtIncompatible("reflection") - public static class ConcurrentTests extends TestCase { + public static class ConcurrentTests extends TestCase { enum WrapWithIterable { WRAP, NO_WRAP } private static void runConcurrentlyMutatedTest( @@ -635,11 +604,11 @@ public class ImmutableListTest extends TestCase { return list; } } - + public static class BasicTests extends TestCase { @GwtIncompatible("NullPointerTester") - public void testNullPointers() { + public void testNullPointers() throws Exception { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicStaticMethods(ImmutableList.class); tester.testAllPublicInstanceMethods(ImmutableList.of(1, 2, 3)); @@ -654,7 +623,8 @@ public class ImmutableListTest extends TestCase { @GwtIncompatible("SerializableTester") public void testSerialization_singleton() { Collection<String> c = ImmutableList.of("a"); - SerializableTester.reserializeAndAssert(c); + ImmutableList<String> copy = (SingletonImmutableList<String>) + SerializableTester.reserializeAndAssert(c); } @GwtIncompatible("SerializableTester") |