aboutsummaryrefslogtreecommitdiffstats
path: root/guava-testlib/test/com/google/common/collect/testing
diff options
context:
space:
mode:
Diffstat (limited to 'guava-testlib/test/com/google/common/collect/testing')
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilderTest.java83
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/HelpersTest.java33
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/IteratorTesterTest.java349
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/MapTestSuiteBuilderTests.java117
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/MinimalCollectionTest.java52
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/MinimalIterableTest.java106
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/MinimalSetTest.java47
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/OpenJdk6ListTests.java70
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/OpenJdk6MapTests.java57
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/OpenJdk6QueueTests.java50
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/OpenJdk6SetTests.java61
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/OpenJdk6Tests.java39
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/SafeTreeMapTest.java126
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java106
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/features/FeatureEnumTest.java108
-rw-r--r--guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java284
16 files changed, 0 insertions, 1688 deletions
diff --git a/guava-testlib/test/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilderTest.java b/guava-testlib/test/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilderTest.java
deleted file mode 100644
index 2e0d594..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilderTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2011 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import com.google.common.collect.testing.features.CollectionFeature;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Max Ross
- */
-public class FeatureSpecificTestSuiteBuilderTest extends TestCase {
-
- static boolean testWasRun;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- testWasRun = false;
- }
-
- public static final class MyAbstractTester extends AbstractTester {
- public void testNothing() {
- testWasRun = true;
- }
- }
-
- private static final class MyTestSuiteBuilder extends
- FeatureSpecificTestSuiteBuilder<MyTestSuiteBuilder, String> {
-
- @Override
- protected List<Class<? extends AbstractTester>> getTesters() {
- return Collections.<Class<? extends AbstractTester>>singletonList(MyAbstractTester.class);
- }
- }
-
- public void testLifecycle() {
- final boolean setUp[] = {false};
- Runnable setUpRunnable = new Runnable() {
- @Override
- public void run() {
- setUp[0] = true;
- }
- };
-
- final boolean tearDown[] = {false};
- Runnable tearDownRunnable = new Runnable() {
- @Override
- public void run() {
- tearDown[0] = true;
- }
- };
-
- MyTestSuiteBuilder builder = new MyTestSuiteBuilder();
- Test test = builder.usingGenerator("yam").named("yam")
- .withFeatures(CollectionFeature.NONE).withSetUp(setUpRunnable)
- .withTearDown(tearDownRunnable).createTestSuite();
- TestResult result = new TestResult();
- test.run(result);
- assertTrue(testWasRun);
- assertTrue(setUp[0]);
- assertTrue(tearDown[0]);
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/HelpersTest.java b/guava-testlib/test/com/google/common/collect/testing/HelpersTest.java
deleted file mode 100644
index 5c1432b..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/HelpersTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.collect.testing.Helpers.NullsBeforeB;
-import static com.google.common.collect.testing.Helpers.testComparator;
-
-import junit.framework.TestCase;
-
-/**
- * Unit test for {@link Helpers}.
- *
- * @author Chris Povirk
- */
-public class HelpersTest extends TestCase {
- public void testNullsBeforeB() {
- testComparator(NullsBeforeB.INSTANCE, "a", "azzzzzz", null, "b", "c");
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/IteratorTesterTest.java b/guava-testlib/test/com/google/common/collect/testing/IteratorTesterTest.java
deleted file mode 100644
index e272ec0..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/IteratorTesterTest.java
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
- * Copyright (C) 2008 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE;
-import static java.util.Collections.emptyList;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * Unit test for IteratorTester.
- *
- * @author Mick Killianey
- */
-@SuppressWarnings("serial") // No serialization is used in this test
-public class IteratorTesterTest extends TestCase {
-
- public void testCanCatchDifferentLengthOfIteration() {
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(4, MODIFIABLE, newArrayList(1, 2, 3),
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return Lists.newArrayList(1, 2, 3, 4).iterator();
- }
- };
- assertFailure(tester);
- }
-
- public void testCanCatchDifferentContents() {
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(3, MODIFIABLE, newArrayList(1, 2, 3),
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return Lists.newArrayList(1, 3, 2).iterator();
- }
- };
- assertFailure(tester);
- }
-
- public void testCanCatchDifferentRemoveBehaviour() {
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(3, MODIFIABLE, newArrayList(1, 2),
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return ImmutableList.of(1, 2).iterator();
- }
- };
- assertFailure(tester);
- }
-
- public void testUnknownOrder() {
- new IteratorTester<Integer>(3, MODIFIABLE, newArrayList(1, 2),
- IteratorTester.KnownOrder.UNKNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return newArrayList(2, 1).iterator();
- }
- }.test();
- }
-
- public void testUnknownOrderUnrecognizedElement() {
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(3, MODIFIABLE, newArrayList(1, 2, 50),
- IteratorTester.KnownOrder.UNKNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return newArrayList(2, 1, 3).iterator();
- }
- };
- assertFailure(tester);
- }
-
- /**
- * This Iterator wraps another iterator and gives it a bug found
- * in JDK6.
- *
- * <p>This bug is this: if you create an iterator from a TreeSet
- * and call next() on that iterator when hasNext() is false, so
- * that next() throws a NoSuchElementException, then subsequent
- * calls to remove() will incorrectly throw an IllegalStateException,
- * instead of removing the last element returned.
- *
- * <p>See
- * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6529795">
- * Sun bug 6529795</a>
- */
- static class IteratorWithSunJavaBug6529795<T> implements Iterator<T> {
- Iterator<T> iterator;
- boolean nextThrewException;
- IteratorWithSunJavaBug6529795(Iterator<T> iterator) {
- this.iterator = iterator;
- }
-
- @Override
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- @Override
- public T next() {
- try {
- return iterator.next();
- } catch (NoSuchElementException e) {
- nextThrewException = true;
- throw e;
- }
- }
-
- @Override
- public void remove() {
- if (nextThrewException) {
- throw new IllegalStateException();
- }
- iterator.remove();
- }
- }
-
- public void testCanCatchSunJavaBug6529795InTargetIterator() {
- try {
- /* Choose 4 steps to get sequence [next, next, next, remove] */
- new IteratorTester<Integer>(4, MODIFIABLE, newArrayList(1, 2),
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- Iterator<Integer> iterator = Lists.newArrayList(1, 2).iterator();
- return new IteratorWithSunJavaBug6529795<Integer>(iterator);
- }
- }.test();
- } catch (AssertionFailedError e) {
- return;
- }
- fail("Should have caught jdk6 bug in target iterator");
- }
-
- public void testCanWorkAroundSunJavaBug6529795InTargetIterator() {
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(4, MODIFIABLE, newArrayList(1, 2),
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- Iterator<Integer> iterator = Lists.newArrayList(1, 2).iterator();
- return new IteratorWithSunJavaBug6529795<Integer>(iterator);
- }
- };
-
- /*
- * Calling this method on an IteratorTester should avoid flagging
- * the bug exposed by the preceding test.
- */
- tester.ignoreSunJavaBug6529795();
-
- tester.test();
- }
-
- private static final int STEPS = 3;
- static class TesterThatCountsCalls extends IteratorTester<Integer> {
- TesterThatCountsCalls() {
- super(STEPS, MODIFIABLE, newArrayList(1),
- IteratorTester.KnownOrder.KNOWN_ORDER);
- }
- int numCallsToNewTargetIterator;
- int numCallsToVerify;
- @Override protected Iterator<Integer> newTargetIterator() {
- numCallsToNewTargetIterator++;
- return Lists.newArrayList(1).iterator();
- }
- @Override protected void verify(List<Integer> elements) {
- numCallsToVerify++;
- super.verify(elements);
- }
- }
-
- public void testVerifyGetsCalled() {
- TesterThatCountsCalls tester = new TesterThatCountsCalls();
-
- tester.test();
-
- assertEquals("Should have verified once per stimulus executed",
- tester.numCallsToVerify,
- tester.numCallsToNewTargetIterator * STEPS);
- }
-
- public void testVerifyCanThrowAssertionThatFailsTest() {
- final String message = "Important info about why verify failed";
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(1, MODIFIABLE, newArrayList(1, 2, 3),
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return Lists.newArrayList(1, 2, 3).iterator();
- }
-
- @Override protected void verify(List<Integer> elements) {
- throw new AssertionFailedError(message);
- }
- };
- AssertionFailedError actual = null;
- try {
- tester.test();
- } catch (AssertionFailedError e) {
- actual = e;
- }
- assertNotNull("verify() should be able to cause test failure", actual);
- assertTrue("AssertionFailedError should have info about why test failed",
- actual.getCause().getMessage().contains(message));
- }
-
- public void testMissingException() {
- List<Integer> emptyList = newArrayList();
-
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(1, MODIFIABLE, emptyList,
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return new Iterator<Integer>() {
- @Override
- public void remove() {
- // We should throw here, but we won't!
- }
- @Override
- public Integer next() {
- // We should throw here, but we won't!
- return null;
- }
- @Override
- public boolean hasNext() {
- return false;
- }
- };
- }
- };
- assertFailure(tester);
- }
-
- public void testUnexpectedException() {
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(1, MODIFIABLE, newArrayList(1),
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return new ThrowingIterator<Integer>(new IllegalStateException());
- }
- };
- assertFailure(tester);
- }
-
- public void testSimilarException() {
- List<Integer> emptyList = emptyList();
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(1, MODIFIABLE, emptyList,
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return new Iterator<Integer>() {
- @Override
- public void remove() {
- throw new IllegalStateException() { /* subclass */};
- }
- @Override
- public Integer next() {
- throw new NoSuchElementException() { /* subclass */};
- }
- @Override
- public boolean hasNext() {
- return false;
- }
- };
- }
- };
- tester.test();
- }
-
- public void testMismatchedException() {
- List<Integer> emptyList = emptyList();
- IteratorTester<Integer> tester =
- new IteratorTester<Integer>(1, MODIFIABLE, emptyList,
- IteratorTester.KnownOrder.KNOWN_ORDER) {
- @Override protected Iterator<Integer> newTargetIterator() {
- return new Iterator<Integer>() {
- @Override
- public void remove() {
- // Wrong exception type.
- throw new IllegalArgumentException();
- }
- @Override
- public Integer next() {
- // Wrong exception type.
- throw new UnsupportedOperationException();
- }
- @Override
- public boolean hasNext() {
- return false;
- }
- };
- }
- };
- assertFailure(tester);
- }
-
- private static void assertFailure(IteratorTester<?> tester) {
- try {
- tester.test();
- fail();
- } catch (AssertionFailedError expected) {
- }
- }
-
- private static final class ThrowingIterator<E> implements Iterator<E> {
- private final RuntimeException ex;
-
- private ThrowingIterator(RuntimeException ex) {
- this.ex = ex;
- }
-
- @Override
- public boolean hasNext() {
- // IteratorTester doesn't expect exceptions for hasNext().
- return true;
- }
-
- @Override
- public E next() {
- ex.fillInStackTrace();
- throw ex;
- }
-
- @Override
- public void remove() {
- ex.fillInStackTrace();
- throw ex;
- }
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/MapTestSuiteBuilderTests.java b/guava-testlib/test/com/google/common/collect/testing/MapTestSuiteBuilderTests.java
deleted file mode 100644
index 43b1983..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/MapTestSuiteBuilderTests.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2008 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.features.MapFeature;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.util.AbstractMap;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Tests {@link MapTestSuiteBuilder} by using it against maps that have various
- * negative behaviors.
- *
- * @author George van den Driessche
- */
-public final class MapTestSuiteBuilderTests extends TestCase {
- private MapTestSuiteBuilderTests() {}
-
- public static Test suite() {
- TestSuite suite = new TestSuite(
- MapTestSuiteBuilderTests.class.getSimpleName());
- suite.addTest(testsForHashMapNullKeysForbidden());
- suite.addTest(testsForHashMapNullValuesForbidden());
- return suite;
- }
-
- private abstract static class WrappedHashMapGenerator
- extends TestStringMapGenerator {
- @Override protected final Map<String, String> create(
- Map.Entry<String, String>[] entries) {
- HashMap<String, String> map = Maps.newHashMap();
- for (Map.Entry<String, String> entry : entries) {
- map.put(entry.getKey(), entry.getValue());
- }
- return wrap(map);
- }
-
- abstract Map<String, String> wrap(HashMap<String, String> map);
- }
-
- private static TestSuite wrappedHashMapTests(
- WrappedHashMapGenerator generator, String name, Feature<?>... features) {
- return MapTestSuiteBuilder.using(generator)
- .named(name)
- .withFeatures(Lists.asList(
- MapFeature.GENERAL_PURPOSE, CollectionSize.ANY, features))
- .createTestSuite();
- }
-
- // TODO: consider being null-hostile in these tests
-
- private static Test testsForHashMapNullKeysForbidden() {
- return wrappedHashMapTests(new WrappedHashMapGenerator() {
- @Override Map<String, String> wrap(final HashMap<String, String> map) {
- if (map.containsKey(null)) {
- throw new NullPointerException();
- }
- return new AbstractMap<String, String>() {
- @Override public Set<Map.Entry<String, String>> entrySet() {
- return map.entrySet();
- }
- @Override public String put(String key, String value) {
- checkNotNull(key);
- return map.put(key, value);
- }
- };
- }
- }, "HashMap w/out null keys", ALLOWS_NULL_VALUES);
- }
-
- private static Test testsForHashMapNullValuesForbidden() {
- return wrappedHashMapTests(new WrappedHashMapGenerator() {
- @Override Map<String, String> wrap(final HashMap<String, String> map) {
- if (map.containsValue(null)) {
- throw new NullPointerException();
- }
- return new AbstractMap<String, String>() {
- @Override public Set<Map.Entry<String, String>> entrySet() {
- return map.entrySet();
- }
- @Override public String put(String key, String value) {
- checkNotNull(value);
- return map.put(key, value);
- }
- };
- }
- }, "HashMap w/out null values", ALLOWS_NULL_KEYS);
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/MinimalCollectionTest.java b/guava-testlib/test/com/google/common/collect/testing/MinimalCollectionTest.java
deleted file mode 100644
index c701b63..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/MinimalCollectionTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2009 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.CollectionSize;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import java.util.Collection;
-
-/**
- * Unit test for {@link MinimalCollection}.
- *
- * @author Kevin Bourrillion
- */
-public class MinimalCollectionTest extends TestCase {
- public static Test suite() {
- return CollectionTestSuiteBuilder
- .using(new TestStringCollectionGenerator() {
- @Override public Collection<String> create(String[] elements) {
- // TODO: MinimalCollection should perhaps throw
- for (Object element : elements) {
- if (element == null) {
- throw new NullPointerException();
- }
- }
- return MinimalCollection.of(elements);
- }
- })
- .named("MinimalCollection")
- .withFeatures(
- CollectionFeature.NONE,
- CollectionSize.ANY)
- .createTestSuite();
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/MinimalIterableTest.java b/guava-testlib/test/com/google/common/collect/testing/MinimalIterableTest.java
deleted file mode 100644
index 540237d..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/MinimalIterableTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2009 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import junit.framework.TestCase;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * Unit test for {@link MinimalIterable}.
- *
- * @author Kevin Bourrillion
- */
-public class MinimalIterableTest extends TestCase {
-
- public void testOf_empty() {
- Iterable<String> iterable = MinimalIterable.<String>of();
- Iterator<String> iterator = iterable.iterator();
- assertFalse(iterator.hasNext());
- try {
- iterator.next();
- fail();
- } catch (NoSuchElementException expected) {
- }
- try {
- iterable.iterator();
- fail();
- } catch (IllegalStateException expected) {
- }
- }
-
- public void testOf_one() {
- Iterable<String> iterable = MinimalIterable.of("a");
- Iterator<String> iterator = iterable.iterator();
- assertTrue(iterator.hasNext());
- assertEquals("a", iterator.next());
- assertFalse(iterator.hasNext());
- try {
- iterator.next();
- fail();
- } catch (NoSuchElementException expected) {
- }
- try {
- iterable.iterator();
- fail();
- } catch (IllegalStateException expected) {
- }
- }
-
- public void testFrom_empty() {
- Iterable<String> iterable
- = MinimalIterable.from(Collections.<String>emptySet());
- Iterator<String> iterator = iterable.iterator();
- assertFalse(iterator.hasNext());
- try {
- iterator.next();
- fail();
- } catch (NoSuchElementException expected) {
- }
- try {
- iterable.iterator();
- fail();
- } catch (IllegalStateException expected) {
- }
- }
-
- public void testFrom_one() {
- Iterable<String> iterable
- = MinimalIterable.from(Collections.singleton("a"));
- Iterator<String> iterator = iterable.iterator();
- assertTrue(iterator.hasNext());
- assertEquals("a", iterator.next());
- try {
- iterator.remove();
- fail();
- } catch (UnsupportedOperationException expected) {
- }
- assertFalse(iterator.hasNext());
- try {
- iterator.next();
- fail();
- } catch (NoSuchElementException expected) {
- }
- try {
- iterable.iterator();
- fail();
- } catch (IllegalStateException expected) {
- }
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/MinimalSetTest.java b/guava-testlib/test/com/google/common/collect/testing/MinimalSetTest.java
deleted file mode 100644
index 1d21f13..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/MinimalSetTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2009 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.CollectionSize;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import java.util.Set;
-
-/**
- * Unit test for {@link MinimalSet}.
- *
- * @author Regina O'Dell
- */
-public class MinimalSetTest extends TestCase {
- public static Test suite() {
- return SetTestSuiteBuilder
- .using(new TestStringSetGenerator() {
- @Override protected Set<String> create(String[] elements) {
- return MinimalSet.of(elements);
- }
- })
- .named("MinimalSet")
- .withFeatures(
- CollectionFeature.ALLOWS_NULL_VALUES,
- CollectionFeature.NONE,
- CollectionSize.ANY)
- .createTestSuite();
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6ListTests.java b/guava-testlib/test/com/google/common/collect/testing/OpenJdk6ListTests.java
deleted file mode 100644
index d4cc2f4..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6ListTests.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2009 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.collect.testing.testers.CollectionIteratorTester.getIteratorKnownOrderRemoveSupportedMethod;
-import static com.google.common.collect.testing.testers.CollectionToArrayTester.getToArrayIsPlainObjectArrayMethod;
-import static com.google.common.collect.testing.testers.ListAddTester.getAddSupportedNullPresentMethod;
-import static com.google.common.collect.testing.testers.ListListIteratorTester.getListIteratorFullyModifiableMethod;
-import static com.google.common.collect.testing.testers.ListSetTester.getSetNullSupportedMethod;
-import static com.google.common.collect.testing.testers.ListSubListTester.getSubListOriginalListSetAffectsSubListLargeListMethod;
-import static com.google.common.collect.testing.testers.ListSubListTester.getSubListOriginalListSetAffectsSubListMethod;
-import static com.google.common.collect.testing.testers.ListSubListTester.getSubListSubListRemoveAffectsOriginalLargeListMethod;
-
-import com.google.common.collect.testing.testers.CollectionAddTester;
-import com.google.common.collect.testing.testers.ListAddAtIndexTester;
-
-import junit.framework.Test;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Tests the {@link List} implementations of {@link java.util}, suppressing
- * tests that trip known OpenJDK 6 bugs.
- *
- * @author Kevin Bourrillion
- */
-public class OpenJdk6ListTests extends TestsForListsInJavaUtil {
- public static Test suite() {
- return new OpenJdk6ListTests().allTests();
- }
-
- @Override protected Collection<Method> suppressForArraysAsList() {
- return Arrays.asList(
- getToArrayIsPlainObjectArrayMethod());
- }
-
- @Override protected Collection<Method> suppressForCopyOnWriteArrayList() {
- return Arrays.asList(
- getSubListOriginalListSetAffectsSubListMethod(),
- getSubListOriginalListSetAffectsSubListLargeListMethod(),
- getSubListSubListRemoveAffectsOriginalLargeListMethod(),
- getIteratorKnownOrderRemoveSupportedMethod(),
- getListIteratorFullyModifiableMethod());
- }
-
- @Override protected Collection<Method> suppressForCheckedList() {
- return Arrays.asList(
- CollectionAddTester.getAddNullSupportedMethod(),
- getAddSupportedNullPresentMethod(),
- ListAddAtIndexTester.getAddNullSupportedMethod(),
- getSetNullSupportedMethod());
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6MapTests.java b/guava-testlib/test/com/google/common/collect/testing/OpenJdk6MapTests.java
deleted file mode 100644
index a56c77a..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6MapTests.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2009 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.collect.testing.testers.CollectionCreationTester.getCreateWithNullUnsupportedMethod;
-import static com.google.common.collect.testing.testers.MapCreationTester.getCreateWithNullKeyUnsupportedMethod;
-import static com.google.common.collect.testing.testers.MapPutAllTester.getPutAllNullKeyUnsupportedMethod;
-import static com.google.common.collect.testing.testers.MapPutTester.getPutNullKeyUnsupportedMethod;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Tests the {@link Map} implementations of {@link java.util}, suppressing
- * tests that trip known OpenJDK 6 bugs.
- *
- * @author Kevin Bourrillion
- */
-public class OpenJdk6MapTests extends TestsForMapsInJavaUtil {
- public static Test suite() {
- return new OpenJdk6MapTests().allTests();
- }
-
- @Override protected Collection<Method> suppressForTreeMapNatural() {
- return Arrays.asList(
- getPutNullKeyUnsupportedMethod(),
- getPutAllNullKeyUnsupportedMethod(),
- getCreateWithNullKeyUnsupportedMethod(),
- getCreateWithNullUnsupportedMethod()); // for keySet
- }
-
- @Override public Test testsForEnumMap() {
- // Do nothing.
- // TODO: work around the reused-entry problem
- // http://bugs.sun.com/view_bug.do?bug_id=6312706
- return new TestSuite();
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6QueueTests.java b/guava-testlib/test/com/google/common/collect/testing/OpenJdk6QueueTests.java
deleted file mode 100644
index 6cc1dd3..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6QueueTests.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2009 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.collect.testing.testers.CollectionCreationTester.getCreateWithNullUnsupportedMethod;
-
-import junit.framework.Test;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Queue;
-
-/**
- * Tests the {@link Queue} implementations of {@link java.util}, suppressing
- * tests that trip known OpenJDK 6 bugs.
- *
- * @author Kevin Bourrillion
- */
-public class OpenJdk6QueueTests extends TestsForQueuesInJavaUtil {
- public static Test suite() {
- return new OpenJdk6QueueTests().allTests();
- }
-
- private static final List<Method> PQ_SUPPRESS = Arrays.asList(
- getCreateWithNullUnsupportedMethod());
-
- @Override protected Collection<Method> suppressForPriorityBlockingQueue() {
- return PQ_SUPPRESS;
- }
-
- @Override protected Collection<Method> suppressForPriorityQueue() {
- return PQ_SUPPRESS;
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6SetTests.java b/guava-testlib/test/com/google/common/collect/testing/OpenJdk6SetTests.java
deleted file mode 100644
index 77aa34f..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6SetTests.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2009 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.collect.testing.testers.CollectionAddAllTester.getAddAllNullUnsupportedMethod;
-import static com.google.common.collect.testing.testers.CollectionAddTester.getAddNullSupportedMethod;
-import static com.google.common.collect.testing.testers.CollectionAddTester.getAddNullUnsupportedMethod;
-import static com.google.common.collect.testing.testers.CollectionCreationTester.getCreateWithNullUnsupportedMethod;
-import static com.google.common.collect.testing.testers.CollectionIteratorTester.getIteratorKnownOrderRemoveSupportedMethod;
-import static com.google.common.collect.testing.testers.SetAddTester.getAddSupportedNullPresentMethod;
-
-import junit.framework.Test;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * Tests the {@link Set} implementations of {@link java.util}, suppressing
- * tests that trip known OpenJDK 6 bugs.
- *
- * @author Kevin Bourrillion
- */
-public class OpenJdk6SetTests extends TestsForSetsInJavaUtil {
- public static Test suite() {
- return new OpenJdk6SetTests().allTests();
- }
-
- @Override protected Collection<Method> suppressForTreeSetNatural() {
- return Arrays.asList(
- getAddNullUnsupportedMethod(),
- getAddAllNullUnsupportedMethod(),
- getCreateWithNullUnsupportedMethod());
- }
-
- @Override protected Collection<Method> suppressForCopyOnWriteArraySet() {
- return Arrays.asList(
- getIteratorKnownOrderRemoveSupportedMethod());
- }
-
- @Override protected Collection<Method> suppressForCheckedSet() {
- return Arrays.asList(
- getAddNullSupportedMethod(),
- getAddSupportedNullPresentMethod());
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6Tests.java b/guava-testlib/test/com/google/common/collect/testing/OpenJdk6Tests.java
deleted file mode 100644
index ebf93ef..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/OpenJdk6Tests.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2009 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Suite of tests for OpenJdk 6 tests. The existence of this class is a hack
- * because the suitebuilder won't pick up the suites directly in the other
- * classes because they don't extend TestCase. Ergh.
- *
- * @author Kevin Bourrillion
- */
-public class OpenJdk6Tests extends TestCase {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(OpenJdk6SetTests.suite());
- suite.addTest(OpenJdk6ListTests.suite());
- suite.addTest(OpenJdk6QueueTests.suite());
- suite.addTest(OpenJdk6MapTests.suite());
- return suite;
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/SafeTreeMapTest.java b/guava-testlib/test/com/google/common/collect/testing/SafeTreeMapTest.java
deleted file mode 100644
index 0532fbf..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/SafeTreeMapTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2010 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static java.util.Collections.sort;
-
-import com.google.common.annotations.GwtIncompatible;
-import com.google.common.collect.ImmutableSortedMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Ordering;
-import com.google.common.collect.testing.Helpers.NullsBeforeTwo;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-import com.google.common.testing.SerializableTester;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.NavigableMap;
-import java.util.SortedMap;
-
-/**
- * Tests for SafeTreeMap.
- *
- * @author Louis Wasserman
- */
-public class SafeTreeMapTest extends TestCase {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTestSuite(SafeTreeMapTest.class);
- suite.addTest(
- NavigableMapTestSuiteBuilder.using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
- Entry<String, String>[] entries) {
- NavigableMap<String, String> map =
- new SafeTreeMap<String, String>(Ordering.natural());
- for (Entry<String, String> entry : entries) {
- map.put(entry.getKey(), entry.getValue());
- }
- return map;
- }
- }).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER,
- MapFeature.ALLOWS_NULL_VALUES, MapFeature.GENERAL_PURPOSE).named(
- "SafeTreeMap with natural comparator").createTestSuite());
- suite.addTest(NavigableMapTestSuiteBuilder.using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
- Entry<String, String>[] entries) {
- NavigableMap<String, String> map =
- new SafeTreeMap<String, String>(NullsBeforeTwo.INSTANCE);
- for (Entry<String, String> entry : entries) {
- map.put(entry.getKey(), entry.getValue());
- }
- return map;
- }
-
- @Override
- public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
- sort(insertionOrder, Helpers.<String, String>entryComparator(NullsBeforeTwo.INSTANCE));
- return insertionOrder;
- }
- }).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER,
- MapFeature.ALLOWS_NULL_KEYS, MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.GENERAL_PURPOSE).named(
- "SafeTreeMap with null-friendly comparator").createTestSuite());
- return suite;
- }
-
- @GwtIncompatible("SerializableTester")
- public void testViewSerialization() {
- Map<String, Integer> map =
- ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
- SerializableTester.reserializeAndAssert(map.entrySet());
- SerializableTester.reserializeAndAssert(map.keySet());
- assertEquals(Lists.newArrayList(map.values()),
- Lists.newArrayList(SerializableTester.reserialize(map.values())));
- }
-
- @GwtIncompatible("SerializableTester")
- public static class ReserializedMapTests
- extends SortedMapInterfaceTest<String, Integer> {
- ReserializedMapTests() {
- super(false, true, true, true, true);
- }
-
- @Override protected SortedMap<String, Integer> makePopulatedMap() {
- NavigableMap<String, Integer> map = new SafeTreeMap<String, Integer>();
- map.put("one", 1);
- map.put("two", 2);
- map.put("three", 3);
- return SerializableTester.reserialize(map);
- }
-
- @Override protected SortedMap<String, Integer> makeEmptyMap()
- throws UnsupportedOperationException {
- NavigableMap<String, Integer> map = new SafeTreeMap<String, Integer>();
- return SerializableTester.reserialize(map);
- }
-
- @Override protected String getKeyNotInPopulatedMap() {
- return "minus one";
- }
-
- @Override protected Integer getValueNotInPopulatedMap() {
- return -1;
- }
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java b/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java
deleted file mode 100644
index a03081b..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/SafeTreeSetTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2010 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import com.google.common.annotations.GwtIncompatible;
-import com.google.common.collect.ImmutableSortedMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Ordering;
-import com.google.common.collect.Sets;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.testing.SerializableTester;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.NavigableSet;
-import java.util.Set;
-import java.util.SortedSet;
-
-public class SafeTreeSetTest extends TestCase {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTestSuite(SafeTreeSetTest.class);
- suite.addTest(
- NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {
- @Override protected Set<String> create(String[] elements) {
- return new SafeTreeSet<String>(Arrays.asList(elements));
- }
-
- @Override public List<String> order(List<String> insertionOrder) {
- return Lists.newArrayList(Sets.newTreeSet(insertionOrder));
- }
- }).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER,
- CollectionFeature.GENERAL_PURPOSE).named(
- "SafeTreeSet with natural comparator").createTestSuite());
- suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
- @Override protected Set<String> create(String[] elements) {
- NavigableSet<String> set =
- new SafeTreeSet<String>(Ordering.natural().nullsFirst());
- set.addAll(Arrays.asList(elements));
- return set;
- }
-
- @Override public List<String> order(List<String> insertionOrder) {
- return Lists.newArrayList(Sets.newTreeSet(insertionOrder));
- }
- }).withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER,
- CollectionFeature.GENERAL_PURPOSE, CollectionFeature.ALLOWS_NULL_VALUES)
- .named("SafeTreeSet with null-friendly comparator").createTestSuite());
- return suite;
- }
-
- @GwtIncompatible("SerializableTester")
- public void testViewSerialization() {
- Map<String, Integer> map =
- ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
- SerializableTester.reserializeAndAssert(map.entrySet());
- SerializableTester.reserializeAndAssert(map.keySet());
- assertEquals(Lists.newArrayList(map.values()),
- Lists.newArrayList(SerializableTester.reserialize(map.values())));
- }
-
- @GwtIncompatible("SerializableTester")
- public void testEmpty_serialization() {
- SortedSet<String> set = new SafeTreeSet<String>();
- SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
- assertEquals(set.comparator(), copy.comparator());
- }
-
- @GwtIncompatible("SerializableTester")
- public void testSingle_serialization() {
- SortedSet<String> set = new SafeTreeSet<String>();
- set.add("e");
- SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
- assertEquals(set.comparator(), copy.comparator());
- }
-
- @GwtIncompatible("SerializableTester")
- public void testSeveral_serialization() {
- SortedSet<String> set = new SafeTreeSet<String>();
- set.add("a");
- set.add("b");
- set.add("c");
- SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
- assertEquals(set.comparator(), copy.comparator());
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/features/FeatureEnumTest.java b/guava-testlib/test/com/google/common/collect/testing/features/FeatureEnumTest.java
deleted file mode 100644
index 394dcd4..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/features/FeatureEnumTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2008 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing.features;
-
-import junit.framework.TestCase;
-
-import java.lang.annotation.Annotation;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.Method;
-
-/**
- * Since annotations have some reusability issues that force copy and paste
- * all over the place, it's worth having a test to ensure that all our Feature
- * enums have their annotations correctly set up.
- *
- * @author George van den Driessche
- */
-public class FeatureEnumTest extends TestCase {
- private static void assertGoodTesterAnnotation(
- Class<? extends Annotation> annotationClass) {
- assertNotNull(
- String.format("%s must be annotated with @TesterAnnotation.",
- annotationClass),
- annotationClass.getAnnotation(TesterAnnotation.class));
- final Retention retentionPolicy =
- annotationClass.getAnnotation(Retention.class);
- assertNotNull(
- String.format("%s must have a @Retention annotation.", annotationClass),
- retentionPolicy);
- assertEquals(
- String.format("%s must have RUNTIME RetentionPolicy.", annotationClass),
- RetentionPolicy.RUNTIME, retentionPolicy.value());
- assertNotNull(
- String.format("%s must be inherited.", annotationClass),
- annotationClass.getAnnotation(Inherited.class));
-
- for (String propertyName : new String[]{"value", "absent"}) {
- Method method = null;
- try {
- method = annotationClass.getMethod(propertyName);
- } catch (NoSuchMethodException e) {
- fail(String.format("%s must have a property named '%s'.",
- annotationClass, propertyName));
- }
- final Class<?> returnType = method.getReturnType();
- assertTrue(String.format("%s.%s() must return an array.",
- annotationClass, propertyName),
- returnType.isArray());
- assertSame(String.format("%s.%s() must return an array of %s.",
- annotationClass, propertyName, annotationClass.getDeclaringClass()),
- annotationClass.getDeclaringClass(), returnType.getComponentType());
- }
- }
-
- // This is public so that tests for Feature enums we haven't yet imagined
- // can reuse it.
- public static <E extends Enum<?> & Feature<?>> void assertGoodFeatureEnum(
- Class<E> featureEnumClass) {
- final Class<?>[] classes = featureEnumClass.getDeclaredClasses();
- for (Class<?> containedClass : classes) {
- if (containedClass.getSimpleName().equals("Require")) {
- if (containedClass.isAnnotation()) {
- assertGoodTesterAnnotation(asAnnotation(containedClass));
- } else {
- fail(String.format("Feature enum %s contains a class named " +
- "'Require' but it is not an annotation.", featureEnumClass));
- }
- return;
- }
- }
- fail(String.format("Feature enum %s should contain an " +
- "annotation named 'Require'.", featureEnumClass));
- }
-
- @SuppressWarnings("unchecked")
- private static Class<? extends Annotation> asAnnotation(Class<?> clazz) {
- if (clazz.isAnnotation()) {
- return (Class<? extends Annotation>) clazz;
- } else {
- throw new IllegalArgumentException(
- String.format("%s is not an annotation.", clazz));
- }
- }
-
- public void testFeatureEnums() throws Exception {
- assertGoodFeatureEnum(CollectionFeature.class);
- assertGoodFeatureEnum(ListFeature.class);
- assertGoodFeatureEnum(SetFeature.class);
- assertGoodFeatureEnum(CollectionSize.class);
- assertGoodFeatureEnum(MapFeature.class);
- }
-}
diff --git a/guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java b/guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java
deleted file mode 100644
index c92c75f..0000000
--- a/guava-testlib/test/com/google/common/collect/testing/features/FeatureUtilTest.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * Copyright (C) 2008 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing.features;
-
-import static org.truth0.Truth.ASSERT;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
-
-import junit.framework.TestCase;
-
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.Set;
-
-/**
- * @author George van den Driessche
- */
-// Enum values use constructors with generic varargs.
-@SuppressWarnings("unchecked")
-public class FeatureUtilTest extends TestCase {
- interface ExampleBaseInterface {
- void behave();
- }
-
- interface ExampleDerivedInterface extends ExampleBaseInterface {
- void misbehave();
- }
-
- enum ExampleBaseFeature implements Feature<ExampleBaseInterface> {
- BASE_FEATURE_1,
- BASE_FEATURE_2;
-
- @Override
- public Set<Feature<? super ExampleBaseInterface>> getImpliedFeatures() {
- return Collections.emptySet();
- }
-
- @Retention(RetentionPolicy.RUNTIME)
- @Inherited
- @TesterAnnotation
- @interface Require {
- ExampleBaseFeature[] value() default {};
- ExampleBaseFeature[] absent() default {};
- }
- }
-
- enum ExampleDerivedFeature implements Feature<ExampleDerivedInterface>{
- DERIVED_FEATURE_1,
- DERIVED_FEATURE_2(ExampleBaseFeature.BASE_FEATURE_1),
- DERIVED_FEATURE_3,
-
- COMPOUND_DERIVED_FEATURE(
- DERIVED_FEATURE_1,
- DERIVED_FEATURE_2,
- ExampleBaseFeature.BASE_FEATURE_2);
-
- private Set<Feature<? super ExampleDerivedInterface>> implied;
-
- ExampleDerivedFeature(
- Feature<? super ExampleDerivedInterface> ... implied) {
- this.implied = ImmutableSet.copyOf(implied);
- }
-
- @Override
- public Set<Feature<? super ExampleDerivedInterface>> getImpliedFeatures() {
- return implied;
- }
-
- @Retention(RetentionPolicy.RUNTIME)
- @Inherited
- @TesterAnnotation
- @interface Require {
- ExampleDerivedFeature[] value() default {};
- ExampleDerivedFeature[] absent() default {};
- }
- }
-
- @Retention(RetentionPolicy.RUNTIME)
- @interface NonTesterAnnotation {
- }
-
- @ExampleBaseFeature.Require({ExampleBaseFeature.BASE_FEATURE_1})
- private static abstract class ExampleBaseInterfaceTester extends TestCase {
- protected final void doNotActuallyRunThis() {
- fail("Nobody's meant to actually run this!");
- }
- }
-
- @NonTesterAnnotation
- @ExampleDerivedFeature.Require({ExampleDerivedFeature.DERIVED_FEATURE_2})
- private static class ExampleDerivedInterfaceTester
- extends ExampleBaseInterfaceTester {
- // Exists to test that our framework doesn't run it:
- @SuppressWarnings("unused")
- @ExampleDerivedFeature.Require({
- ExampleDerivedFeature.DERIVED_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_2})
- public void testRequiringTwoExplicitDerivedFeatures() throws Exception {
- doNotActuallyRunThis();
- }
-
- // Exists to test that our framework doesn't run it:
- @SuppressWarnings("unused")
- @ExampleDerivedFeature.Require({
- ExampleDerivedFeature.DERIVED_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_3})
- public void testRequiringAllThreeDerivedFeatures() {
- doNotActuallyRunThis();
- }
-
- // Exists to test that our framework doesn't run it:
- @SuppressWarnings("unused")
- @ExampleBaseFeature.Require(absent = {ExampleBaseFeature.BASE_FEATURE_1})
- public void testRequiringConflictingFeatures() throws Exception {
- doNotActuallyRunThis();
- }
- }
-
- @ExampleDerivedFeature.Require(
- absent = {ExampleDerivedFeature.DERIVED_FEATURE_2})
- private static class ExampleDerivedInterfaceTester_Conflict
- extends ExampleBaseInterfaceTester {
- }
-
- public void testTestFeatureEnums() throws Exception {
- // Haha! Let's test our own test rig!
- FeatureEnumTest.assertGoodFeatureEnum(
- FeatureUtilTest.ExampleBaseFeature.class);
- FeatureEnumTest.assertGoodFeatureEnum(
- FeatureUtilTest.ExampleDerivedFeature.class);
- }
-
- public void testAddImpliedFeatures_returnsSameSetInstance() throws Exception {
- Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(
- ExampleBaseFeature.BASE_FEATURE_1);
- assertSame(features, FeatureUtil.addImpliedFeatures(features));
- }
-
- public void testAddImpliedFeatures_addsImpliedFeatures() throws Exception {
- Set<Feature<?>> features;
-
- features = Sets.<Feature<?>>newHashSet(
- ExampleDerivedFeature.DERIVED_FEATURE_1);
- ASSERT.that(FeatureUtil.addImpliedFeatures(features)).has().item(
- ExampleDerivedFeature.DERIVED_FEATURE_1);
-
- features = Sets.<Feature<?>>newHashSet(
- ExampleDerivedFeature.DERIVED_FEATURE_2);
- ASSERT.that(FeatureUtil.addImpliedFeatures(features)).has().allOf(
- ExampleDerivedFeature.DERIVED_FEATURE_2,
- ExampleBaseFeature.BASE_FEATURE_1);
-
- features = Sets.<Feature<?>>newHashSet(
- ExampleDerivedFeature.COMPOUND_DERIVED_FEATURE);
- ASSERT.that(FeatureUtil.addImpliedFeatures(features)).has().allOf(
- ExampleDerivedFeature.COMPOUND_DERIVED_FEATURE,
- ExampleDerivedFeature.DERIVED_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_2,
- ExampleBaseFeature.BASE_FEATURE_1,
- ExampleBaseFeature.BASE_FEATURE_2);
- }
-
- public void testImpliedFeatures_returnsNewSetInstance() throws Exception {
- Set<Feature<?>> features = Sets.<Feature<?>>newHashSet(
- ExampleBaseFeature.BASE_FEATURE_1);
- assertNotSame(features, FeatureUtil.impliedFeatures(features));
- }
-
- public void testImpliedFeatures_returnsImpliedFeatures() throws Exception {
- Set<Feature<?>> features;
-
- features = Sets.<Feature<?>>newHashSet(
- ExampleDerivedFeature.DERIVED_FEATURE_1);
- assertTrue(FeatureUtil.impliedFeatures(features).isEmpty());
-
- features = Sets.<Feature<?>>newHashSet(
- ExampleDerivedFeature.DERIVED_FEATURE_2);
- ASSERT.that(FeatureUtil.impliedFeatures(features)).has().item(
- ExampleBaseFeature.BASE_FEATURE_1);
-
- features = Sets.<Feature<?>>newHashSet(
- ExampleDerivedFeature.COMPOUND_DERIVED_FEATURE);
- ASSERT.that(FeatureUtil.impliedFeatures(features)).has().allOf(
- ExampleDerivedFeature.DERIVED_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_2,
- ExampleBaseFeature.BASE_FEATURE_1,
- ExampleBaseFeature.BASE_FEATURE_2);
- }
-
- public void testBuildTesterRequirements_class() throws Exception {
- assertEquals(FeatureUtil.buildTesterRequirements(
- ExampleBaseInterfaceTester.class),
- new TesterRequirements(
- Sets.<Feature<?>>newHashSet(ExampleBaseFeature.BASE_FEATURE_1),
- Collections.<Feature<?>>emptySet()));
-
- assertEquals(FeatureUtil.buildTesterRequirements(
- ExampleDerivedInterfaceTester.class),
- new TesterRequirements(
- Sets.<Feature<?>>newHashSet(
- ExampleBaseFeature.BASE_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_2),
- Collections.<Feature<?>>emptySet()));
- }
-
- public void testBuildTesterRequirements_method() throws Exception {
- assertEquals(FeatureUtil.buildTesterRequirements(
- ExampleDerivedInterfaceTester.class.getMethod(
- "testRequiringTwoExplicitDerivedFeatures")),
- new TesterRequirements(
- Sets.<Feature<?>>newHashSet(
- ExampleBaseFeature.BASE_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_2),
- Collections.<Feature<?>>emptySet()));
- assertEquals(FeatureUtil.buildTesterRequirements(
- ExampleDerivedInterfaceTester.class.getMethod(
- "testRequiringAllThreeDerivedFeatures")),
- new TesterRequirements(
- Sets.<Feature<?>>newHashSet(
- ExampleBaseFeature.BASE_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_2,
- ExampleDerivedFeature.DERIVED_FEATURE_3),
- Collections.<Feature<?>>emptySet()));
- }
-
- public void testBuildTesterRequirements_classClassConflict()
- throws Exception {
- try {
- FeatureUtil.buildTesterRequirements(
- ExampleDerivedInterfaceTester_Conflict.class);
- fail("Expected ConflictingRequirementsException");
- } catch (ConflictingRequirementsException e) {
- ASSERT.that(e.getConflicts()).has().item(
- ExampleBaseFeature.BASE_FEATURE_1);
- assertEquals(ExampleDerivedInterfaceTester_Conflict.class, e.getSource());
- }
- }
-
- public void testBuildTesterRequirements_methodClassConflict()
- throws Exception {
- final Method method = ExampleDerivedInterfaceTester.class
- .getMethod("testRequiringConflictingFeatures");
- try {
- FeatureUtil.buildTesterRequirements(method);
- fail("Expected ConflictingRequirementsException");
- } catch (ConflictingRequirementsException e) {
- ASSERT.that(e.getConflicts()).has().item(
- ExampleBaseFeature.BASE_FEATURE_1);
- assertEquals(method, e.getSource());
- }
- }
-
- public void testBuildDeclaredTesterRequirements() throws Exception {
- assertEquals(FeatureUtil.buildDeclaredTesterRequirements(
- ExampleDerivedInterfaceTester.class
- .getMethod("testRequiringTwoExplicitDerivedFeatures")),
- new TesterRequirements(FeatureUtil.addImpliedFeatures(
- Sets.<Feature<?>>newHashSet(
- ExampleDerivedFeature.DERIVED_FEATURE_1,
- ExampleDerivedFeature.DERIVED_FEATURE_2)),
- Collections.<Feature<?>>emptySet()));
- }
-
-}