diff options
Diffstat (limited to 'guava-testlib/blackhole-gwt')
34 files changed, 0 insertions, 4342 deletions
diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java deleted file mode 100644 index 48b5ce2..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java +++ /dev/null @@ -1,387 +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.google; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; -import static com.google.common.collect.testing.features.CollectionFeature.RESTRICTS_ELEMENTS; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; -import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.Multiset; -import com.google.common.collect.Multiset.Entry; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.ConcurrentModificationException; -import java.util.Iterator; - -/** - * Common superclass for {@link MultisetSetCountUnconditionallyTester} and - * {@link MultisetSetCountConditionallyTester}. It is used by those testers to - * test calls to the unconditional {@code setCount()} method and calls to the - * conditional {@code setCount()} method when the expected present count is - * correct. - * - * @author Chris Povirk - */ -@GwtCompatible(emulated = true) -public abstract class AbstractMultisetSetCountTester<E> - extends AbstractMultisetTester<E> { - /* - * TODO: consider adding MultisetFeatures.SUPPORTS_SET_COUNT. Currently we - * assume that using setCount() to increase the count is permitted iff add() - * is permitted and similarly for decrease/remove(). We assume that a - * setCount() no-op is permitted if either add() or remove() is permitted, - * though we also allow it to "succeed" if neither is permitted. - */ - - private void assertSetCount(E element, int count) { - setCountCheckReturnValue(element, count); - - assertEquals( - "multiset.count() should return the value passed to setCount()", - count, getMultiset().count(element)); - - int size = 0; - for (Multiset.Entry<E> entry : getMultiset().entrySet()) { - size += entry.getCount(); - } - assertEquals( - "multiset.size() should be the sum of the counts of all entries", - size, getMultiset().size()); - } - - /** - * Call the {@code setCount()} method under test, and check its return value. - */ - abstract void setCountCheckReturnValue(E element, int count); - - /** - * Call the {@code setCount()} method under test, but do not check its return - * value. Callers should use this method over - * {@link #setCountCheckReturnValue(Object, int)} when they expect - * {@code setCount()} to throw an exception, as checking the return value - * could produce an incorrect error message like - * "setCount() should return the original count" instead of the message passed - * to a later invocation of {@code fail()}, like "setCount should throw - * UnsupportedOperationException." - */ - abstract void setCountNoCheckReturnValue(E element, int count); - - private void assertSetCountIncreasingFailure(E element, int count) { - try { - setCountNoCheckReturnValue(element, count); - fail("a call to multiset.setCount() to increase an element's count " - + "should throw"); - } catch (UnsupportedOperationException expected) { - } - } - - private void assertSetCountDecreasingFailure(E element, int count) { - try { - setCountNoCheckReturnValue(element, count); - fail("a call to multiset.setCount() to decrease an element's count " - + "should throw"); - } catch (UnsupportedOperationException expected) { - } - } - - // Unconditional setCount no-ops. - - private void assertZeroToZero() { - assertSetCount(samples.e3, 0); - } - - private void assertOneToOne() { - assertSetCount(samples.e0, 1); - } - - private void assertThreeToThree() { - initThreeCopies(); - assertSetCount(samples.e0, 3); - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_zeroToZero_addSupported() { - assertZeroToZero(); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_zeroToZero_removeSupported() { - assertZeroToZero(); - } - - @CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) - public void testSetCount_zeroToZero_unsupported() { - try { - assertZeroToZero(); - } catch (UnsupportedOperationException tolerated) { - } - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_oneToOne_addSupported() { - assertOneToOne(); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_oneToOne_removeSupported() { - assertOneToOne(); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) - public void testSetCount_oneToOne_unsupported() { - try { - assertOneToOne(); - } catch (UnsupportedOperationException tolerated) { - } - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_threeToThree_addSupported() { - assertThreeToThree(); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_threeToThree_removeSupported() { - assertThreeToThree(); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) - public void testSetCount_threeToThree_unsupported() { - try { - assertThreeToThree(); - } catch (UnsupportedOperationException tolerated) { - } - } - - // Unconditional setCount size increases: - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_zeroToOne_supported() { - assertSetCount(samples.e3, 1); - } - - @CollectionFeature.Require({SUPPORTS_ADD, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - public void testSetCountZeroToOneConcurrentWithIteration() { - try { - Iterator<E> iterator = collection.iterator(); - assertSetCount(samples.e3, 1); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionFeature.Require({SUPPORTS_ADD, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - public void testSetCountZeroToOneConcurrentWithEntrySetIteration() { - try { - Iterator<Entry<E>> iterator = getMultiset().entrySet().iterator(); - assertSetCount(samples.e3, 1); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_zeroToThree_supported() { - assertSetCount(samples.e3, 3); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_oneToThree_supported() { - assertSetCount(samples.e0, 3); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testSetCount_zeroToOne_unsupported() { - assertSetCountIncreasingFailure(samples.e3, 1); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testSetCount_zeroToThree_unsupported() { - assertSetCountIncreasingFailure(samples.e3, 3); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testSetCount_oneToThree_unsupported() { - assertSetCountIncreasingFailure(samples.e3, 3); - } - - // Unconditional setCount size decreases: - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_oneToZero_supported() { - assertSetCount(samples.e0, 0); - } - - @CollectionFeature.Require({SUPPORTS_REMOVE, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - @CollectionSize.Require(absent = ZERO) - public void testSetCountOneToZeroConcurrentWithIteration() { - try { - Iterator<E> iterator = collection.iterator(); - assertSetCount(samples.e0, 0); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionFeature.Require({SUPPORTS_REMOVE, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - public void testSetCountOneToZeroConcurrentWithEntrySetIteration() { - try { - Iterator<Entry<E>> iterator = getMultiset().entrySet().iterator(); - assertSetCount(samples.e0, 0); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_threeToZero_supported() { - initThreeCopies(); - assertSetCount(samples.e0, 0); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_threeToOne_supported() { - initThreeCopies(); - assertSetCount(samples.e0, 1); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testSetCount_oneToZero_unsupported() { - assertSetCountDecreasingFailure(samples.e0, 0); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testSetCount_threeToZero_unsupported() { - initThreeCopies(); - assertSetCountDecreasingFailure(samples.e0, 0); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testSetCount_threeToOne_unsupported() { - initThreeCopies(); - assertSetCountDecreasingFailure(samples.e0, 1); - } - - // setCount with nulls: - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES}) - public void testSetCount_removeNull_nullSupported() { - initCollectionWithNullElement(); - assertSetCount(null, 0); - } - - @CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES}, - absent = RESTRICTS_ELEMENTS) - public void testSetCount_addNull_nullSupported() { - assertSetCount(null, 1); - } - - @CollectionFeature.Require(value = SUPPORTS_ADD, absent = ALLOWS_NULL_VALUES) - public void testSetCount_addNull_nullUnsupported() { - try { - setCountNoCheckReturnValue(null, 1); - fail("adding null with setCount() should throw NullPointerException"); - } catch (NullPointerException expected) { - } - } - - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - public void testSetCount_noOpNull_nullSupported() { - try { - assertSetCount(null, 0); - } catch (UnsupportedOperationException tolerated) { - } - } - - @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) - public void testSetCount_noOpNull_nullUnsupported() { - try { - assertSetCount(null, 0); - } catch (NullPointerException tolerated) { - } catch (UnsupportedOperationException tolerated) { - } - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - public void testSetCount_existingNoNopNull_nullSupported() { - initCollectionWithNullElement(); - try { - assertSetCount(null, 1); - } catch (UnsupportedOperationException tolerated) { - } - } - - // Negative count. - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_negative_removeSupported() { - try { - setCountNoCheckReturnValue(samples.e3, -1); - fail("calling setCount() with a negative count should throw " - + "IllegalArgumentException"); - } catch (IllegalArgumentException expected) { - } - } - - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testSetCount_negative_removeUnsupported() { - try { - setCountNoCheckReturnValue(samples.e3, -1); - fail("calling setCount() with a negative count should throw " - + "IllegalArgumentException or UnsupportedOperationException"); - } catch (IllegalArgumentException expected) { - } catch (UnsupportedOperationException expected) { - } - } - - // TODO: test adding element of wrong type -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapInverseTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapInverseTester.java deleted file mode 100644 index eef939b..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapInverseTester.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2012 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.google; - -import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.BiMap; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.testing.SerializableTester; - -import java.io.Serializable; - -/** - * Tests for the {@code inverse} view of a BiMap. - * - * <p>This assumes that {@code bimap.inverse().inverse() == bimap}, which is not technically - * required but is fulfilled by all current implementations. - * - * @author Louis Wasserman - */ -@GwtCompatible(emulated = true) -public class BiMapInverseTester<K, V> extends AbstractBiMapTester<K, V> { - - public void testInverseSame() { - assertSame(getMap(), getMap().inverse().inverse()); - } - - @CollectionFeature.Require(SERIALIZABLE) - public void testInverseSerialization() { - BiMapPair<K, V> pair = new BiMapPair<K, V>(getMap()); - BiMapPair<K, V> copy = SerializableTester.reserialize(pair); - assertEquals(pair.forward, copy.forward); - assertEquals(pair.backward, copy.backward); - assertSame(copy.backward, copy.forward.inverse()); - assertSame(copy.forward, copy.backward.inverse()); - } - - private static class BiMapPair<K, V> implements Serializable { - final BiMap<K, V> forward; - final BiMap<V, K> backward; - - BiMapPair(BiMap<K, V> original) { - this.forward = original; - this.backward = original.inverse(); - } - - private static final long serialVersionUID = 0; - } - -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapRemoveTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapRemoveTester.java deleted file mode 100644 index 5c01444..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapRemoveTester.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2012 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.google; - -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.MapFeature; - -import java.util.Iterator; - -/** - * Tester for {@code BiMap.remove}. - * - * @author Louis Wasserman - */ -@GwtCompatible(emulated = true) -public class BiMapRemoveTester<K, V> extends AbstractBiMapTester<K, V> { - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveKeyRemovesFromInverse() { - getMap().remove(samples.e0.getKey()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveKeyFromKeySetRemovesFromInverse() { - getMap().keySet().remove(samples.e0.getKey()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveFromValuesRemovesFromInverse() { - getMap().values().remove(samples.e0.getValue()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveFromInverseRemovesFromForward() { - getMap().inverse().remove(samples.e0.getValue()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveFromInverseKeySetRemovesFromForward() { - getMap().inverse().keySet().remove(samples.e0.getValue()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveFromInverseValuesRemovesFromInverse() { - getMap().inverse().values().remove(samples.e0.getKey()); - expectMissing(samples.e0); - } - - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testKeySetIteratorRemove() { - int initialSize = getNumElements(); - Iterator<K> iterator = getMap().keySet().iterator(); - iterator.next(); - iterator.remove(); - assertEquals(initialSize - 1, getMap().size()); - assertEquals(initialSize - 1, getMap().inverse().size()); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetIteratorTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetIteratorTester.java deleted file mode 100644 index e665afc..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetIteratorTester.java +++ /dev/null @@ -1,90 +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.google; - -import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.IteratorFeature; -import com.google.common.collect.testing.IteratorTester; -import com.google.common.collect.testing.features.CollectionFeature; - -import java.util.Arrays; -import java.util.Iterator; - -/** - * Tester to make sure the {@code iterator().remove()} implementation of {@code Multiset} works when - * there are multiple occurrences of elements. - * - * @author Louis Wasserman - */ -@GwtCompatible(emulated = true) -public class MultisetIteratorTester<E> extends AbstractMultisetTester<E> { - @SuppressWarnings("unchecked") - @CollectionFeature.Require({SUPPORTS_REMOVE, KNOWN_ORDER}) - public void testRemovingIteratorKnownOrder() { - new IteratorTester<E>(4, IteratorFeature.MODIFIABLE, getSubjectGenerator().order( - Arrays.asList(samples.e0, samples.e1, samples.e1, samples.e2)), - IteratorTester.KnownOrder.KNOWN_ORDER) { - @Override - protected Iterator<E> newTargetIterator() { - return getSubjectGenerator().create(samples.e0, samples.e1, samples.e1, samples.e2) - .iterator(); - } - }.test(); - } - - @SuppressWarnings("unchecked") - @CollectionFeature.Require(value = SUPPORTS_REMOVE, absent = KNOWN_ORDER) - public void testRemovingIteratorUnknownOrder() { - new IteratorTester<E>(4, IteratorFeature.MODIFIABLE, Arrays.asList(samples.e0, samples.e1, - samples.e1, samples.e2), IteratorTester.KnownOrder.UNKNOWN_ORDER) { - @Override - protected Iterator<E> newTargetIterator() { - return getSubjectGenerator().create(samples.e0, samples.e1, samples.e1, samples.e2) - .iterator(); - } - }.test(); - } - - @SuppressWarnings("unchecked") - @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_REMOVE) - public void testIteratorKnownOrder() { - new IteratorTester<E>(4, IteratorFeature.UNMODIFIABLE, getSubjectGenerator().order( - Arrays.asList(samples.e0, samples.e1, samples.e1, samples.e2)), - IteratorTester.KnownOrder.KNOWN_ORDER) { - @Override - protected Iterator<E> newTargetIterator() { - return getSubjectGenerator().create(samples.e0, samples.e1, samples.e1, samples.e2) - .iterator(); - } - }.test(); - } - - @SuppressWarnings("unchecked") - @CollectionFeature.Require(absent = {SUPPORTS_REMOVE, KNOWN_ORDER}) - public void testIteratorUnknownOrder() { - new IteratorTester<E>(4, IteratorFeature.UNMODIFIABLE, Arrays.asList(samples.e0, samples.e1, - samples.e1, samples.e2), IteratorTester.KnownOrder.UNKNOWN_ORDER) { - @Override - protected Iterator<E> newTargetIterator() { - return getSubjectGenerator().create(samples.e0, samples.e1, samples.e1, samples.e2) - .iterator(); - } - }.test(); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetReadsTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetReadsTester.java deleted file mode 100644 index ea11eac..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetReadsTester.java +++ /dev/null @@ -1,141 +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.google; - -import static com.google.common.collect.testing.features.CollectionSize.ONE; -import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.HashMultiset; -import com.google.common.collect.Multiset; -import com.google.common.collect.Multisets; -import com.google.common.collect.testing.WrongType; -import com.google.common.collect.testing.features.CollectionSize; - -/** - * A generic JUnit test which tests multiset-specific read operations. - * Can't be invoked directly; please see - * {@link com.google.common.collect.testing.SetTestSuiteBuilder}. - * - * @author Jared Levy - */ -@GwtCompatible(emulated = true) -public class MultisetReadsTester<E> extends AbstractMultisetTester<E> { - public void testCount_0() { - assertEquals("multiset.count(missing) didn't return 0", - 0, getMultiset().count(samples.e3)); - } - - @CollectionSize.Require(absent = ZERO) - public void testCount_1() { - assertEquals("multiset.count(present) didn't return 1", - 1, getMultiset().count(samples.e0)); - } - - @CollectionSize.Require(SEVERAL) - public void testCount_3() { - initThreeCopies(); - assertEquals("multiset.count(thriceContained) didn't return 3", - 3, getMultiset().count(samples.e0)); - } - - public void testCount_null() { - assertEquals("multiset.count(null) didn't return 0", - 0, getMultiset().count(null)); - } - - public void testCount_wrongType() { - assertEquals("multiset.count(wrongType) didn't return 0", - 0, getMultiset().count(WrongType.VALUE)); - } - - @CollectionSize.Require(absent = ZERO) - public void testElementSet_contains() { - assertTrue("multiset.elementSet().contains(present) returned false", - getMultiset().elementSet().contains(samples.e0)); - } - - @CollectionSize.Require(absent = ZERO) - public void testEntrySet_contains() { - assertTrue("multiset.entrySet() didn't contain [present, 1]", - getMultiset().entrySet().contains( - Multisets.immutableEntry(samples.e0, 1))); - } - - public void testEntrySet_contains_count0() { - assertFalse("multiset.entrySet() contains [missing, 0]", - getMultiset().entrySet().contains( - Multisets.immutableEntry(samples.e3, 0))); - } - - public void testEntrySet_contains_nonentry() { - assertFalse("multiset.entrySet() contains a non-entry", - getMultiset().entrySet().contains(samples.e0)); - } - - public void testEntrySet_twice() { - assertEquals("calling multiset.entrySet() twice returned unequal sets", - getMultiset().entrySet(), getMultiset().entrySet()); - } - - @CollectionSize.Require(ZERO) - public void testEntrySet_hashCode_size0() { - assertEquals("multiset.entrySet() has incorrect hash code", - 0, getMultiset().entrySet().hashCode()); - } - - @CollectionSize.Require(ONE) - public void testEntrySet_hashCode_size1() { - assertEquals("multiset.entrySet() has incorrect hash code", - 1 ^ samples.e0.hashCode(), getMultiset().entrySet().hashCode()); - } - - public void testEquals_yes() { - assertTrue("multiset doesn't equal a multiset with the same elements", - getMultiset().equals(HashMultiset.create(getSampleElements()))); - } - - public void testEquals_differentSize() { - Multiset<E> other = HashMultiset.create(getSampleElements()); - other.add(samples.e0); - assertFalse("multiset equals a multiset with a different size", - getMultiset().equals(other)); - } - - @CollectionSize.Require(absent = ZERO) - public void testEquals_differentElements() { - Multiset<E> other = HashMultiset.create(getSampleElements()); - other.remove(samples.e0); - other.add(samples.e3); - assertFalse("multiset equals a multiset with different elements", - getMultiset().equals(other)); - } - - @CollectionSize.Require(ZERO) - public void testHashCode_size0() { - assertEquals("multiset has incorrect hash code", - 0, getMultiset().hashCode()); - } - - @CollectionSize.Require(ONE) - public void testHashCode_size1() { - assertEquals("multiset has incorrect hash code", - 1 ^ samples.e0.hashCode(), getMultiset().hashCode()); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetWritesTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetWritesTester.java deleted file mode 100644 index 91cd8d3..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetWritesTester.java +++ /dev/null @@ -1,253 +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.google; - -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; -import static com.google.common.collect.testing.features.CollectionSize.ONE; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.Multiset; -import com.google.common.collect.Multisets; -import com.google.common.collect.testing.WrongType; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.Collections; -import java.util.Iterator; - -/** - * A generic JUnit test which tests multiset-specific write operations. - * Can't be invoked directly; please see {@link MultisetTestSuiteBuilder}. - * - * @author Jared Levy - */ -@GwtCompatible(emulated = true) -public class MultisetWritesTester<E> extends AbstractMultisetTester<E> { - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAddOccurrencesZero() { - int originalCount = getMultiset().count(samples.e0); - assertEquals("old count", originalCount, getMultiset().add(samples.e0, 0)); - expectUnchanged(); - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAddOccurrences() { - int originalCount = getMultiset().count(samples.e0); - assertEquals("old count", originalCount, getMultiset().add(samples.e0, 2)); - assertEquals("old count", originalCount + 2, getMultiset().count(samples.e0)); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testAddOccurrences_unsupported() { - try { - getMultiset().add(samples.e0, 2); - fail("unsupported multiset.add(E, int) didn't throw exception"); - } catch (UnsupportedOperationException required) {} - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAdd_occurrences_negative() { - try { - getMultiset().add(samples.e0, -1); - fail("multiset.add(E, -1) didn't throw an exception"); - } catch (IllegalArgumentException required) {} - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemoveZeroNoOp() { - int originalCount = getMultiset().count(samples.e0); - assertEquals("old count", originalCount, getMultiset().remove(samples.e0, 0)); - expectUnchanged(); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_present() { - assertEquals("multiset.remove(present, 2) didn't return the old count", - 1, getMultiset().remove(samples.e0, 2)); - assertFalse("multiset contains present after multiset.remove(present, 2)", - getMultiset().contains(samples.e0)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_absent() { - assertEquals("multiset.remove(absent, 0) didn't return 0", - 0, getMultiset().remove(samples.e3, 2)); - } - - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testRemove_occurrences_unsupported_absent() { - // notice: we don't care whether it succeeds, or fails with UOE - try { - assertEquals( - "multiset.remove(absent, 2) didn't return 0 or throw an exception", - 0, getMultiset().remove(samples.e3, 2)); - } catch (UnsupportedOperationException ok) {} - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_0() { - int oldCount = getMultiset().count(samples.e0); - assertEquals("multiset.remove(E, 0) didn't return the old count", - oldCount, getMultiset().remove(samples.e0, 0)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_negative() { - try { - getMultiset().remove(samples.e0, -1); - fail("multiset.remove(E, -1) didn't throw an exception"); - } catch (IllegalArgumentException required) {} - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_wrongType() { - assertEquals("multiset.remove(wrongType, 1) didn't return 0", - 0, getMultiset().remove(WrongType.VALUE, 1)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_clear() { - getMultiset().entrySet().clear(); - assertTrue("multiset not empty after entrySet().clear()", - getMultiset().isEmpty()); - } - - @CollectionSize.Require(ONE) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_iterator() { - Iterator<Multiset.Entry<E>> iterator = getMultiset().entrySet().iterator(); - assertTrue( - "non-empty multiset.entrySet() iterator.hasNext() returned false", - iterator.hasNext()); - assertEquals("multiset.entrySet() iterator.next() returned incorrect entry", - Multisets.immutableEntry(samples.e0, 1), iterator.next()); - assertFalse( - "size 1 multiset.entrySet() iterator.hasNext() returned true " - + "after next()", - iterator.hasNext()); - iterator.remove(); - assertTrue( - "multiset isn't empty after multiset.entrySet() iterator.remove()", - getMultiset().isEmpty()); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testEntrySet_iterator_remove_unsupported() { - Iterator<Multiset.Entry<E>> iterator = getMultiset().entrySet().iterator(); - assertTrue( - "non-empty multiset.entrySet() iterator.hasNext() returned false", - iterator.hasNext()); - try { - iterator.remove(); - fail("multiset.entrySet() iterator.remove() didn't throw an exception"); - } catch (UnsupportedOperationException expected) {} - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_remove_present() { - assertTrue( - "multiset.entrySet.remove(presentEntry) returned false", - getMultiset().entrySet().remove( - Multisets.immutableEntry(samples.e0, 1))); - assertFalse( - "multiset contains element after removing its entry", - getMultiset().contains(samples.e0)); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_remove_missing() { - assertFalse( - "multiset.entrySet.remove(missingEntry) returned true", - getMultiset().entrySet().remove( - Multisets.immutableEntry(samples.e0, 2))); - assertTrue( - "multiset didn't contain element after removing a missing entry", - getMultiset().contains(samples.e0)); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_removeAll_present() { - assertTrue( - "multiset.entrySet.removeAll(presentEntry) returned false", - getMultiset().entrySet().removeAll( - Collections.singleton(Multisets.immutableEntry(samples.e0, 1)))); - assertFalse( - "multiset contains element after removing its entry", - getMultiset().contains(samples.e0)); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_removeAll_missing() { - assertFalse( - "multiset.entrySet.remove(missingEntry) returned true", - getMultiset().entrySet().removeAll( - Collections.singleton(Multisets.immutableEntry(samples.e0, 2)))); - assertTrue( - "multiset didn't contain element after removing a missing entry", - getMultiset().contains(samples.e0)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_removeAll_null() { - try { - getMultiset().entrySet().removeAll(null); - fail("multiset.entrySet.removeAll(null) didn't throw an exception"); - } catch (NullPointerException expected) {} - } - - @CollectionSize.Require(ONE) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_retainAll_present() { - assertFalse( - "multiset.entrySet.retainAll(presentEntry) returned false", - getMultiset().entrySet().retainAll( - Collections.singleton(Multisets.immutableEntry(samples.e0, 1)))); - assertTrue( - "multiset doesn't contains element after retaining its entry", - getMultiset().contains(samples.e0)); - } - - @CollectionSize.Require(ONE) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_retainAll_missing() { - assertTrue( - "multiset.entrySet.retainAll(missingEntry) returned true", - getMultiset().entrySet().retainAll( - Collections.singleton(Multisets.immutableEntry(samples.e0, 2)))); - assertFalse( - "multiset contains element after retaining a different entry", - getMultiset().contains(samples.e0)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_retainAll_null() { - try { - getMultiset().entrySet().retainAll(null); - // Returning successfully is not ideal, but tolerated. - } catch (NullPointerException expected) {} - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/SetGenerators.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/SetGenerators.java deleted file mode 100644 index 5102cdf..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/SetGenerators.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.google; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Sets.newTreeSet; -import static com.google.common.collect.testing.SampleElements.Strings.AFTER_LAST; -import static com.google.common.collect.testing.SampleElements.Strings.AFTER_LAST_2; -import static com.google.common.collect.testing.SampleElements.Strings.BEFORE_FIRST; -import static com.google.common.collect.testing.SampleElements.Strings.BEFORE_FIRST_2; -import static junit.framework.Assert.assertEquals; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.ContiguousSet; -import com.google.common.collect.DiscreteDomain; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; -import com.google.common.collect.Range; -import com.google.common.collect.Sets; -import com.google.common.collect.testing.TestCollectionGenerator; -import com.google.common.collect.testing.TestCollidingSetGenerator; -import com.google.common.collect.testing.TestIntegerSortedSetGenerator; -import com.google.common.collect.testing.TestSetGenerator; -import com.google.common.collect.testing.TestStringListGenerator; -import com.google.common.collect.testing.TestStringSetGenerator; -import com.google.common.collect.testing.TestStringSortedSetGenerator; -import com.google.common.collect.testing.TestUnhashableCollectionGenerator; -import com.google.common.collect.testing.UnhashableObject; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; - -/** - * Generators of different types of sets and derived collections from sets. - * - * @author Kevin Bourrillion - * @author Jared Levy - * @author Hayward Chan - */ -@GwtCompatible(emulated = true) -public class SetGenerators { - - public static class ImmutableSetCopyOfGenerator extends TestStringSetGenerator { - @Override protected Set<String> create(String[] elements) { - return ImmutableSet.copyOf(elements); - } - } - - public static class ImmutableSetWithBadHashesGenerator - extends TestCollidingSetGenerator - // Work around a GWT compiler bug. Not explicitly listing this will - // cause the createArray() method missing in the generated javascript. - // TODO: Remove this once the GWT bug is fixed. - implements TestCollectionGenerator<Object> { - @Override - public Set<Object> create(Object... elements) { - return ImmutableSet.copyOf(elements); - } - } - - public static class DegeneratedImmutableSetGenerator - extends TestStringSetGenerator { - // Make sure we get what we think we're getting, or else this test - // is pointless - @SuppressWarnings("cast") - @Override protected Set<String> create(String[] elements) { - return (ImmutableSet<String>) - ImmutableSet.of(elements[0], elements[0]); - } - } - - public static class ImmutableSortedSetCopyOfGenerator - extends TestStringSortedSetGenerator { - @Override protected SortedSet<String> create(String[] elements) { - return ImmutableSortedSet.copyOf(elements); - } - } - - public static class ImmutableSortedSetHeadsetGenerator - extends TestStringSortedSetGenerator { - @Override protected SortedSet<String> create(String[] elements) { - List<String> list = Lists.newArrayList(elements); - list.add("zzz"); - return ImmutableSortedSet.copyOf(list) - .headSet("zzy"); - } - } - - public static class ImmutableSortedSetTailsetGenerator - extends TestStringSortedSetGenerator { - @Override protected SortedSet<String> create(String[] elements) { - List<String> list = Lists.newArrayList(elements); - list.add("\0"); - return ImmutableSortedSet.copyOf(list) - .tailSet("\0\0"); - } - } - - public static class ImmutableSortedSetSubsetGenerator - extends TestStringSortedSetGenerator { - @Override protected SortedSet<String> create(String[] elements) { - List<String> list = Lists.newArrayList(elements); - list.add("\0"); - list.add("zzz"); - return ImmutableSortedSet.copyOf(list) - .subSet("\0\0", "zzy"); - } - } - - public static class ImmutableSortedSetExplicitComparator - extends TestStringSetGenerator { - - private static final Comparator<String> STRING_REVERSED - = Collections.reverseOrder(); - - @Override protected SortedSet<String> create(String[] elements) { - return ImmutableSortedSet.orderedBy(STRING_REVERSED) - .add(elements) - .build(); - } - - @Override public List<String> order(List<String> insertionOrder) { - Collections.sort(insertionOrder, Collections.reverseOrder()); - return insertionOrder; - } - } - - public static class ImmutableSortedSetExplicitSuperclassComparatorGenerator - extends TestStringSetGenerator { - - private static final Comparator<Comparable<?>> COMPARABLE_REVERSED - = Collections.reverseOrder(); - - @Override protected SortedSet<String> create(String[] elements) { - return new ImmutableSortedSet.Builder<String>(COMPARABLE_REVERSED) - .add(elements) - .build(); - } - - @Override public List<String> order(List<String> insertionOrder) { - Collections.sort(insertionOrder, Collections.reverseOrder()); - return insertionOrder; - } - } - - public static class ImmutableSortedSetReversedOrderGenerator - extends TestStringSetGenerator { - - @Override protected SortedSet<String> create(String[] elements) { - return ImmutableSortedSet.<String>reverseOrder() - .addAll(Arrays.asList(elements).iterator()) - .build(); - } - - @Override public List<String> order(List<String> insertionOrder) { - Collections.sort(insertionOrder, Collections.reverseOrder()); - return insertionOrder; - } - } - - public static class ImmutableSortedSetUnhashableGenerator - extends TestUnhashableSetGenerator { - @Override public Set<UnhashableObject> create( - UnhashableObject[] elements) { - return ImmutableSortedSet.copyOf(elements); - } - } - - public static class ImmutableSetAsListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - return ImmutableSet.copyOf(elements).asList(); - } - } - - public static class ImmutableSortedSetAsListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - Comparator<String> comparator = createExplicitComparator(elements); - ImmutableSet<String> set = ImmutableSortedSet.copyOf( - comparator, Arrays.asList(elements)); - return set.asList(); - } - } - - public static class ImmutableSortedSetSubsetAsListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - Comparator<String> comparator = createExplicitComparator(elements); - ImmutableSortedSet.Builder<String> builder - = ImmutableSortedSet.orderedBy(comparator); - builder.add(BEFORE_FIRST); - builder.add(elements); - builder.add(AFTER_LAST); - return builder.build().subSet(BEFORE_FIRST_2, - AFTER_LAST).asList(); - } - } - - public static class ImmutableSortedSetAsListSubListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - Comparator<String> comparator = createExplicitComparator(elements); - ImmutableSortedSet.Builder<String> builder - = ImmutableSortedSet.orderedBy(comparator); - builder.add(BEFORE_FIRST); - builder.add(elements); - builder.add(AFTER_LAST); - return builder.build().asList().subList(1, elements.length + 1); - } - } - - public static class ImmutableSortedSetSubsetAsListSubListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - Comparator<String> comparator = createExplicitComparator(elements); - ImmutableSortedSet.Builder<String> builder - = ImmutableSortedSet.orderedBy(comparator); - builder.add(BEFORE_FIRST); - builder.add(BEFORE_FIRST_2); - builder.add(elements); - builder.add(AFTER_LAST); - builder.add(AFTER_LAST_2); - return builder.build().subSet(BEFORE_FIRST_2, - AFTER_LAST_2) - .asList().subList(1, elements.length + 1); - } - } - - public abstract static class TestUnhashableSetGenerator - extends TestUnhashableCollectionGenerator<Set<UnhashableObject>> - implements TestSetGenerator<UnhashableObject> { - } - - private static Ordering<String> createExplicitComparator( - String[] elements) { - // Collapse equal elements, which Ordering.explicit() doesn't support, while - // maintaining the ordering by first occurrence. - Set<String> elementsPlus = Sets.newLinkedHashSet(); - elementsPlus.add(BEFORE_FIRST); - elementsPlus.add(BEFORE_FIRST_2); - elementsPlus.addAll(Arrays.asList(elements)); - elementsPlus.add(AFTER_LAST); - elementsPlus.add(AFTER_LAST_2); - return Ordering.explicit(Lists.newArrayList(elementsPlus)); - } - - /* - * All the ContiguousSet generators below manually reject nulls here. In principle, we'd like to - * defer that to Range, since it's ContiguousSet.create() that's used to create the sets. However, - * that gets messy here, and we already have null tests for Range. - */ - - /* - * These generators also rely on consecutive integer inputs (not necessarily in order, but no - * holes). - */ - - // SetCreationTester has some tests that pass in duplicates. Dedup them. - private static <E extends Comparable<? super E>> SortedSet<E> nullCheckedTreeSet(E[] elements) { - SortedSet<E> set = newTreeSet(); - for (E element : elements) { - // Explicit null check because TreeSet wrongly accepts add(null) when empty. - set.add(checkNotNull(element)); - } - return set; - } - - public static class ContiguousSetGenerator extends AbstractContiguousSetGenerator { - @Override protected SortedSet<Integer> create(Integer[] elements) { - return checkedCreate(nullCheckedTreeSet(elements)); - } - } - - public static class ContiguousSetHeadsetGenerator extends AbstractContiguousSetGenerator { - @Override protected SortedSet<Integer> create(Integer[] elements) { - SortedSet<Integer> set = nullCheckedTreeSet(elements); - int tooHigh = (set.isEmpty()) ? 0 : set.last() + 1; - set.add(tooHigh); - return checkedCreate(set).headSet(tooHigh); - } - } - - public static class ContiguousSetTailsetGenerator extends AbstractContiguousSetGenerator { - @Override protected SortedSet<Integer> create(Integer[] elements) { - SortedSet<Integer> set = nullCheckedTreeSet(elements); - int tooLow = (set.isEmpty()) ? 0 : set.first() - 1; - set.add(tooLow); - return checkedCreate(set).tailSet(tooLow + 1); - } - } - - public static class ContiguousSetSubsetGenerator extends AbstractContiguousSetGenerator { - @Override protected SortedSet<Integer> create(Integer[] elements) { - SortedSet<Integer> set = nullCheckedTreeSet(elements); - if (set.isEmpty()) { - /* - * The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be - * greater than tooHigh. - */ - return ContiguousSet.create(Range.openClosed(0, 1), DiscreteDomain.integers()).subSet(0, 1); - } - int tooHigh = set.last() + 1; - int tooLow = set.first() - 1; - set.add(tooHigh); - set.add(tooLow); - return checkedCreate(set).subSet(tooLow + 1, tooHigh); - } - } - - private abstract static class AbstractContiguousSetGenerator - extends TestIntegerSortedSetGenerator { - protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) { - List<Integer> elements = newArrayList(elementsSet); - /* - * A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it - * doesn't need one, or it should be suppressed for ContiguousSet. - */ - for (int i = 0; i < elements.size() - 1; i++) { - assertEquals(elements.get(i) + 1, (int) elements.get(i + 1)); - } - Range<Integer> range = - (elements.isEmpty()) ? Range.closedOpen(0, 0) : Range.encloseAll(elements); - return ContiguousSet.create(range, DiscreteDomain.integers()); - } - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/GwtPlatform.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/GwtPlatform.java deleted file mode 100644 index b4d12b8..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/GwtPlatform.java +++ /dev/null @@ -1,38 +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.gwt.core.client.GwtScriptOnly; -import com.google.gwt.lang.Array; - -/** - * Version of {@link GwtPlatform} used in web-mode. It includes methods in - * {@link Platform} that requires different implementions in web mode and - * hosted mode. It is factored out from {@link Platform} because <code> - * {@literal @}GwtScriptOnly</code> only supports public classes and methods. - * - * @author Hayward Chan - */ -@GwtScriptOnly -public final class GwtPlatform { - - private GwtPlatform() {} - - public static <T> T[] clone(T[] array) { - return (T[]) Array.clone(array); - } -} diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/Helpers.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/Helpers.java deleted file mode 100644 index 28f5571..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/Helpers.java +++ /dev/null @@ -1,404 +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 java.util.Collections.sort; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertTrue; - -import com.google.common.annotations.GwtCompatible; - -import junit.framework.Assert; -import junit.framework.AssertionFailedError; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -@GwtCompatible(emulated = true) -public class Helpers { - // Clone of Objects.equal - static boolean equal(Object a, Object b) { - return a == b || (a != null && a.equals(b)); - } - - // Clone of Lists.newArrayList - public static <E> List<E> copyToList(Iterable<? extends E> elements) { - List<E> list = new ArrayList<E>(); - addAll(list, elements); - return list; - } - - public static <E> List<E> copyToList(E[] elements) { - return copyToList(Arrays.asList(elements)); - } - - // Clone of Sets.newLinkedHashSet - public static <E> Set<E> copyToSet(Iterable<? extends E> elements) { - Set<E> set = new LinkedHashSet<E>(); - addAll(set, elements); - return set; - } - - public static <E> Set<E> copyToSet(E[] elements) { - return copyToSet(Arrays.asList(elements)); - } - - // Would use Maps.immutableEntry - public static <K, V> Entry<K, V> mapEntry(K key, V value) { - return Collections.singletonMap(key, value).entrySet().iterator().next(); - } - - public static void assertEqualIgnoringOrder( - Iterable<?> expected, Iterable<?> actual) { - List<?> exp = copyToList(expected); - List<?> act = copyToList(actual); - String actString = act.toString(); - - // Of course we could take pains to give the complete description of the - // problem on any failure. - - // Yeah it's n^2. - for (Object object : exp) { - if (!act.remove(object)) { - Assert.fail("did not contain expected element " + object + ", " - + "expected = " + exp + ", actual = " + actString); - } - } - assertTrue("unexpected elements: " + act, act.isEmpty()); - } - - public static void assertContentsAnyOrder( - Iterable<?> actual, Object... expected) { - assertEqualIgnoringOrder(Arrays.asList(expected), actual); - } - - public static <E> boolean addAll( - Collection<E> addTo, Iterable<? extends E> elementsToAdd) { - boolean modified = false; - for (E e : elementsToAdd) { - modified |= addTo.add(e); - } - return modified; - } - - static <T> Iterable<T> reverse(final List<T> list) { - return new Iterable<T>() { - @Override - public Iterator<T> iterator() { - final ListIterator<T> listIter = list.listIterator(list.size()); - return new Iterator<T>() { - @Override - public boolean hasNext() { - return listIter.hasPrevious(); - } - @Override - public T next() { - return listIter.previous(); - } - @Override - public void remove() { - listIter.remove(); - } - }; - } - }; - } - - static <T> Iterator<T> cycle(final Iterable<T> iterable) { - return new Iterator<T>() { - Iterator<T> iterator = Collections.<T>emptySet().iterator(); - @Override - public boolean hasNext() { - return true; - } - @Override - public T next() { - if (!iterator.hasNext()) { - iterator = iterable.iterator(); - } - return iterator.next(); - } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } - - static <T> T get(Iterator<T> iterator, int position) { - for (int i = 0; i < position; i++) { - iterator.next(); - } - return iterator.next(); - } - - static void fail(Throwable cause, Object message) { - AssertionFailedError assertionFailedError = - new AssertionFailedError(String.valueOf(message)); - assertionFailedError.initCause(cause); - throw assertionFailedError; - } - - public static <K, V> Comparator<Entry<K, V>> entryComparator( - final Comparator<? super K> keyComparator) { - return new Comparator<Entry<K, V>>() { - @Override - @SuppressWarnings("unchecked") // no less safe than putting it in the map! - public int compare(Entry<K, V> a, Entry<K, V> b) { - return (keyComparator == null) - ? ((Comparable) a.getKey()).compareTo(b.getKey()) - : keyComparator.compare(a.getKey(), b.getKey()); - } - }; - } - - public static <T> void testComparator( - Comparator<? super T> comparator, T... valuesInExpectedOrder) { - testComparator(comparator, Arrays.asList(valuesInExpectedOrder)); - } - - public static <T> void testComparator( - Comparator<? super T> comparator, List<T> valuesInExpectedOrder) { - // This does an O(n^2) test of all pairs of values in both orders - for (int i = 0; i < valuesInExpectedOrder.size(); i++) { - T t = valuesInExpectedOrder.get(i); - - for (int j = 0; j < i; j++) { - T lesser = valuesInExpectedOrder.get(j); - assertTrue(comparator + ".compare(" + lesser + ", " + t + ")", - comparator.compare(lesser, t) < 0); - } - - assertEquals(comparator + ".compare(" + t + ", " + t + ")", - 0, comparator.compare(t, t)); - - for (int j = i + 1; j < valuesInExpectedOrder.size(); j++) { - T greater = valuesInExpectedOrder.get(j); - assertTrue(comparator + ".compare(" + greater + ", " + t + ")", - comparator.compare(greater, t) > 0); - } - } - } - - public static <T extends Comparable<? super T>> void testCompareToAndEquals( - List<T> valuesInExpectedOrder) { - // This does an O(n^2) test of all pairs of values in both orders - for (int i = 0; i < valuesInExpectedOrder.size(); i++) { - T t = valuesInExpectedOrder.get(i); - - for (int j = 0; j < i; j++) { - T lesser = valuesInExpectedOrder.get(j); - assertTrue(lesser + ".compareTo(" + t + ')', lesser.compareTo(t) < 0); - assertFalse(lesser.equals(t)); - } - - assertEquals(t + ".compareTo(" + t + ')', 0, t.compareTo(t)); - assertTrue(t.equals(t)); - - for (int j = i + 1; j < valuesInExpectedOrder.size(); j++) { - T greater = valuesInExpectedOrder.get(j); - assertTrue(greater + ".compareTo(" + t + ')', greater.compareTo(t) > 0); - assertFalse(greater.equals(t)); - } - } - } - - /** - * Returns a collection that simulates concurrent modification by - * having its size method return incorrect values. This is useful - * for testing methods that must treat the return value from size() - * as a hint only. - * - * @param delta the difference between the true size of the - * collection and the values returned by the size method - */ - public static <T> Collection<T> misleadingSizeCollection(final int delta) { - // It would be nice to be able to return a real concurrent - // collection like ConcurrentLinkedQueue, so that e.g. concurrent - // iteration would work, but that would not be GWT-compatible. - return new ArrayList<T>() { - @Override public int size() { return Math.max(0, super.size() + delta); } - }; - } - - /** - * Returns a "nefarious" map entry with the specified key and value, - * meaning an entry that is suitable for testing that map entries cannot be - * modified via a nefarious implementation of equals. This is used for testing - * unmodifiable collections of map entries; for example, it should not be - * possible to access the raw (modifiable) map entry via a nefarious equals - * method. - */ - public static <K, V> Map.Entry<K, V> nefariousMapEntry(final K key, - final V value) { - return new Map.Entry<K, V>() { - @Override public K getKey() { - return key; - } - @Override public V getValue() { - return value; - } - @Override public V setValue(V value) { - throw new UnsupportedOperationException(); - } - @SuppressWarnings("unchecked") - @Override public boolean equals(Object o) { - if (o instanceof Map.Entry) { - Map.Entry<K, V> e = (Map.Entry<K, V>) o; - e.setValue(value); // muhahaha! - - return equal(this.getKey(), e.getKey()) - && equal(this.getValue(), e.getValue()); - } - return false; - } - - @Override public int hashCode() { - K k = getKey(); - V v = getValue(); - return ((k == null) ? - 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode()); - } - - /** - * Returns a string representation of the form <code>{key}={value}</code>. - */ - @Override public String toString() { - return getKey() + "=" + getValue(); - } - }; - } - - static <E> List<E> castOrCopyToList(Iterable<E> iterable) { - if (iterable instanceof List) { - return (List<E>) iterable; - } - List<E> list = new ArrayList<E>(); - for (E e : iterable) { - list.add(e); - } - return list; - } - - private static final Comparator<Comparable> NATURAL_ORDER = new Comparator<Comparable>() { - @SuppressWarnings("unchecked") // assume any Comparable is Comparable<Self> - @Override public int compare(Comparable left, Comparable right) { - return left.compareTo(right); - } - }; - - public static <K extends Comparable, V> Iterable<Entry<K, V>> orderEntriesByKey( - List<Entry<K, V>> insertionOrder) { - sort(insertionOrder, Helpers.<K, V>entryComparator(NATURAL_ORDER)); - return insertionOrder; - } - - /** - * Private replacement for {@link com.google.gwt.user.client.rpc.GwtTransient} to work around - * build-system quirks. - */ - private @interface GwtTransient {} - - /** - * Compares strings in natural order except that null comes immediately before a given value. This - * works better than Ordering.natural().nullsFirst() because, if null comes before all other - * values, it lies outside the submap/submultiset ranges we test, and the variety of tests that - * exercise null handling fail on those subcollections. - */ - public abstract static class NullsBefore implements Comparator<String>, Serializable { - /* - * We don't serialize this class in GWT, so we don't care about whether GWT will serialize this - * field. - */ - @GwtTransient private final String justAfterNull; - - protected NullsBefore(String justAfterNull) { - if (justAfterNull == null) { - throw new NullPointerException(); - } - - this.justAfterNull = justAfterNull; - } - - @Override - public int compare(String lhs, String rhs) { - if (lhs == rhs) { - return 0; - } - if (lhs == null) { - // lhs (null) comes just before justAfterNull. - // If rhs is b, lhs comes first. - if (rhs.equals(justAfterNull)) { - return -1; - } - return justAfterNull.compareTo(rhs); - } - if (rhs == null) { - // rhs (null) comes just before justAfterNull. - // If lhs is b, rhs comes first. - if (lhs.equals(justAfterNull)) { - return 1; - } - return lhs.compareTo(justAfterNull); - } - return lhs.compareTo(rhs); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof NullsBefore) { - NullsBefore other = (NullsBefore) obj; - return justAfterNull.equals(other.justAfterNull); - } - return false; - } - - @Override - public int hashCode() { - return justAfterNull.hashCode(); - } - } - - public static final class NullsBeforeB extends NullsBefore { - public static final NullsBeforeB INSTANCE = new NullsBeforeB(); - - private NullsBeforeB() { - super("b"); - } - } - - public static final class NullsBeforeTwo extends NullsBefore { - public static final NullsBeforeTwo INSTANCE = new NullsBeforeTwo(); - - private NullsBeforeTwo() { - super("two"); // from TestStringSortedMapGenerator's sample keys - } - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/Platform.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/Platform.java deleted file mode 100644 index 110a566..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/Platform.java +++ /dev/null @@ -1,80 +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; - -/** - * Minimal GWT emulation of {@code com.google.common.collect.testing.Platform}. - * - * <p><strong>This .java file should never be consumed by javac.</strong> - * - * @author Hayward Chan - */ -class Platform { - - static boolean checkIsInstance(Class<?> clazz, Object obj) { - /* - * In GWT, we can't tell whether obj is an instance of clazz because GWT - * doesn't support reflections. For testing purposes, we give up this - * particular assertion (so that we can keep the rest). - */ - return true; - } - - // Class.cast is not supported in GWT. - static void checkCast(Class<?> clazz, Object obj) { - } - - static <T> T[] clone(T[] array) { - return GwtPlatform.clone(array); - } - - // TODO: Consolidate different copies in one single place. - static String format(String template, Object... args) { - // start substituting the arguments into the '%s' placeholders - StringBuilder builder = new StringBuilder( - template.length() + 16 * args.length); - int templateStart = 0; - int i = 0; - while (i < args.length) { - int placeholderStart = template.indexOf("%s", templateStart); - if (placeholderStart == -1) { - break; - } - builder.append(template.substring(templateStart, placeholderStart)); - builder.append(args[i++]); - templateStart = placeholderStart + 2; - } - builder.append(template.substring(templateStart)); - - // if we run out of placeholders, append the extra args in square braces - if (i < args.length) { - builder.append(" ["); - builder.append(args[i++]); - while (i < args.length) { - builder.append(", "); - builder.append(args[i++]); - } - builder.append("]"); - } - - return builder.toString(); - } - - static String classGetSimpleName(Class<?> clazz) { - throw new UnsupportedOperationException("Shouldn't be called in GWT."); - } -} diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionAddAllTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionAddAllTester.java deleted file mode 100644 index 9280c7a..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionAddAllTester.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; -import static com.google.common.collect.testing.features.CollectionFeature.RESTRICTS_ELEMENTS; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -import static java.util.Collections.singletonList; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.AbstractCollectionTester; -import com.google.common.collect.testing.MinimalCollection; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.List; - -/** - * A generic JUnit test which tests addAll operations on a collection. Can't be - * invoked directly; please see - * {@link com.google.common.collect.testing.CollectionTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - * @author Kevin Bourrillion - */ -@SuppressWarnings("unchecked") // too many "unchecked generic array creations" -@GwtCompatible(emulated = true) -public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> { - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAddAll_supportedNothing() { - assertFalse("addAll(nothing) should return false", - collection.addAll(emptyCollection())); - expectUnchanged(); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testAddAll_unsupportedNothing() { - try { - assertFalse("addAll(nothing) should return false or throw", - collection.addAll(emptyCollection())); - } catch (UnsupportedOperationException tolerated) { - } - expectUnchanged(); - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAddAll_supportedNonePresent() { - assertTrue("addAll(nonePresent) should return true", - collection.addAll(createDisjointCollection())); - expectAdded(samples.e3, samples.e4); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testAddAll_unsupportedNonePresent() { - try { - collection.addAll(createDisjointCollection()); - fail("addAll(nonePresent) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - expectMissing(samples.e3, samples.e4); - } - - @CollectionFeature.Require(SUPPORTS_ADD) - @CollectionSize.Require(absent = ZERO) - public void testAddAll_supportedSomePresent() { - assertTrue("addAll(somePresent) should return true", - collection.addAll(MinimalCollection.of(samples.e3, samples.e0))); - assertTrue("should contain " + samples.e3, collection.contains(samples.e3)); - assertTrue("should contain " + samples.e0, collection.contains(samples.e0)); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - @CollectionSize.Require(absent = ZERO) - public void testAddAll_unsupportedSomePresent() { - try { - collection.addAll(MinimalCollection.of(samples.e3, samples.e0)); - fail("addAll(somePresent) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - } - - @CollectionFeature.Require({SUPPORTS_ADD, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - @CollectionSize.Require(absent = ZERO) - public void testAddAllConcurrentWithIteration() { - try { - Iterator<E> iterator = collection.iterator(); - assertTrue(collection.addAll(MinimalCollection.of(samples.e3, samples.e0))); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - @CollectionSize.Require(absent = ZERO) - public void testAddAll_unsupportedAllPresent() { - try { - assertFalse("addAll(allPresent) should return false or throw", - collection.addAll(MinimalCollection.of(samples.e0))); - } catch (UnsupportedOperationException tolerated) { - } - expectUnchanged(); - } - - @CollectionFeature.Require(value = {SUPPORTS_ADD, - ALLOWS_NULL_VALUES}, absent = RESTRICTS_ELEMENTS) - public void testAddAll_nullSupported() { - List<E> containsNull = singletonList(null); - assertTrue("addAll(containsNull) should return true", collection - .addAll(containsNull)); - /* - * We need (E) to force interpretation of null as the single element of a - * varargs array, not the array itself - */ - expectAdded((E) null); - } - - @CollectionFeature.Require(value = SUPPORTS_ADD, - absent = ALLOWS_NULL_VALUES) - public void testAddAll_nullUnsupported() { - List<E> containsNull = singletonList(null); - try { - collection.addAll(containsNull); - fail("addAll(containsNull) should throw"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - expectNullMissingWhenNullUnsupported( - "Should not contain null after unsupported addAll(containsNull)"); - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAddAll_nullCollectionReference() { - try { - collection.addAll(null); - fail("addAll(null) should throw NullPointerException"); - } catch (NullPointerException expected) { - } - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionAddTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionAddTester.java deleted file mode 100644 index 3a5bc13..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionAddTester.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; -import static com.google.common.collect.testing.features.CollectionFeature.RESTRICTS_ELEMENTS; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.AbstractCollectionTester; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.ConcurrentModificationException; -import java.util.Iterator; - -/** - * A generic JUnit test which tests {@code add} operations on a collection. - * Can't be invoked directly; please see - * {@link com.google.common.collect.testing.CollectionTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - * @author Kevin Bourrillion - */ -@SuppressWarnings("unchecked") // too many "unchecked generic array creations" -@GwtCompatible(emulated = true) -public class CollectionAddTester<E> extends AbstractCollectionTester<E> { - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAdd_supportedNotPresent() { - assertTrue("add(notPresent) should return true", - collection.add(samples.e3)); - expectAdded(samples.e3); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testAdd_unsupportedNotPresent() { - try { - collection.add(samples.e3); - fail("add(notPresent) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - expectMissing(samples.e3); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - @CollectionSize.Require(absent = ZERO) - public void testAdd_unsupportedPresent() { - try { - assertFalse("add(present) should return false or throw", - collection.add(samples.e0)); - } catch (UnsupportedOperationException tolerated) { - } - expectUnchanged(); - } - - @CollectionFeature.Require( - value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES}, - absent = RESTRICTS_ELEMENTS) - public void testAdd_nullSupported() { - assertTrue("add(null) should return true", collection.add(null)); - expectAdded((E) null); - } - - @CollectionFeature.Require(value = SUPPORTS_ADD, - absent = ALLOWS_NULL_VALUES) - public void testAdd_nullUnsupported() { - try { - collection.add(null); - fail("add(null) should throw"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - expectNullMissingWhenNullUnsupported( - "Should not contain null after unsupported add(null)"); - } - - @CollectionFeature.Require({SUPPORTS_ADD, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - @CollectionSize.Require(absent = ZERO) - public void testAddConcurrentWithIteration() { - try { - Iterator<E> iterator = collection.iterator(); - assertTrue(collection.add(samples.e3)); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionCreationTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionCreationTester.java deleted file mode 100644 index bcdf61c..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionCreationTester.java +++ /dev/null @@ -1,58 +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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.AbstractCollectionTester; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -/** - * A generic JUnit test which tests creation (typically through a constructor or - * static factory method) of a collection. Can't be invoked directly; please see - * {@link com.google.common.collect.testing.CollectionTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - */ -@GwtCompatible(emulated = true) -public class CollectionCreationTester<E> extends AbstractCollectionTester<E> { - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - @CollectionSize.Require(absent = ZERO) - public void testCreateWithNull_supported() { - E[] array = createArrayWithNullElement(); - collection = getSubjectGenerator().create(array); - expectContents(array); - } - - @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) - @CollectionSize.Require(absent = ZERO) - public void testCreateWithNull_unsupported() { - E[] array = createArrayWithNullElement(); - - try { - getSubjectGenerator().create(array); - fail("Creating a collection containing null should fail"); - } catch (NullPointerException expected) { - } - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionIteratorTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionIteratorTester.java deleted file mode 100644 index 8f54656..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionIteratorTester.java +++ /dev/null @@ -1,126 +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.testers; - -import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE; -import static com.google.common.collect.testing.IteratorFeature.UNMODIFIABLE; -import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.AbstractCollectionTester; -import com.google.common.collect.testing.Helpers; -import com.google.common.collect.testing.IteratorFeature; -import com.google.common.collect.testing.IteratorTester; -import com.google.common.collect.testing.features.CollectionFeature; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Set; - -/** - * A generic JUnit test which tests {@code iterator} operations on a collection. - * Can't be invoked directly; please see - * {@link com.google.common.collect.testing.CollectionTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - */ -@GwtCompatible(emulated = true) -public class CollectionIteratorTester<E> extends AbstractCollectionTester<E> { - public void testIterator() { - List<E> iteratorElements = new ArrayList<E>(); - for (E element : collection) { // uses iterator() - iteratorElements.add(element); - } - Helpers.assertEqualIgnoringOrder( - Arrays.asList(createSamplesArray()), iteratorElements); - } - - @CollectionFeature.Require(KNOWN_ORDER) - public void testIterationOrdering() { - List<E> iteratorElements = new ArrayList<E>(); - for (E element : collection) { // uses iterator() - iteratorElements.add(element); - } - List<E> expected = Helpers.copyToList(getOrderedElements()); - assertEquals("Different ordered iteration", expected, iteratorElements); - } - - // TODO: switch to DerivedIteratorTestSuiteBuilder - - @CollectionFeature.Require({KNOWN_ORDER, SUPPORTS_REMOVE}) - public void testIterator_knownOrderRemoveSupported() { - runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, - getOrderedElements()); - } - - @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_REMOVE) - public void testIterator_knownOrderRemoveUnsupported() { - runIteratorTest(UNMODIFIABLE, IteratorTester.KnownOrder.KNOWN_ORDER, - getOrderedElements()); - } - - @CollectionFeature.Require(absent = KNOWN_ORDER, value = SUPPORTS_REMOVE) - public void testIterator_unknownOrderRemoveSupported() { - runIteratorTest(MODIFIABLE, IteratorTester.KnownOrder.UNKNOWN_ORDER, - getSampleElements()); - } - - @CollectionFeature.Require(absent = {KNOWN_ORDER, SUPPORTS_REMOVE}) - public void testIterator_unknownOrderRemoveUnsupported() { - runIteratorTest(UNMODIFIABLE, IteratorTester.KnownOrder.UNKNOWN_ORDER, - getSampleElements()); - } - - private void runIteratorTest(Set<IteratorFeature> features, - IteratorTester.KnownOrder knownOrder, Iterable<E> elements) { - new IteratorTester<E>(Platform.collectionIteratorTesterNumIterations(), features, elements, - knownOrder) { - { - // TODO: don't set this universally - ignoreSunJavaBug6529795(); - } - - @Override protected Iterator<E> newTargetIterator() { - resetCollection(); - return collection.iterator(); - } - - @Override protected void verify(List<E> elements) { - expectContents(elements); - } - }.test(); - } - - public void testIteratorNoSuchElementException() { - Iterator<E> iterator = collection.iterator(); - while (iterator.hasNext()) { - iterator.next(); - } - - try { - iterator.next(); - fail("iterator.next() should throw NoSuchElementException"); - } catch (NoSuchElementException expected) {} - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionToArrayTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionToArrayTester.java deleted file mode 100644 index 377ac12..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/CollectionToArrayTester.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.AbstractCollectionTester; -import com.google.common.collect.testing.Helpers; -import com.google.common.collect.testing.WrongType; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.Arrays; -import java.util.List; - -/** - * A generic JUnit test which tests {@code toArray()} operations on a - * collection. Can't be invoked directly; please see - * {@link com.google.common.collect.testing.CollectionTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Kevin Bourrillion - * @author Chris Povirk - */ -@GwtCompatible(emulated = true) -public class CollectionToArrayTester<E> extends AbstractCollectionTester<E> { - public void testToArray_noArgs() { - Object[] array = collection.toArray(); - expectArrayContentsAnyOrder(createSamplesArray(), array); - } - - /** - * {@link Collection#toArray(Object[])} says: "Note that - * <tt>toArray(new Object[0])</tt> is identical in function to - * <tt>toArray()</tt>." - * - * <p>For maximum effect, the collection under test should be created from an - * element array of a type other than {@code Object[]}. - */ - public void testToArray_isPlainObjectArray() { - Object[] array = collection.toArray(); - assertEquals(Object[].class, array.getClass()); - } - - public void testToArray_emptyArray() { - E[] empty = getSubjectGenerator().createArray(0); - E[] array = collection.toArray(empty); - assertEquals("toArray(emptyT[]) should return an array of type T", - empty.getClass(), array.getClass()); - assertEquals("toArray(emptyT[]).length:", getNumElements(), array.length); - expectArrayContentsAnyOrder(createSamplesArray(), array); - } - - @CollectionFeature.Require(KNOWN_ORDER) - public void testToArray_emptyArray_ordered() { - E[] empty = getSubjectGenerator().createArray(0); - E[] array = collection.toArray(empty); - assertEquals("toArray(emptyT[]) should return an array of type T", - empty.getClass(), array.getClass()); - assertEquals("toArray(emptyT[]).length:", getNumElements(), array.length); - expectArrayContentsInOrder(getOrderedElements(), array); - } - - public void testToArray_emptyArrayOfObject() { - Object[] in = new Object[0]; - Object[] array = collection.toArray(in); - assertEquals("toArray(emptyObject[]) should return an array of type Object", - Object[].class, array.getClass()); - assertEquals("toArray(emptyObject[]).length", - getNumElements(), array.length); - expectArrayContentsAnyOrder(createSamplesArray(), array); - } - - public void testToArray_rightSizedArray() { - E[] array = getSubjectGenerator().createArray(getNumElements()); - assertSame("toArray(sameSizeE[]) should return the given array", - array, collection.toArray(array)); - expectArrayContentsAnyOrder(createSamplesArray(), array); - } - - @CollectionFeature.Require(KNOWN_ORDER) - public void testToArray_rightSizedArray_ordered() { - E[] array = getSubjectGenerator().createArray(getNumElements()); - assertSame("toArray(sameSizeE[]) should return the given array", - array, collection.toArray(array)); - expectArrayContentsInOrder(getOrderedElements(), array); - } - - public void testToArray_rightSizedArrayOfObject() { - Object[] array = new Object[getNumElements()]; - assertSame("toArray(sameSizeObject[]) should return the given array", - array, collection.toArray(array)); - expectArrayContentsAnyOrder(createSamplesArray(), array); - } - - @CollectionFeature.Require(KNOWN_ORDER) - public void testToArray_rightSizedArrayOfObject_ordered() { - Object[] array = new Object[getNumElements()]; - assertSame("toArray(sameSizeObject[]) should return the given array", - array, collection.toArray(array)); - expectArrayContentsInOrder(getOrderedElements(), array); - } - - public void testToArray_oversizedArray() { - E[] array = getSubjectGenerator().createArray(getNumElements() + 2); - array[getNumElements()] = samples.e3; - array[getNumElements() + 1] = samples.e3; - assertSame("toArray(overSizedE[]) should return the given array", - array, collection.toArray(array)); - - List<E> subArray = Arrays.asList(array).subList(0, getNumElements()); - E[] expectedSubArray = createSamplesArray(); - for (int i = 0; i < getNumElements(); i++) { - assertTrue( - "toArray(overSizedE[]) should contain element " + expectedSubArray[i], - subArray.contains(expectedSubArray[i])); - } - assertNull("The array element " - + "immediately following the end of the collection should be nulled", - array[getNumElements()]); - // array[getNumElements() + 1] might or might not have been nulled - } - - @CollectionFeature.Require(KNOWN_ORDER) - public void testToArray_oversizedArray_ordered() { - E[] array = getSubjectGenerator().createArray(getNumElements() + 2); - array[getNumElements()] = samples.e3; - array[getNumElements() + 1] = samples.e3; - assertSame("toArray(overSizedE[]) should return the given array", - array, collection.toArray(array)); - - List<E> expected = getOrderedElements(); - for (int i = 0; i < getNumElements(); i++) { - assertEquals(expected.get(i), array[i]); - } - assertNull("The array element " - + "immediately following the end of the collection should be nulled", - array[getNumElements()]); - // array[getNumElements() + 1] might or might not have been nulled - } - - @CollectionSize.Require(absent = ZERO) - public void testToArray_emptyArrayOfWrongTypeForNonEmptyCollection() { - try { - WrongType[] array = new WrongType[0]; - collection.toArray(array); - fail("toArray(notAssignableTo[]) should throw"); - } catch (ArrayStoreException expected) { - } - } - - @CollectionSize.Require(ZERO) - public void testToArray_emptyArrayOfWrongTypeForEmptyCollection() { - WrongType[] array = new WrongType[0]; - assertSame( - "toArray(sameSizeNotAssignableTo[]) should return the given array", - array, collection.toArray(array)); - } - - private void expectArrayContentsAnyOrder(Object[] expected, Object[] actual) { - Helpers.assertEqualIgnoringOrder( - Arrays.asList(expected), Arrays.asList(actual)); - } - - private void expectArrayContentsInOrder(List<E> expected, Object[] actual) { - assertEquals("toArray() ordered contents: ", - expected, Arrays.asList(actual)); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListAddAtIndexTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListAddAtIndexTester.java deleted file mode 100644 index 614959a..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListAddAtIndexTester.java +++ /dev/null @@ -1,153 +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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; -import static com.google.common.collect.testing.features.CollectionSize.ONE; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.ListFeature; - -import java.util.ConcurrentModificationException; -import java.util.Iterator; - -/** - * A generic JUnit test which tests {@code add(int, Object)} operations on a - * list. Can't be invoked directly; please see - * {@link com.google.common.collect.testing.ListTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - */ -@SuppressWarnings("unchecked") // too many "unchecked generic array creations" -@GwtCompatible(emulated = true) -public class ListAddAtIndexTester<E> extends AbstractListTester<E> { - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - @CollectionSize.Require(absent = ZERO) - public void testAddAtIndex_supportedPresent() { - getList().add(0, samples.e0); - expectAdded(0, samples.e0); - } - - @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) - @CollectionSize.Require(absent = ZERO) - /* - * absent = ZERO isn't required, since unmodList.add() must - * throw regardless, but it keeps the method name accurate. - */ - public void testAddAtIndex_unsupportedPresent() { - try { - getList().add(0, samples.e0); - fail("add(n, present) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - public void testAddAtIndex_supportedNotPresent() { - getList().add(0, samples.e3); - expectAdded(0, samples.e3); - } - - @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION) - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - public void testAddAtIndexConcurrentWithIteration() { - try { - Iterator<E> iterator = collection.iterator(); - getList().add(0, samples.e3); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX) - public void testAddAtIndex_unsupportedNotPresent() { - try { - getList().add(0, samples.e3); - fail("add(n, notPresent) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - expectMissing(samples.e3); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testAddAtIndex_middle() { - getList().add(getNumElements() / 2, samples.e3); - expectAdded(getNumElements() / 2, samples.e3); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - @CollectionSize.Require(absent = ZERO) - public void testAddAtIndex_end() { - getList().add(getNumElements(), samples.e3); - expectAdded(getNumElements(), samples.e3); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - public void testAddAtIndex_nullSupported() { - getList().add(0, null); - expectAdded(0, (E) null); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) - public void testAddAtIndex_nullUnsupported() { - try { - getList().add(0, null); - fail("add(n, null) should throw"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - expectNullMissingWhenNullUnsupported( - "Should not contain null after unsupported add(n, null)"); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - public void testAddAtIndex_negative() { - try { - getList().add(-1, samples.e3); - fail("add(-1, e) should throw"); - } catch (IndexOutOfBoundsException expected) { - } - expectUnchanged(); - expectMissing(samples.e3); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - public void testAddAtIndex_tooLarge() { - try { - getList().add(getNumElements() + 1, samples.e3); - fail("add(size + 1, e) should throw"); - } catch (IndexOutOfBoundsException expected) { - } - expectUnchanged(); - expectMissing(samples.e3); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListAddTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListAddTester.java deleted file mode 100644 index bac3d60..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListAddTester.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.Helpers; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.List; - -/** - * A generic JUnit test which tests {@code add(Object)} operations on a list. - * Can't be invoked directly; please see - * {@link com.google.common.collect.testing.ListTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - */ -@SuppressWarnings("unchecked") // too many "unchecked generic array creations" -@GwtCompatible(emulated = true) -public class ListAddTester<E> extends AbstractListTester<E> { - @CollectionFeature.Require(SUPPORTS_ADD) - @CollectionSize.Require(absent = ZERO) - public void testAdd_supportedPresent() { - assertTrue("add(present) should return true", getList().add(samples.e0)); - expectAdded(samples.e0); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - @CollectionSize.Require(absent = ZERO) - /* - * absent = ZERO isn't required, since unmodList.add() must - * throw regardless, but it keeps the method name accurate. - */ - public void testAdd_unsupportedPresent() { - try { - getList().add(samples.e0); - fail("add(present) should throw"); - } catch (UnsupportedOperationException expected) { - } - } - - @CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES}) - @CollectionSize.Require(absent = ZERO) - public void testAdd_supportedNullPresent() { - E[] array = createArrayWithNullElement(); - collection = getSubjectGenerator().create(array); - assertTrue("add(nullPresent) should return true", getList().add(null)); - - List<E> expected = Helpers.copyToList(array); - expected.add(null); - expectContents(expected); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListHashCodeTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListHashCodeTester.java deleted file mode 100644 index 501c8ca..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListHashCodeTester.java +++ /dev/null @@ -1,41 +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.testers; - -import com.google.common.annotations.GwtCompatible; - -/** - * Tests {@link java.util.List#hashCode}. - * - * <p>This class is GWT compatible. - * - * @author George van den Driessche - */ -@GwtCompatible(emulated = true) -public class ListHashCodeTester<E> extends AbstractListTester<E> { - public void testHashCode() { - int expectedHashCode = 1; - for (E element : getOrderedElements()) { - expectedHashCode = 31 * expectedHashCode + - ((element == null) ? 0 : element.hashCode()); - } - assertEquals( - "A List's hashCode() should be computed from those of its elements.", - expectedHashCode, getList().hashCode()); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListListIteratorTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListListIteratorTester.java deleted file mode 100644 index dbd2718..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListListIteratorTester.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE; -import static com.google.common.collect.testing.IteratorFeature.UNMODIFIABLE; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; -import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX; -import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_SET; -import static com.google.common.collect.testing.testers.Platform.listListIteratorTesterNumIterations; -import static java.util.Collections.singleton; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.Helpers; -import com.google.common.collect.testing.IteratorFeature; -import com.google.common.collect.testing.ListIteratorTester; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.ListFeature; - -import java.util.List; -import java.util.ListIterator; -import java.util.Set; - -/** - * A generic JUnit test which tests {@code listIterator} operations on a list. - * Can't be invoked directly; please see - * {@link com.google.common.collect.testing.ListTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - * @author Kevin Bourrillion - */ -@GwtCompatible(emulated = true) -public class ListListIteratorTester<E> extends AbstractListTester<E> { - // TODO: switch to DerivedIteratorTestSuiteBuilder - - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - @ListFeature.Require(absent = {SUPPORTS_SET, SUPPORTS_ADD_WITH_INDEX}) - public void testListIterator_unmodifiable() { - runListIteratorTest(UNMODIFIABLE); - } - - /* - * For now, we don't cope with testing this when the list supports only some - * modification operations. - */ - @CollectionFeature.Require(SUPPORTS_REMOVE) - @ListFeature.Require({SUPPORTS_SET, SUPPORTS_ADD_WITH_INDEX}) - public void testListIterator_fullyModifiable() { - runListIteratorTest(MODIFIABLE); - } - - private void runListIteratorTest(Set<IteratorFeature> features) { - new ListIteratorTester<E>( - listListIteratorTesterNumIterations(), singleton(samples.e4), features, - Helpers.copyToList(getOrderedElements()), 0) { - { - // TODO: don't set this universally - stopTestingWhenAddThrowsException(); - } - - @Override protected ListIterator<E> newTargetIterator() { - resetCollection(); - return getList().listIterator(); - } - - @Override protected void verify(List<E> elements) { - expectContents(elements); - } - }.test(); - } - - public void testListIterator_tooLow() { - try { - getList().listIterator(-1); - fail(); - } catch (IndexOutOfBoundsException expected) { - } - } - - public void testListIterator_tooHigh() { - try { - getList().listIterator(getNumElements() + 1); - fail(); - } catch (IndexOutOfBoundsException expected) { - } - } - - public void testListIterator_atSize() { - getList().listIterator(getNumElements()); - // TODO: run the iterator through ListIteratorTester - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListSetTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListSetTester.java deleted file mode 100644 index 1a57800..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListSetTester.java +++ /dev/null @@ -1,136 +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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_SET; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.ListFeature; - -/** - * A generic JUnit test which tests {@code set()} operations on a list. Can't be - * invoked directly; please see - * {@link com.google.common.collect.testing.ListTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author George van den Driessche - */ -@GwtCompatible(emulated = true) -public class ListSetTester<E> extends AbstractListTester<E> { - @ListFeature.Require(SUPPORTS_SET) - @CollectionSize.Require(absent = ZERO) - public void testSet() { - doTestSet(samples.e3); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - @ListFeature.Require(SUPPORTS_SET) - public void testSet_null() { - doTestSet(null); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - @ListFeature.Require(SUPPORTS_SET) - public void testSet_replacingNull() { - E[] elements = createSamplesArray(); - int i = aValidIndex(); - elements[i] = null; - collection = getSubjectGenerator().create(elements); - - doTestSet(samples.e3); - } - - private void doTestSet(E newValue) { - int index = aValidIndex(); - E initialValue = getList().get(index); - assertEquals("set(i, x) should return the old element at position i.", - initialValue, getList().set(index, newValue)); - assertEquals("After set(i, x), get(i) should return x", - newValue, getList().get(index)); - assertEquals("set() should not change the size of a list.", - getNumElements(), getList().size()); - } - - @ListFeature.Require(SUPPORTS_SET) - public void testSet_indexTooLow() { - try { - getList().set(-1, samples.e3); - fail("set(-1) should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException expected) { - } - expectUnchanged(); - } - - @ListFeature.Require(SUPPORTS_SET) - public void testSet_indexTooHigh() { - int index = getNumElements(); - try { - getList().set(index, samples.e3); - fail("set(size) should throw IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException expected) { - } - expectUnchanged(); - } - - @CollectionSize.Require(absent = ZERO) - @ListFeature.Require(absent = SUPPORTS_SET) - public void testSet_unsupported() { - try { - getList().set(aValidIndex(), samples.e3); - fail("set() should throw UnsupportedOperationException"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - } - - @CollectionSize.Require(ZERO) - @ListFeature.Require(absent = SUPPORTS_SET) - public void testSet_unsupportedByEmptyList() { - try { - getList().set(0, samples.e3); - fail("set() should throw UnsupportedOperationException " - + "or IndexOutOfBoundsException"); - } catch (UnsupportedOperationException tolerated) { - } catch (IndexOutOfBoundsException tolerated) { - } - expectUnchanged(); - } - - @CollectionSize.Require(absent = ZERO) - @ListFeature.Require(SUPPORTS_SET) - @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) - public void testSet_nullUnsupported() { - try { - getList().set(aValidIndex(), null); - fail("set(null) should throw NullPointerException"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - } - - private int aValidIndex() { - return getList().size() / 2; - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListSubListTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListSubListTester.java deleted file mode 100644 index 5881d8b..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/ListSubListTester.java +++ /dev/null @@ -1,324 +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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS; -import static com.google.common.collect.testing.features.CollectionSize.ONE; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX; -import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_REMOVE_WITH_INDEX; -import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_SET; -import static java.util.Collections.emptyList; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.Helpers; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.ListFeature; -import com.google.common.testing.SerializableTester; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * A generic JUnit test which tests {@code subList()} operations on a list. - * Can't be invoked directly; please see - * {@link com.google.common.collect.testing.ListTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - */ -@SuppressWarnings("unchecked") // too many "unchecked generic array creations" -@GwtCompatible(emulated = true) -public class ListSubListTester<E> extends AbstractListTester<E> { - public void testSubList_startNegative() { - try { - getList().subList(-1, 0); - fail("subList(-1, 0) should throw"); - } catch (IndexOutOfBoundsException expected) { - } - } - - public void testSubList_endTooLarge() { - try { - getList().subList(0, getNumElements() + 1); - fail("subList(0, size + 1) should throw"); - } catch (IndexOutOfBoundsException expected) { - } - } - - public void testSubList_startGreaterThanEnd() { - try { - getList().subList(1, 0); - fail("subList(1, 0) should throw"); - } catch (IndexOutOfBoundsException expected) { - } catch (IllegalArgumentException expected) { - /* - * The subList() docs claim that this should be an - * IndexOutOfBoundsException, but many JDK implementations throw - * IllegalArgumentException: - * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4506427 - */ - } - } - - public void testSubList_empty() { - assertEquals("subList(0, 0) should be empty", - emptyList(), getList().subList(0, 0)); - } - - public void testSubList_entireList() { - assertEquals("subList(0, size) should be equal to the original list", - getList(), getList().subList(0, getNumElements())); - } - - @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) - @CollectionSize.Require(absent = ZERO) - public void testSubList_subListRemoveAffectsOriginal() { - List<E> subList = getList().subList(0, 1); - subList.remove(0); - List<E> expected = - Arrays.asList(createSamplesArray()).subList(1, getNumElements()); - expectContents(expected); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - public void testSubList_subListAddAffectsOriginal() { - List<E> subList = getList().subList(0, 0); - subList.add(samples.e3); - expectAdded(0, samples.e3); - } - - @ListFeature.Require(SUPPORTS_SET) - @CollectionSize.Require(absent = ZERO) - public void testSubList_subListSetAffectsOriginal() { - List<E> subList = getList().subList(0, 1); - subList.set(0, samples.e3); - List<E> expected = Helpers.copyToList(createSamplesArray()); - expected.set(0, samples.e3); - expectContents(expected); - } - - @ListFeature.Require(SUPPORTS_SET) - @CollectionSize.Require(absent = ZERO) - public void testSubList_originalListSetAffectsSubList() { - List<E> subList = getList().subList(0, 1); - getList().set(0, samples.e3); - assertEquals("A set() call to a list after a sublist has been created " - + "should be reflected in the sublist", - Collections.singletonList(samples.e3), subList); - } - - @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_subListRemoveAffectsOriginalLargeList() { - List<E> subList = getList().subList(1, 3); - subList.remove(samples.e2); - List<E> expected = Helpers.copyToList(createSamplesArray()); - expected.remove(2); - expectContents(expected); - } - - @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_subListAddAtIndexAffectsOriginalLargeList() { - List<E> subList = getList().subList(2, 3); - subList.add(0, samples.e3); - expectAdded(2, samples.e3); - } - - @ListFeature.Require(SUPPORTS_SET) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_subListSetAffectsOriginalLargeList() { - List<E> subList = getList().subList(1, 2); - subList.set(0, samples.e3); - List<E> expected = Helpers.copyToList(createSamplesArray()); - expected.set(1, samples.e3); - expectContents(expected); - } - - @ListFeature.Require(SUPPORTS_SET) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_originalListSetAffectsSubListLargeList() { - List<E> subList = getList().subList(1, 3); - getList().set(1, samples.e3); - assertEquals("A set() call to a list after a sublist has been created " - + "should be reflected in the sublist", - Arrays.asList(samples.e3, samples.e2), subList); - } - - public void testSubList_ofSubListEmpty() { - List<E> subList = getList().subList(0, 0).subList(0, 0); - assertEquals("subList(0, 0).subList(0, 0) should be an empty list", - emptyList(), subList); - } - - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_ofSubListNonEmpty() { - List<E> subList = getList().subList(0, 2).subList(1, 2); - assertEquals("subList(0, 2).subList(1, 2) " - + "should be a single-element list of the element at index 1", - Collections.singletonList(getOrderedElements().get(1)), subList); - } - - @CollectionSize.Require(absent = {ZERO}) - public void testSubList_size() { - List<E> list = getList(); - int size = getNumElements(); - assertEquals(list.subList(0, size).size(), - size); - assertEquals(list.subList(0, size - 1).size(), - size - 1); - assertEquals(list.subList(1, size).size(), - size - 1); - assertEquals(list.subList(size, size).size(), - 0); - assertEquals(list.subList(0, 0).size(), - 0); - } - - @CollectionSize.Require(absent = {ZERO}) - public void testSubList_isEmpty() { - List<E> list = getList(); - int size = getNumElements(); - for (List<E> subList : Arrays.asList( - list.subList(0, size), - list.subList(0, size - 1), - list.subList(1, size), - list.subList(0, 0), - list.subList(size, size))) { - assertEquals(subList.isEmpty(), subList.size() == 0); - } - } - - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_get() { - List<E> list = getList(); - int size = getNumElements(); - List<E> copy = list.subList(0, size); - List<E> head = list.subList(0, size - 1); - List<E> tail = list.subList(1, size); - assertEquals(list.get(0), copy.get(0)); - assertEquals(list.get(size - 1), copy.get(size - 1)); - assertEquals(list.get(1), tail.get(0)); - assertEquals(list.get(size - 1), tail.get(size - 2)); - assertEquals(list.get(0), head.get(0)); - assertEquals(list.get(size - 2), head.get(size - 2)); - for (List<E> subList : Arrays.asList(copy, head, tail)) { - for (int index : Arrays.asList(-1, subList.size())) { - try { - subList.get(index); - fail("expected IndexOutOfBoundsException"); - } catch (IndexOutOfBoundsException expected) { - } - } - } - } - - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_contains() { - List<E> list = getList(); - int size = getNumElements(); - List<E> copy = list.subList(0, size); - List<E> head = list.subList(0, size - 1); - List<E> tail = list.subList(1, size); - assertTrue(copy.contains(list.get(0))); - assertTrue(head.contains(list.get(0))); - assertTrue(tail.contains(list.get(1))); - // The following assumes all elements are distinct. - assertTrue(copy.contains(list.get(size - 1))); - assertTrue(head.contains(list.get(size - 2))); - assertTrue(tail.contains(list.get(size - 1))); - assertFalse(head.contains(list.get(size - 1))); - assertFalse(tail.contains(list.get(0))); - } - - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_indexOf() { - List<E> list = getList(); - int size = getNumElements(); - List<E> copy = list.subList(0, size); - List<E> head = list.subList(0, size - 1); - List<E> tail = list.subList(1, size); - assertEquals(copy.indexOf(list.get(0)), - 0); - assertEquals(head.indexOf(list.get(0)), - 0); - assertEquals(tail.indexOf(list.get(1)), - 0); - // The following assumes all elements are distinct. - assertEquals(copy.indexOf(list.get(size - 1)), - size - 1); - assertEquals(head.indexOf(list.get(size - 2)), - size - 2); - assertEquals(tail.indexOf(list.get(size - 1)), - size - 2); - assertEquals(head.indexOf(list.get(size - 1)), - -1); - assertEquals(tail.indexOf(list.get(0)), - -1); - } - - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testSubList_lastIndexOf() { - List<E> list = getList(); - int size = list.size(); - List<E> copy = list.subList(0, size); - List<E> head = list.subList(0, size - 1); - List<E> tail = list.subList(1, size); - assertEquals(copy.lastIndexOf(list.get(size - 1)), - size - 1); - assertEquals(head.lastIndexOf(list.get(size - 2)), - size - 2); - assertEquals(tail.lastIndexOf(list.get(size - 1)), - size - 2); - // The following assumes all elements are distinct. - assertEquals(copy.lastIndexOf(list.get(0)), - 0); - assertEquals(head.lastIndexOf(list.get(0)), - 0); - assertEquals(tail.lastIndexOf(list.get(1)), - 0); - assertEquals(head.lastIndexOf(list.get(size - 1)), - -1); - assertEquals(tail.lastIndexOf(list.get(0)), - -1); - } - - @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS) - public void testReserializeWholeSubList() { - SerializableTester.reserializeAndAssert(getList().subList(0, getNumElements())); - } - - @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS) - public void testReserializeEmptySubList() { - SerializableTester.reserializeAndAssert(getList().subList(0, 0)); - } - - @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testReserializeSubList() { - SerializableTester.reserializeAndAssert(getList().subList(0, 2)); - } - - /* - * TODO: perform all List tests on subList(), but beware infinite recursion - */ -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapCreationTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapCreationTester.java deleted file mode 100644 index 6f8ab8a..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapCreationTester.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.features.CollectionSize.ONE; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -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 static com.google.common.collect.testing.features.MapFeature.REJECTS_DUPLICATES_AT_CREATION; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.AbstractMapTester; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.MapFeature; - -import java.util.Arrays; -import java.util.List; -import java.util.Map.Entry; - -/** - * A generic JUnit test which tests creation (typically through a constructor or - * static factory method) of a map. Can't be invoked directly; please see - * {@link com.google.common.collect.testing.MapTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - * @author Kevin Bourrillion - */ -@GwtCompatible(emulated = true) -public class MapCreationTester<K, V> extends AbstractMapTester<K, V> { - @MapFeature.Require(ALLOWS_NULL_KEYS) - @CollectionSize.Require(absent = ZERO) - public void testCreateWithNullKeySupported() { - initMapWithNullKey(); - expectContents(createArrayWithNullKey()); - } - - @MapFeature.Require(absent = ALLOWS_NULL_KEYS) - @CollectionSize.Require(absent = ZERO) - public void testCreateWithNullKeyUnsupported() { - try { - initMapWithNullKey(); - fail("Creating a map containing a null key should fail"); - } catch (NullPointerException expected) { - } - } - - @MapFeature.Require(ALLOWS_NULL_VALUES) - @CollectionSize.Require(absent = ZERO) - public void testCreateWithNullValueSupported() { - initMapWithNullValue(); - expectContents(createArrayWithNullValue()); - } - - @MapFeature.Require(absent = ALLOWS_NULL_VALUES) - @CollectionSize.Require(absent = ZERO) - public void testCreateWithNullValueUnsupported() { - try { - initMapWithNullValue(); - fail("Creating a map containing a null value should fail"); - } catch (NullPointerException expected) { - } - } - - @MapFeature.Require({ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES}) - @CollectionSize.Require(absent = ZERO) - public void testCreateWithNullKeyAndValueSupported() { - Entry<K, V>[] entries = createSamplesArray(); - entries[getNullLocation()] = entry(null, null); - resetMap(entries); - expectContents(entries); - } - - @MapFeature.Require(value = ALLOWS_NULL_KEYS, - absent = REJECTS_DUPLICATES_AT_CREATION) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testCreateWithDuplicates_nullDuplicatesNotRejected() { - expectFirstRemoved(getEntriesMultipleNullKeys()); - } - - @MapFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testCreateWithDuplicates_nonNullDuplicatesNotRejected() { - expectFirstRemoved(getEntriesMultipleNonNullKeys()); - } - - @MapFeature.Require({ALLOWS_NULL_KEYS, REJECTS_DUPLICATES_AT_CREATION}) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testCreateWithDuplicates_nullDuplicatesRejected() { - Entry<K, V>[] entries = getEntriesMultipleNullKeys(); - try { - resetMap(entries); - fail("Should reject duplicate null elements at creation"); - } catch (IllegalArgumentException expected) { - } - } - - @MapFeature.Require(REJECTS_DUPLICATES_AT_CREATION) - @CollectionSize.Require(absent = {ZERO, ONE}) - public void testCreateWithDuplicates_nonNullDuplicatesRejected() { - Entry<K, V>[] entries = getEntriesMultipleNonNullKeys(); - try { - resetMap(entries); - fail("Should reject duplicate non-null elements at creation"); - } catch (IllegalArgumentException expected) { - } - } - - private Entry<K, V>[] getEntriesMultipleNullKeys() { - Entry<K, V>[] entries = createArrayWithNullKey(); - entries[0] = entry(null, entries[0].getValue()); - return entries; - } - - private Entry<K, V>[] getEntriesMultipleNonNullKeys() { - Entry<K, V>[] entries = createSamplesArray(); - entries[0] = entry(samples.e1.getKey(), samples.e0.getValue()); - return entries; - } - - private void expectFirstRemoved(Entry<K, V>[] entries) { - resetMap(entries); - - List<Entry<K, V>> expectedWithDuplicateRemoved = - Arrays.asList(entries).subList(1, getNumElements()); - expectContents(expectedWithDuplicateRemoved); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapPutAllTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapPutAllTester.java deleted file mode 100644 index 48ff734..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapPutAllTester.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -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 static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; -import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; -import static java.util.Collections.singletonList; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.AbstractMapTester; -import com.google.common.collect.testing.MinimalCollection; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.MapFeature; - -import java.util.Collections; -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * A generic JUnit test which tests {@code putAll} operations on a map. Can't be - * invoked directly; please see - * {@link com.google.common.collect.testing.MapTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - * @author Kevin Bourrillion - */ -@SuppressWarnings("unchecked") // too many "unchecked generic array creations" -@GwtCompatible(emulated = true) -public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> { - private List<Entry<K, V>> containsNullKey; - private List<Entry<K, V>> containsNullValue; - - @Override public void setUp() throws Exception { - super.setUp(); - containsNullKey = singletonList(entry(null, samples.e3.getValue())); - containsNullValue = singletonList(entry(samples.e3.getKey(), null)); - } - - @MapFeature.Require(SUPPORTS_PUT) - public void testPutAll_supportedNothing() { - getMap().putAll(emptyMap()); - expectUnchanged(); - } - - @MapFeature.Require(absent = SUPPORTS_PUT) - public void testPutAll_unsupportedNothing() { - try { - getMap().putAll(emptyMap()); - } catch (UnsupportedOperationException tolerated) { - } - expectUnchanged(); - } - - @MapFeature.Require(SUPPORTS_PUT) - public void testPutAll_supportedNonePresent() { - putAll(createDisjointCollection()); - expectAdded(samples.e3, samples.e4); - } - - @MapFeature.Require(absent = SUPPORTS_PUT) - public void testPutAll_unsupportedNonePresent() { - try { - putAll(createDisjointCollection()); - fail("putAll(nonePresent) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - expectMissing(samples.e3, samples.e4); - } - - @MapFeature.Require(SUPPORTS_PUT) - @CollectionSize.Require(absent = ZERO) - public void testPutAll_supportedSomePresent() { - putAll(MinimalCollection.of(samples.e3, samples.e0)); - expectAdded(samples.e3); - } - - @MapFeature.Require({ FAILS_FAST_ON_CONCURRENT_MODIFICATION, - SUPPORTS_PUT }) - @CollectionSize.Require(absent = ZERO) - public void testPutAllSomePresentConcurrentWithEntrySetIteration() { - try { - Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator(); - putAll(MinimalCollection.of(samples.e3, samples.e0)); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @MapFeature.Require(absent = SUPPORTS_PUT) - @CollectionSize.Require(absent = ZERO) - public void testPutAll_unsupportedSomePresent() { - try { - putAll(MinimalCollection.of(samples.e3, samples.e0)); - fail("putAll(somePresent) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - } - - @MapFeature.Require(absent = SUPPORTS_PUT) - @CollectionSize.Require(absent = ZERO) - public void testPutAll_unsupportedAllPresent() { - try { - putAll(MinimalCollection.of(samples.e0)); - } catch (UnsupportedOperationException tolerated) { - } - expectUnchanged(); - } - - @MapFeature.Require({SUPPORTS_PUT, - ALLOWS_NULL_KEYS}) - public void testPutAll_nullKeySupported() { - putAll(containsNullKey); - expectAdded(containsNullKey.get(0)); - } - - @MapFeature.Require(value = SUPPORTS_PUT, - absent = ALLOWS_NULL_KEYS) - public void testPutAll_nullKeyUnsupported() { - try { - putAll(containsNullKey); - fail("putAll(containsNullKey) should throw"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - expectNullKeyMissingWhenNullKeysUnsupported( - "Should not contain null key after unsupported " + - "putAll(containsNullKey)"); - } - - @MapFeature.Require({SUPPORTS_PUT, - ALLOWS_NULL_VALUES}) - public void testPutAll_nullValueSupported() { - putAll(containsNullValue); - expectAdded(containsNullValue.get(0)); - } - - @MapFeature.Require(value = SUPPORTS_PUT, - absent = ALLOWS_NULL_VALUES) - public void testPutAll_nullValueUnsupported() { - try { - putAll(containsNullValue); - fail("putAll(containsNullValue) should throw"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - expectNullValueMissingWhenNullValuesUnsupported( - "Should not contain null value after unsupported " + - "putAll(containsNullValue)"); - } - - @MapFeature.Require(SUPPORTS_PUT) - public void testPutAll_nullCollectionReference() { - try { - getMap().putAll(null); - fail("putAll(null) should throw NullPointerException"); - } catch (NullPointerException expected) { - } - } - - private Map<K, V> emptyMap() { - return Collections.emptyMap(); - } - - private void putAll(Iterable<Entry<K, V>> entries) { - Map<K, V> map = new LinkedHashMap<K, V>(); - for (Entry<K, V> entry : entries) { - map.put(entry.getKey(), entry.getValue()); - } - getMap().putAll(map); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapPutTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapPutTester.java deleted file mode 100644 index 78de07d..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/MapPutTester.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -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 static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; -import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.AbstractMapTester; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.MapFeature; - -import java.util.ConcurrentModificationException; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -/** - * A generic JUnit test which tests {@code put} operations on a map. Can't be - * invoked directly; please see - * {@link com.google.common.collect.testing.MapTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Chris Povirk - * @author Kevin Bourrillion - */ -@SuppressWarnings("unchecked") // too many "unchecked generic array creations" -@GwtCompatible(emulated = true) -public class MapPutTester<K, V> extends AbstractMapTester<K, V> { - private Entry<K, V> nullKeyEntry; - private Entry<K, V> nullValueEntry; - private Entry<K, V> nullKeyValueEntry; - private Entry<K, V> presentKeyNullValueEntry; - - @Override public void setUp() throws Exception { - super.setUp(); - nullKeyEntry = entry(null, samples.e3.getValue()); - nullValueEntry = entry(samples.e3.getKey(), null); - nullKeyValueEntry = entry(null, null); - presentKeyNullValueEntry = entry(samples.e0.getKey(), null); - } - - @MapFeature.Require(SUPPORTS_PUT) - public void testPut_supportedNotPresent() { - assertNull("put(notPresent, value) should return null", put(samples.e3)); - expectAdded(samples.e3); - } - - @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT}) - @CollectionSize.Require(absent = ZERO) - public void testPutAbsentConcurrentWithEntrySetIteration() { - try { - Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator(); - put(samples.e3); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT}) - @CollectionSize.Require(absent = ZERO) - public void testPutAbsentConcurrentWithKeySetIteration() { - try { - Iterator<K> iterator = getMap().keySet().iterator(); - put(samples.e3); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_PUT}) - @CollectionSize.Require(absent = ZERO) - public void testPutAbsentConcurrentWithValueIteration() { - try { - Iterator<V> iterator = getMap().values().iterator(); - put(samples.e3); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @MapFeature.Require(absent = SUPPORTS_PUT) - public void testPut_unsupportedNotPresent() { - try { - put(samples.e3); - fail("put(notPresent, value) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - expectMissing(samples.e3); - } - - @MapFeature.Require(absent = SUPPORTS_PUT) - @CollectionSize.Require(absent = ZERO) - public void testPut_unsupportedPresentExistingValue() { - try { - assertEquals("put(present, existingValue) should return present or throw", - samples.e0.getValue(), put(samples.e0)); - } catch (UnsupportedOperationException tolerated) { - } - expectUnchanged(); - } - - @MapFeature.Require(absent = SUPPORTS_PUT) - @CollectionSize.Require(absent = ZERO) - public void testPut_unsupportedPresentDifferentValue() { - try { - getMap().put(samples.e0.getKey(), samples.e3.getValue()); - fail("put(present, differentValue) should throw"); - } catch (UnsupportedOperationException expected) { - } - expectUnchanged(); - } - - @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS}) - public void testPut_nullKeySupportedNotPresent() { - assertNull("put(null, value) should return null", put(nullKeyEntry)); - expectAdded(nullKeyEntry); - } - - @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS}) - @CollectionSize.Require(absent = ZERO) - public void testPut_nullKeySupportedPresent() { - Entry<K, V> newEntry = entry(null, samples.e3.getValue()); - initMapWithNullKey(); - assertEquals("put(present, value) should return the associated value", - getValueForNullKey(), put(newEntry)); - - Entry<K, V>[] expected = createArrayWithNullKey(); - expected[getNullLocation()] = newEntry; - expectContents(expected); - } - - @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEYS) - public void testPut_nullKeyUnsupported() { - try { - put(nullKeyEntry); - fail("put(null, value) should throw"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - expectNullKeyMissingWhenNullKeysUnsupported( - "Should not contain null key after unsupported put(null, value)"); - } - - @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) - public void testPut_nullValueSupported() { - assertNull("put(key, null) should return null", put(nullValueEntry)); - expectAdded(nullValueEntry); - } - - @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) - public void testPut_nullValueUnsupported() { - try { - put(nullValueEntry); - fail("put(key, null) should throw"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - expectNullValueMissingWhenNullValuesUnsupported( - "Should not contain null value after unsupported put(key, null)"); - } - - @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) - @CollectionSize.Require(absent = ZERO) - public void testPut_replaceWithNullValueSupported() { - assertEquals("put(present, null) should return the associated value", - samples.e0.getValue(), put(presentKeyNullValueEntry)); - expectReplacement(presentKeyNullValueEntry); - } - - @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES) - @CollectionSize.Require(absent = ZERO) - public void testPut_replaceWithNullValueUnsupported() { - try { - put(presentKeyNullValueEntry); - fail("put(present, null) should throw"); - } catch (NullPointerException expected) { - } - expectUnchanged(); - expectNullValueMissingWhenNullValuesUnsupported( - "Should not contain null after unsupported put(present, null)"); - } - - @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) - @CollectionSize.Require(absent = ZERO) - public void testPut_replaceNullValueWithNullSupported() { - initMapWithNullValue(); - assertNull("put(present, null) should return the associated value (null)", - getMap().put(getKeyForNullValue(), null)); - expectContents(createArrayWithNullValue()); - } - - @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES}) - @CollectionSize.Require(absent = ZERO) - public void testPut_replaceNullValueWithNonNullSupported() { - Entry<K, V> newEntry = entry(getKeyForNullValue(), samples.e3.getValue()); - initMapWithNullValue(); - assertNull("put(present, value) should return the associated value (null)", - put(newEntry)); - - Entry<K, V>[] expected = createArrayWithNullValue(); - expected[getNullLocation()] = newEntry; - expectContents(expected); - } - - @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES}) - public void testPut_nullKeyAndValueSupported() { - assertNull("put(null, null) should return null", put(nullKeyValueEntry)); - expectAdded(nullKeyValueEntry); - } - - private V put(Map.Entry<K, V> entry) { - return getMap().put(entry.getKey(), entry.getValue()); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/Platform.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/Platform.java deleted file mode 100644 index ce26f1c..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/Platform.java +++ /dev/null @@ -1,74 +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.testers; - -import com.google.common.annotations.GwtCompatible; -import com.google.gwt.core.client.GWT; - -/** - * The emulation source used in GWT. - * - * @author Hayward Chan - */ -@GwtCompatible(emulated = true) -class Platform { - - // Use fewer steps in the ListIteratorTester in ListListIteratorTester because it's slow in prod - // mode. - static int listListIteratorTesterNumIterations() { - // TODO(hhchan): It's 4 in java. Figure out why even 3 is too slow in prod mode. - return GWT.isProdMode() ? 2 : 4; - } - - // Use fewer steps in the IteratorTester in CollectionIteratorTester because it's slow in prod - // mode.. - static int collectionIteratorTesterNumIterations() { - return GWT.isProdMode() ? 3 : 5; - } - - // TODO: Consolidate different copies in one single place. - static String format(String template, Object... args) { - // start substituting the arguments into the '%s' placeholders - StringBuilder builder = new StringBuilder( - template.length() + 16 * args.length); - int templateStart = 0; - int i = 0; - while (i < args.length) { - int placeholderStart = template.indexOf("%s", templateStart); - if (placeholderStart == -1) { - break; - } - builder.append(template.substring(templateStart, placeholderStart)); - builder.append(args[i++]); - templateStart = placeholderStart + 2; - } - builder.append(template.substring(templateStart)); - - // if we run out of placeholders, append the extra args in square braces - if (i < args.length) { - builder.append(" ["); - builder.append(args[i++]); - while (i < args.length) { - builder.append(", "); - builder.append(args[i++]); - } - builder.append("]"); - } - - return builder.toString(); - } -} diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/SetAddTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/SetAddTester.java deleted file mode 100644 index a92aabc..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/SetAddTester.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2007 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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -/** - * A generic JUnit test which tests add operations on a set. Can't be - * invoked directly; please see - * {@link com.google.common.collect.testing.SetTestSuiteBuilder}. - * - * <p>This class is GWT compatible. - * - * @author Kevin Bourrillion - */ -@GwtCompatible(emulated = true) -public class SetAddTester<E> extends AbstractSetTester<E> { - @CollectionFeature.Require(SUPPORTS_ADD) - @CollectionSize.Require(absent = ZERO) - public void testAdd_supportedPresent() { - assertFalse("add(present) should return false", getSet().add(samples.e0)); - expectUnchanged(); - } - - @CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES}) - @CollectionSize.Require(absent = ZERO) - public void testAdd_supportedNullPresent() { - E[] array = createArrayWithNullElement(); - collection = getSubjectGenerator().create(array); - assertFalse("add(nullPresent) should return false", getSet().add(null)); - expectContents(array); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/SetHashCodeTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/SetHashCodeTester.java deleted file mode 100644 index 20dea36..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/super/com/google/common/collect/testing/testers/SetHashCodeTester.java +++ /dev/null @@ -1,63 +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.testers; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.Collection; - -/** - * Tests {@link java.util.Set#hashCode}. - * - * <p>This class is GWT compatible. - * - * @author George van den Driessche - */ -@GwtCompatible(emulated = true) -public class SetHashCodeTester<E> extends AbstractSetTester<E> { - public void testHashCode() { - int expectedHashCode = 0; - for (E element : getSampleElements()) { - expectedHashCode += ((element == null) ? 0 : element.hashCode()); - } - assertEquals( - "A Set's hashCode() should be the sum of those of its elements.", - expectedHashCode, getSet().hashCode()); - } - - @CollectionSize.Require(absent = CollectionSize.ZERO) - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - public void testHashCode_containingNull() { - Collection<E> elements = getSampleElements(getNumElements() - 1); - int expectedHashCode = 0; - for (E element : elements) { - expectedHashCode += ((element == null) ? 0 : element.hashCode()); - } - - elements.add(null); - collection = getSubjectGenerator().create(elements.toArray()); - assertEquals( - "A Set's hashCode() should be the sum of those of its elements (with " - + "a null element counting as having a hash of zero).", - expectedHashCode, getSet().hashCode()); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/testing/super/com/google/common/testing/Platform.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/testing/super/com/google/common/testing/Platform.java deleted file mode 100644 index 9fa092e..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/testing/super/com/google/common/testing/Platform.java +++ /dev/null @@ -1,36 +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.testing; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Methods factored out so that they can be emulated differently in GWT. - * - * @author Chris Povirk - */ -final class Platform { - /** - * Serializes and deserializes the specified object (a no-op under GWT). - */ - @SuppressWarnings("unchecked") - static <T> T reserialize(T object) { - return checkNotNull(object); - } - - private Platform() {} -} diff --git a/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/GwtPlatform.java b/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/GwtPlatform.java deleted file mode 100644 index 4311b8c..0000000 --- a/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/GwtPlatform.java +++ /dev/null @@ -1,40 +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.annotations.GwtCompatible; -import com.google.gwt.core.client.GwtScriptOnly; - -/** - * Version of {@link GwtPlatform} used in hosted-mode. It includes methods in - * {@link Platform} that requires different implementions in web mode and - * hosted mode. It is factored out from {@link Platform} because <code> - * {@literal @}GwtScriptOnly</code> only supports public classes and methods. - * - * @author Hayward Chan - */ -@GwtScriptOnly -@GwtCompatible -public final class GwtPlatform { - - private GwtPlatform() {} - - /** See {@link Platform#clone(Object[])} */ - public static <T> T[] clone(T[] array) { - return array.clone(); - } -} diff --git a/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/Testing.gwt.xml b/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/Testing.gwt.xml deleted file mode 100644 index c990e09..0000000 --- a/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/Testing.gwt.xml +++ /dev/null @@ -1,17 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- semi-autogenerated module descriptor --> -<module> - - <source path=""/> - - <super-source path="super"/> - - <inherits name="com.google.gwt.junit.JUnit"/> - - <inherits name="java.util.Util"/> - - <inherits name="com.google.common.annotations.Annotations"/> - - <inherits name="com.google.common.testing.Testing"/> - -</module> diff --git a/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/google/Google.gwt.xml b/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/google/Google.gwt.xml deleted file mode 100644 index 7ffba41..0000000 --- a/guava-testlib/blackhole-gwt/src/com/google/common/collect/testing/google/Google.gwt.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- semi-autogenerated module descriptor --> -<module> - - <source path=""/> - - <super-source path="super"/> - - <inherits name="com.google.gwt.junit.JUnit"/> - - <inherits name="com.google.common.annotations.Annotations"/> - - <inherits name="com.google.common.base.Base"/> - - <inherits name="com.google.common.collect.Collect"/> - - <inherits name="com.google.common.collect.testing.Testing"/> - - <inherits name="com.google.common.primitives.Primitives"/> - - <inherits name="com.google.common.testing.Testing"/> - -</module> diff --git a/guava-testlib/blackhole-gwt/src/com/google/common/testing/Testing.gwt.xml b/guava-testlib/blackhole-gwt/src/com/google/common/testing/Testing.gwt.xml deleted file mode 100644 index e8fb333..0000000 --- a/guava-testlib/blackhole-gwt/src/com/google/common/testing/Testing.gwt.xml +++ /dev/null @@ -1,19 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- semi-autogenerated module descriptor --> -<module> - - <source path=""/> - - <super-source path="super"/> - - <inherits name="com.google.gwt.junit.JUnit"/> - - <inherits name="java.util.Util"/> - - <inherits name="com.google.common.annotations.Annotations"/> - - <inherits name="com.google.common.base.Base"/> - - <inherits name="com.google.common.collect.Collect"/> - -</module> diff --git a/guava-testlib/blackhole-gwt/test/com/google/common/testing/TestModuleEntryPoint.java b/guava-testlib/blackhole-gwt/test/com/google/common/testing/TestModuleEntryPoint.java deleted file mode 100644 index ed6e199..0000000 --- a/guava-testlib/blackhole-gwt/test/com/google/common/testing/TestModuleEntryPoint.java +++ /dev/null @@ -1,30 +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.testing; - -import com.google.gwt.core.client.EntryPoint; - -/** - * A dummy entry point of the test module. - * - * @author Hayward Chan - */ -public class TestModuleEntryPoint implements EntryPoint { - - @Override public void onModuleLoad() { - } -} diff --git a/guava-testlib/blackhole-gwt/test/com/google/common/testing/testModule.gwt.xml b/guava-testlib/blackhole-gwt/test/com/google/common/testing/testModule.gwt.xml deleted file mode 100644 index f35130d..0000000 --- a/guava-testlib/blackhole-gwt/test/com/google/common/testing/testModule.gwt.xml +++ /dev/null @@ -1,16 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<module> - <inherits name="com.google.gwt.user.User"/> - <inherits name="com.google.gwt.junit.JUnit"/> - <inherits name="com.google.common.collect.Collect"/> - <inherits name="com.google.common.testing.Testing"/> - <inherits name="org.junit.contrib.truth.Truth"/> - <entry-point class="com.google.common.testing.TestModuleEntryPoint"/> - - <source path=""/> - - <add-linker name="std"/> - - <super-source path="super"/> - -</module> |