aboutsummaryrefslogtreecommitdiffstats
path: root/guava-testlib/src/com/google/common
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2015-01-15 16:22:36 +0000
committerPaul Duffin <paulduffin@google.com>2015-01-19 12:15:57 +0000
commitdbd967a6e5c96cc1a97c5521f88dc1564ba2f81b (patch)
tree7365392c3ea77742021cf187acfd465f9bb774ab /guava-testlib/src/com/google/common
parent2d0fc0880966a0cd782d1c09f3b883f209bb3111 (diff)
downloadandroid_external_guava-dbd967a6e5c96cc1a97c5521f88dc1564ba2f81b.tar.gz
android_external_guava-dbd967a6e5c96cc1a97c5521f88dc1564ba2f81b.tar.bz2
android_external_guava-dbd967a6e5c96cc1a97c5521f88dc1564ba2f81b.zip
Revert "Upgraded Guava to unmodified v14.0.1"
This reverts commit 3c77433663281544363151bf284b0240dfd22a42. Change-Id: I25630eb4eef9a993c94f273796d3d9f04811e74d
Diffstat (limited to 'guava-testlib/src/com/google/common')
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTestSuiteBuilder.java5
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTester.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/AbstractContainerTester.java13
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/AbstractIteratorTester.java5
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/AbstractMapTester.java16
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/AbstractTester.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/AnEnum.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/BaseComparable.java5
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/CollectionTestSuiteBuilder.java69
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/ConcurrentMapInterfaceTest.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/DerivedCollectionGenerators.java401
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/DerivedComparable.java5
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/DerivedGenerator.java35
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/DerivedTestIteratorGenerator.java8
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/ExampleIteratorTester.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java42
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/Helpers.java140
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/IteratorFeature.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/IteratorTester.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/ListIteratorTester.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/ListTestSuiteBuilder.java70
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/MapTestSuiteBuilder.java178
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/MinimalCollection.java5
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/MinimalIterable.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/MinimalSet.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/NavigableMapTestSuiteBuilder.java180
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/NavigableSetTestSuiteBuilder.java6
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/OneSizeGenerator.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/OneSizeTestContainerGenerator.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/PerCollectionSizeTestSuiteBuilder.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/Platform.java28
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/SampleElements.java26
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/SetTestSuiteBuilder.java70
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/SortedMapInterfaceTest.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/SortedMapTestSuiteBuilder.java131
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java55
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestCharacterListGenerator.java66
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestCollectionGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestCollidingSetGenerator.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestContainerGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestEnumMapGenerator.java11
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestEnumSetGenerator.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestIntegerSetGenerator.java68
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestIntegerSortedSetGenerator.java44
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestIteratorGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestListGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestMapEntrySetGenerator.java5
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestMapGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestQueueGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestSetGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestSortedMapGenerator.java59
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestStringCollectionGenerator.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestStringListGenerator.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestStringMapGenerator.java5
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestStringQueueGenerator.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestStringSetGenerator.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestStringSortedMapGenerator.java69
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestStringSortedSetGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestSubjectGenerator.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestUnhashableCollectionGenerator.java4
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java13
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java126
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/TestsForSetsInJavaUtil.java82
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/UnhashableObject.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/WrongType.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/CollectionFeature.java24
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/CollectionSize.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/ConflictingRequirementsException.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/Feature.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/FeatureUtil.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/ListFeature.java10
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/MapFeature.java17
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/SetFeature.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/features/TesterRequirements.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/AbstractBiMapTester.java77
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/AbstractListMultimapTester.java54
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/AbstractMultimapTester.java166
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java65
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/BiMapClearTester.java79
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java88
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/BiMapInverseTester.java84
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/BiMapPutTester.java99
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/BiMapRemoveTester.java107
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/BiMapTestSuiteBuilder.java173
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java211
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/ListGenerators.java27
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/ListMultimapPutAllTester.java53
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/ListMultimapPutTester.java77
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/ListMultimapRemoveTester.java116
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/ListMultimapReplaceValuesTester.java48
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java100
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java159
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsEntryTester.java76
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsKeyTester.java90
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsValueTester.java66
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapGetTester.java122
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java76
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapPutTester.java194
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveAllTester.java94
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveEntryTester.java187
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapReplaceValuesTester.java93
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapSizeTester.java91
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultimapTestSuiteBuilder.java600
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultisetIteratorTester.java31
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultisetNavigationTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultisetReadsTester.java7
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultisetSerializationTester.java47
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultisetTestSuiteBuilder.java230
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/MultisetWritesTester.java54
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/Platform.java40
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SetGenerators.java136
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutAllTester.java55
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutTester.java59
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SetMultimapReplaceValuesTester.java49
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SetMultimapTestSuiteBuilder.java111
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java183
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SortedMultisetTestSuiteBuilder.java72
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapGetTester.java35
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapTestSuiteBuilder.java84
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/TestBiMapGenerator.java36
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/TestListMultimapGenerator.java31
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/TestMultimapGenerator.java45
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/TestSetMultimapGenerator.java31
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/TestStringBiMapGenerator.java92
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/TestStringListMultimapGenerator.java101
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/google/TestStringSetMultimapGenerator.java100
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/AbstractListIndexOfTester.java4
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/AbstractListTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/AbstractQueueTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/AbstractSetTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddAllTester.java46
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddTester.java39
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionClearTester.java33
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsAllTester.java3
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionCreationTester.java7
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionEqualsTester.java4
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionIsEmptyTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionIteratorTester.java12
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveAllTester.java50
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveTester.java19
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionRetainAllTester.java54
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionSerializationEqualTester.java40
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionSerializationTester.java41
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionSizeTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionToArrayTester.java6
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/CollectionToStringTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllAtIndexTester.java27
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllTester.java10
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListAddAtIndexTester.java23
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListAddTester.java6
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListCreationTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListEqualsTester.java4
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListGetTester.java5
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListHashCodeTester.java10
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListIndexOfTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListLastIndexOfTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListListIteratorTester.java11
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAllTester.java6
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAtIndexTester.java20
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListRetainAllTester.java8
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListSetTester.java7
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListSubListTester.java40
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/ListToArrayTester.java8
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapClearTester.java58
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapContainsKeyTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapContainsValueTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapCreationTester.java21
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapEqualsTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapGetTester.java4
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapHashCodeTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapIsEmptyTester.java4
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapNavigationTester.java (renamed from guava-testlib/src/com/google/common/collect/testing/testers/NavigableMapNavigationTester.java)31
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapPutAllTester.java64
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapPutTester.java60
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapRemoveTester.java50
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapSerializationTester.java37
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/MapSizeTester.java4
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/Platform.java15
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/QueueElementTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/QueueOfferTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/QueuePeekTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/QueuePollTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/QueueRemoveTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SetAddAllTester.java10
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SetAddTester.java7
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SetCreationTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SetEqualsTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SetHashCodeTester.java9
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SetNavigationTester.java (renamed from guava-testlib/src/com/google/common/collect/testing/testers/NavigableSetNavigationTester.java)113
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SetRemoveTester.java2
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SortedMapNavigationTester.java101
-rw-r--r--guava-testlib/src/com/google/common/collect/testing/testers/SortedSetNavigationTester.java102
-rw-r--r--guava-testlib/src/com/google/common/testing/AbstractPackageSanityTests.java380
-rw-r--r--guava-testlib/src/com/google/common/testing/ArbitraryInstances.java440
-rw-r--r--guava-testlib/src/com/google/common/testing/ClassSanityTester.java765
-rw-r--r--guava-testlib/src/com/google/common/testing/DummyProxy.java110
-rw-r--r--guava-testlib/src/com/google/common/testing/EqualsTester.java13
-rw-r--r--guava-testlib/src/com/google/common/testing/EquivalenceTester.java2
-rw-r--r--guava-testlib/src/com/google/common/testing/FakeTicker.java20
-rw-r--r--guava-testlib/src/com/google/common/testing/ForwardingWrapperTester.java214
-rw-r--r--guava-testlib/src/com/google/common/testing/FreshValueGenerator.java789
-rw-r--r--guava-testlib/src/com/google/common/testing/GcFinalization.java59
-rw-r--r--guava-testlib/src/com/google/common/testing/NullPointerTester.java422
-rw-r--r--guava-testlib/src/com/google/common/testing/RelationshipTester.java62
-rw-r--r--guava-testlib/src/com/google/common/testing/TearDown.java2
-rw-r--r--guava-testlib/src/com/google/common/testing/TearDownStack.java4
-rw-r--r--guava-testlib/src/com/google/common/testing/TestLogHandler.java8
-rw-r--r--guava-testlib/src/com/google/common/testing/package-info.java23
-rw-r--r--guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java117
213 files changed, 1208 insertions, 10804 deletions
diff --git a/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTestSuiteBuilder.java
index e9aac95..32bc3fb 100644
--- a/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTestSuiteBuilder.java
@@ -28,7 +28,6 @@ import com.google.common.collect.testing.testers.CollectionIteratorTester;
import com.google.common.collect.testing.testers.CollectionRemoveAllTester;
import com.google.common.collect.testing.testers.CollectionRemoveTester;
import com.google.common.collect.testing.testers.CollectionRetainAllTester;
-import com.google.common.collect.testing.testers.CollectionSerializationTester;
import com.google.common.collect.testing.testers.CollectionSizeTester;
import com.google.common.collect.testing.testers.CollectionToArrayTester;
import com.google.common.collect.testing.testers.CollectionToStringTester;
@@ -65,15 +64,13 @@ public abstract class AbstractCollectionTestSuiteBuilder<
CollectionRemoveAllTester.class,
CollectionRemoveTester.class,
CollectionRetainAllTester.class,
- CollectionSerializationTester.class,
CollectionSizeTester.class,
CollectionToArrayTester.class,
CollectionToStringTester.class
);
}
- @Override
- protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<
+ @Override List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<
?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>>
parentBuilder) {
DerivedIteratorTestSuiteBuilder<?> iteratorTestSuiteBuilder =
diff --git a/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTester.java b/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTester.java
index 1ddaf93..f1c7688 100644
--- a/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Collection;
/**
@@ -29,7 +27,6 @@ import java.util.Collection;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public abstract class AbstractCollectionTester<E>
extends AbstractContainerTester<Collection<E>, E> {
diff --git a/guava-testlib/src/com/google/common/collect/testing/AbstractContainerTester.java b/guava-testlib/src/com/google/common/collect/testing/AbstractContainerTester.java
index e79ee5f..fb95223 100644
--- a/guava-testlib/src/com/google/common/collect/testing/AbstractContainerTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/AbstractContainerTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -35,7 +33,6 @@ import java.util.List;
*
* @author George van den Driessche
*/
-@GwtCompatible
public abstract class AbstractContainerTester<C, E>
extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
protected SampleElements<E> samples;
@@ -113,7 +110,7 @@ public abstract class AbstractContainerTester<C, E>
}
protected void expectUnchanged() {
- expectContents(getOrderedElements());
+ expectContents(getSampleElements());
}
/**
@@ -124,7 +121,7 @@ public abstract class AbstractContainerTester<C, E>
* of each given element has increased by one since the test collection was
* created, and the number of occurrences of all other elements has not
* changed.
- *
+ *
* <p>Note: This means that a test like the following will fail if
* {@code collection} is a {@code Set}:
*
@@ -173,12 +170,6 @@ public abstract class AbstractContainerTester<C, E>
return array;
}
- protected E[] createOrderedArray() {
- E[] array = getSubjectGenerator().createArray(getNumElements());
- getOrderedElements().toArray(array);
- return array;
- }
-
public static class ArrayWithDuplicate<E> {
public final E[] elements;
public final E duplicate;
diff --git a/guava-testlib/src/com/google/common/collect/testing/AbstractIteratorTester.java b/guava-testlib/src/com/google/common/collect/testing/AbstractIteratorTester.java
index d8e52ec..385b92a 100644
--- a/guava-testlib/src/com/google/common/collect/testing/AbstractIteratorTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/AbstractIteratorTester.java
@@ -19,8 +19,6 @@ package com.google.common.collect.testing;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
-import com.google.common.annotations.GwtCompatible;
-
import junit.framework.AssertionFailedError;
import java.util.ArrayList;
@@ -47,7 +45,6 @@ import java.util.Stack;
* @author Kevin Bourrillion
* @author Chris Povirk
*/
-@GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
private boolean whenNextThrowsExceptionStopTestingCallsToRemove;
private boolean whenAddThrowsExceptionStopTesting;
@@ -425,7 +422,7 @@ abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
private static List<Object> subListCopy(Object[] source, int size) {
final Object[] copy = new Object[size];
- System.arraycopy(source, 0, copy, 0, size);
+ Platform.unsafeArrayCopy(source, 0, copy, 0, size);
return Arrays.asList(copy);
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/AbstractMapTester.java b/guava-testlib/src/com/google/common/collect/testing/AbstractMapTester.java
index b86c61a..c8c3169 100644
--- a/guava-testlib/src/com/google/common/collect/testing/AbstractMapTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/AbstractMapTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -38,7 +36,6 @@ import java.util.Map.Entry;
*
* @author George van den Driessche
*/
-@GwtCompatible
public abstract class AbstractMapTester<K, V> extends
AbstractContainerTester<Map<K, V>, Map.Entry<K, V>> {
protected Map<K, V> getMap() {
@@ -175,16 +172,15 @@ public abstract class AbstractMapTester<K, V> extends
for (Entry<K, V> entry : entries) {
assertFalse("Should not contain entry " + entry,
actualContents().contains(entry));
- assertFalse("Should not contain key " + entry.getKey() + " mapped to"
- + " value " + entry.getValue(),
- equal(getMap().get(entry.getKey()), entry.getValue()));
+ assertFalse("Should not contain key " + entry.getKey(),
+ getMap().containsKey(entry.getKey()));
+ assertFalse("Should not contain value " + entry.getValue(),
+ getMap().containsValue(entry.getValue()));
+ assertNull("Should not return a mapping for key " + entry.getKey(),
+ getMap().get(entry.getKey()));
}
}
- private static boolean equal(Object a, Object b) {
- return a == b || (a != null && a.equals(b));
- }
-
// This one-liner saves us from some ugly casts
protected Entry<K, V> entry(K key, V value) {
return Helpers.mapEntry(key, value);
diff --git a/guava-testlib/src/com/google/common/collect/testing/AbstractTester.java b/guava-testlib/src/com/google/common/collect/testing/AbstractTester.java
index e1c8a6f..c141fb4 100644
--- a/guava-testlib/src/com/google/common/collect/testing/AbstractTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/AbstractTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import junit.framework.TestCase;
/**
@@ -32,7 +30,6 @@ import junit.framework.TestCase;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class AbstractTester<G> extends TestCase {
private G subjectGenerator;
private String suiteName;
diff --git a/guava-testlib/src/com/google/common/collect/testing/AnEnum.java b/guava-testlib/src/com/google/common/collect/testing/AnEnum.java
index 0c9b98e..3fc1ae3 100644
--- a/guava-testlib/src/com/google/common/collect/testing/AnEnum.java
+++ b/guava-testlib/src/com/google/common/collect/testing/AnEnum.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
/**
* A sample enumerated type we use for testing.
*
@@ -25,7 +23,6 @@ import com.google.common.annotations.GwtCompatible;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public enum AnEnum {
A, B, C, D, E, F
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/BaseComparable.java b/guava-testlib/src/com/google/common/collect/testing/BaseComparable.java
index 7ed604d..93f449c 100644
--- a/guava-testlib/src/com/google/common/collect/testing/BaseComparable.java
+++ b/guava-testlib/src/com/google/common/collect/testing/BaseComparable.java
@@ -16,16 +16,13 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.io.Serializable;
/**
* Simple base class to verify that we handle generics correctly.
- *
+ *
* @author Kevin Bourrillion
*/
-@GwtCompatible
public class BaseComparable implements Comparable<BaseComparable>, Serializable {
private final String s;
diff --git a/guava-testlib/src/com/google/common/collect/testing/CollectionTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/CollectionTestSuiteBuilder.java
index d4143b5..e05a700 100644
--- a/guava-testlib/src/com/google/common/collect/testing/CollectionTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/CollectionTestSuiteBuilder.java
@@ -16,25 +16,12 @@
package com.google.common.collect.testing;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.testing.SerializableTester;
-
-import junit.framework.TestSuite;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
/**
* Concrete instantiation of {@link AbstractCollectionTestSuiteBuilder} for
* testing collections that do not have a more specific tester like
* {@link ListTestSuiteBuilder} or {@link SetTestSuiteBuilder}.
*
* @author Chris Povirk
- * @author Louis Wasserman
*/
public class CollectionTestSuiteBuilder<E>
extends AbstractCollectionTestSuiteBuilder<
@@ -43,60 +30,4 @@ public class CollectionTestSuiteBuilder<E>
TestCollectionGenerator<E> generator) {
return new CollectionTestSuiteBuilder<E>().usingGenerator(generator);
}
-
- @Override
- protected
- List<TestSuite>
- createDerivedSuites(
- FeatureSpecificTestSuiteBuilder<
- ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>> parentBuilder) {
- List<TestSuite> derivedSuites = new ArrayList<TestSuite>(
- super.createDerivedSuites(parentBuilder));
-
- if (parentBuilder.getFeatures().contains(CollectionFeature.SERIALIZABLE)) {
- derivedSuites.add(CollectionTestSuiteBuilder
- .using(new ReserializedCollectionGenerator<E>(parentBuilder.getSubjectGenerator()))
- .named(getName() + " reserialized")
- .withFeatures(computeReserializedCollectionFeatures(parentBuilder.getFeatures()))
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
- }
- return derivedSuites;
- }
-
- static class ReserializedCollectionGenerator<E> implements TestCollectionGenerator<E> {
- final OneSizeTestContainerGenerator<Collection<E>, E> gen;
-
- private ReserializedCollectionGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
- this.gen = gen;
- }
-
- @Override
- public SampleElements<E> samples() {
- return gen.samples();
- }
-
- @Override
- public Collection<E> create(Object... elements) {
- return SerializableTester.reserialize(gen.create(elements));
- }
-
- @Override
- public E[] createArray(int length) {
- return gen.createArray(length);
- }
-
- @Override
- public Iterable<E> order(List<E> insertionOrder) {
- return gen.order(insertionOrder);
- }
- }
-
- private static Set<Feature<?>> computeReserializedCollectionFeatures(Set<Feature<?>> features) {
- Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
- derivedFeatures.addAll(features);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);
- return derivedFeatures;
- }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/ConcurrentMapInterfaceTest.java b/guava-testlib/src/com/google/common/collect/testing/ConcurrentMapInterfaceTest.java
index 55db55c..4ad4230 100644
--- a/guava-testlib/src/com/google/common/collect/testing/ConcurrentMapInterfaceTest.java
+++ b/guava-testlib/src/com/google/common/collect/testing/ConcurrentMapInterfaceTest.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.concurrent.ConcurrentMap;
/**
@@ -33,7 +31,6 @@ import java.util.concurrent.ConcurrentMap;
*
* @author Jared Levy
*/
-@GwtCompatible
public abstract class ConcurrentMapInterfaceTest<K, V>
extends MapInterfaceTest<K, V> {
diff --git a/guava-testlib/src/com/google/common/collect/testing/DerivedCollectionGenerators.java b/guava-testlib/src/com/google/common/collect/testing/DerivedCollectionGenerators.java
deleted file mode 100644
index e177f9f..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/DerivedCollectionGenerators.java
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- * Copyright (C) 2008 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.collect.testing.Helpers.castOrCopyToList;
-import static com.google.common.collect.testing.Helpers.equal;
-import static com.google.common.collect.testing.Helpers.mapEntry;
-import static java.util.Collections.sort;
-
-import com.google.common.annotations.GwtCompatible;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.SortedMap;
-
-/**
- * Derived suite generators, split out of the suite builders so that they are available to GWT.
- *
- * @author George van den Driessche
- */
-@GwtCompatible
-public final class DerivedCollectionGenerators {
- public static class MapEntrySetGenerator<K, V>
- implements TestSetGenerator<Map.Entry<K, V>>, DerivedGenerator {
- private final OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>
- mapGenerator;
-
- public MapEntrySetGenerator(
- OneSizeTestContainerGenerator<
- Map<K, V>, Map.Entry<K, V>> mapGenerator) {
- this.mapGenerator = mapGenerator;
- }
-
- @Override
- public SampleElements<Map.Entry<K, V>> samples() {
- return mapGenerator.samples();
- }
-
- @Override
- public Set<Map.Entry<K, V>> create(Object... elements) {
- return mapGenerator.create(elements).entrySet();
- }
-
- @Override
- public Map.Entry<K, V>[] createArray(int length) {
- return mapGenerator.createArray(length);
- }
-
- @Override
- public Iterable<Map.Entry<K, V>> order(
- List<Map.Entry<K, V>> insertionOrder) {
- return mapGenerator.order(insertionOrder);
- }
-
- public OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>> getInnerGenerator() {
- return mapGenerator;
- }
- }
-
- // TODO: investigate some API changes to SampleElements that would tidy up
- // parts of the following classes.
-
- public static class MapKeySetGenerator<K, V>
- implements TestSetGenerator<K>, DerivedGenerator {
- private final OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>
- mapGenerator;
- private final SampleElements<K> samples;
-
- public MapKeySetGenerator(
- OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>
- mapGenerator) {
- this.mapGenerator = mapGenerator;
- final SampleElements<Map.Entry<K, V>> mapSamples =
- this.mapGenerator.samples();
- this.samples = new SampleElements<K>(
- mapSamples.e0.getKey(),
- mapSamples.e1.getKey(),
- mapSamples.e2.getKey(),
- mapSamples.e3.getKey(),
- mapSamples.e4.getKey());
- }
-
- @Override
- public SampleElements<K> samples() {
- return samples;
- }
-
- @Override
- public Set<K> create(Object... elements) {
- @SuppressWarnings("unchecked")
- K[] keysArray = (K[]) elements;
-
- // Start with a suitably shaped collection of entries
- Collection<Map.Entry<K, V>> originalEntries =
- mapGenerator.getSampleElements(elements.length);
-
- // Create a copy of that, with the desired value for each key
- Collection<Map.Entry<K, V>> entries =
- new ArrayList<Entry<K, V>>(elements.length);
- int i = 0;
- for (Map.Entry<K, V> entry : originalEntries) {
- entries.add(Helpers.mapEntry(keysArray[i++], entry.getValue()));
- }
-
- return mapGenerator.create(entries.toArray()).keySet();
- }
-
- @Override
- public K[] createArray(int length) {
- // TODO: with appropriate refactoring of OneSizeGenerator, we can perhaps
- // tidy this up and get rid of the casts here and in
- // MapValueCollectionGenerator.
-
- return ((TestMapGenerator<K, V>) mapGenerator.getInnerGenerator())
- .createKeyArray(length);
- }
-
- @Override
- public Iterable<K> order(List<K> insertionOrder) {
- V v = ((TestMapGenerator<K, V>) mapGenerator.getInnerGenerator()).samples().e0.getValue();
- List<Entry<K, V>> entries = new ArrayList<Entry<K, V>>();
- for (K element : insertionOrder) {
- entries.add(mapEntry(element, v));
- }
-
- List<K> keys = new ArrayList<K>();
- for (Entry<K, V> entry : mapGenerator.order(entries)) {
- keys.add(entry.getKey());
- }
- return keys;
- }
-
- public OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>> getInnerGenerator() {
- return mapGenerator;
- }
- }
-
- public static class MapValueCollectionGenerator<K, V>
- implements TestCollectionGenerator<V>, DerivedGenerator {
- private final OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>
- mapGenerator;
- private final SampleElements<V> samples;
-
- public MapValueCollectionGenerator(
- OneSizeTestContainerGenerator<
- Map<K, V>, Map.Entry<K, V>> mapGenerator) {
- this.mapGenerator = mapGenerator;
- final SampleElements<Map.Entry<K, V>> mapSamples =
- this.mapGenerator.samples();
- this.samples = new SampleElements<V>(
- mapSamples.e0.getValue(),
- mapSamples.e1.getValue(),
- mapSamples.e2.getValue(),
- mapSamples.e3.getValue(),
- mapSamples.e4.getValue());
- }
-
- @Override
- public SampleElements<V> samples() {
- return samples;
- }
-
- @Override
- public Collection<V> create(Object... elements) {
- @SuppressWarnings("unchecked")
- V[] valuesArray = (V[]) elements;
-
- // Start with a suitably shaped collection of entries
- Collection<Map.Entry<K, V>> originalEntries =
- mapGenerator.getSampleElements(elements.length);
-
- // Create a copy of that, with the desired value for each value
- Collection<Map.Entry<K, V>> entries =
- new ArrayList<Entry<K, V>>(elements.length);
- int i = 0;
- for (Map.Entry<K, V> entry : originalEntries) {
- entries.add(Helpers.mapEntry(entry.getKey(), valuesArray[i++]));
- }
-
- return mapGenerator.create(entries.toArray()).values();
- }
-
- @Override
- public V[] createArray(int length) {
- //noinspection UnnecessaryLocalVariable
- final V[] vs = ((TestMapGenerator<K, V>) mapGenerator.getInnerGenerator())
- .createValueArray(length);
- return vs;
- }
-
- @Override
- public Iterable<V> order(List<V> insertionOrder) {
- final List<Entry<K, V>> orderedEntries =
- castOrCopyToList(mapGenerator.order(castOrCopyToList(
- mapGenerator.getSampleElements(5))));
- sort(insertionOrder, new Comparator<V>() {
- @Override public int compare(V left, V right) {
- // The indexes are small enough for the subtraction trick to be safe.
- return indexOfEntryWithValue(left) - indexOfEntryWithValue(right);
- }
-
- int indexOfEntryWithValue(V value) {
- for (int i = 0; i < orderedEntries.size(); i++) {
- if (equal(orderedEntries.get(i).getValue(), value)) {
- return i;
- }
- }
- throw new IllegalArgumentException("Map.values generator can order only sample values");
- }
- });
- return insertionOrder;
- }
-
- public OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>> getInnerGenerator() {
- return mapGenerator;
- }
- }
-
- // TODO(cpovirk): could something like this be used elsewhere, e.g., ReserializedListGenerator?
- static class ForwardingTestMapGenerator<K, V> implements TestMapGenerator<K, V> {
- TestMapGenerator<K, V> delegate;
-
- ForwardingTestMapGenerator(TestMapGenerator<K, V> delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public Iterable<Entry<K, V>> order(List<Entry<K, V>> insertionOrder) {
- return delegate.order(insertionOrder);
- }
-
- @Override
- public K[] createKeyArray(int length) {
- return delegate.createKeyArray(length);
- }
-
- @Override
- public V[] createValueArray(int length) {
- return delegate.createValueArray(length);
- }
-
- @Override
- public SampleElements<Entry<K, V>> samples() {
- return delegate.samples();
- }
-
- @Override
- public Map<K, V> create(Object... elements) {
- return delegate.create(elements);
- }
-
- @Override
- public Entry<K, V>[] createArray(int length) {
- return delegate.createArray(length);
- }
- }
-
- /**
- * Two bounds (from and to) define how to build a subMap.
- */
- public enum Bound {
- INCLUSIVE,
- EXCLUSIVE,
- NO_BOUND;
- }
-
- /*
- * TODO(cpovirk): surely we can find a less ugly solution than a class that accepts 3 parameters,
- * exposes as many getters, does work in the constructor, and has both a superclass and a subclass
- */
- public static class SortedMapSubmapTestMapGenerator<K, V>
- extends ForwardingTestMapGenerator<K, V> implements TestSortedMapGenerator<K, V> {
- final Bound to;
- final Bound from;
- final K firstInclusive;
- final K lastInclusive;
- private final Comparator<Entry<K, V>> entryComparator;
-
- public SortedMapSubmapTestMapGenerator(
- TestSortedMapGenerator<K, V> delegate, Bound to, Bound from) {
- super(delegate);
- this.to = to;
- this.from = from;
-
- SortedMap<K, V> emptyMap = delegate.create();
- this.entryComparator = Helpers.entryComparator(emptyMap.comparator());
-
- // derive values for inclusive filtering from the input samples
- SampleElements<Entry<K, V>> samples = delegate.samples();
- @SuppressWarnings("unchecked") // no elements are inserted into the array
- List<Entry<K, V>> samplesList = Arrays.asList(
- samples.e0, samples.e1, samples.e2, samples.e3, samples.e4);
- Collections.sort(samplesList, entryComparator);
- this.firstInclusive = samplesList.get(0).getKey();
- this.lastInclusive = samplesList.get(samplesList.size() - 1).getKey();
- }
-
- @Override public SortedMap<K, V> create(Object... entries) {
- @SuppressWarnings("unchecked") // map generators must past entry objects
- List<Entry<K, V>> normalValues = (List) Arrays.asList(entries);
- List<Entry<K, V>> extremeValues = new ArrayList<Entry<K, V>>();
-
- // prepare extreme values to be filtered out of view
- K firstExclusive = getInnerGenerator().belowSamplesGreater().getKey();
- K lastExclusive = getInnerGenerator().aboveSamplesLesser().getKey();
- if (from != Bound.NO_BOUND) {
- extremeValues.add(getInnerGenerator().belowSamplesLesser());
- extremeValues.add(getInnerGenerator().belowSamplesGreater());
- }
- if (to != Bound.NO_BOUND) {
- extremeValues.add(getInnerGenerator().aboveSamplesLesser());
- extremeValues.add(getInnerGenerator().aboveSamplesGreater());
- }
-
- // the regular values should be visible after filtering
- List<Entry<K, V>> allEntries = new ArrayList<Entry<K, V>>();
- allEntries.addAll(extremeValues);
- allEntries.addAll(normalValues);
- SortedMap<K, V> map = (SortedMap<K, V>)
- delegate.create((Object[])
- allEntries.toArray(new Entry[allEntries.size()]));
-
- return createSubMap(map, firstExclusive, lastExclusive);
- }
-
- /**
- * Calls the smallest subMap overload that filters out the extreme values. This method is
- * overridden in NavigableMapTestSuiteBuilder.
- */
- SortedMap<K, V> createSubMap(SortedMap<K, V> map, K firstExclusive, K lastExclusive) {
- if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
- return map.headMap(lastExclusive);
- } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
- return map.tailMap(firstInclusive);
- } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
- return map.subMap(firstInclusive, lastExclusive);
- } else {
- throw new IllegalArgumentException();
- }
- }
-
- public final Bound getTo() {
- return to;
- }
-
- public final Bound getFrom() {
- return from;
- }
-
- public final TestSortedMapGenerator<K, V> getInnerGenerator() {
- return (TestSortedMapGenerator<K, V>) delegate;
- }
-
- @Override
- public Entry<K, V> belowSamplesLesser() {
- // should never reach here!
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Entry<K, V> belowSamplesGreater() {
- // should never reach here!
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Entry<K, V> aboveSamplesLesser() {
- // should never reach here!
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Entry<K, V> aboveSamplesGreater() {
- // should never reach here!
- throw new UnsupportedOperationException();
- }
- }
-
- private DerivedCollectionGenerators() {}
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/DerivedComparable.java b/guava-testlib/src/com/google/common/collect/testing/DerivedComparable.java
index 5b0d16f..254bd57 100644
--- a/guava-testlib/src/com/google/common/collect/testing/DerivedComparable.java
+++ b/guava-testlib/src/com/google/common/collect/testing/DerivedComparable.java
@@ -16,14 +16,11 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
/**
* Simple derived class to verify that we handle generics correctly.
- *
+ *
* @author Kevin Bourrillion
*/
-@GwtCompatible
public class DerivedComparable extends BaseComparable {
public DerivedComparable(String s) {
super(s);
diff --git a/guava-testlib/src/com/google/common/collect/testing/DerivedGenerator.java b/guava-testlib/src/com/google/common/collect/testing/DerivedGenerator.java
deleted file mode 100644
index d80f5a9..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/DerivedGenerator.java
+++ /dev/null
@@ -1,35 +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;
-
-import com.google.common.annotations.GwtCompatible;
-
-/**
- * A generator that relies on a preexisting generator for most of its work. For example, a derived
- * iterator generator may delegate the work of creating the underlying collection to an inner
- * collection generator.
- *
- * <p>{@code GwtTestSuiteGenerator} expects every {@code DerivedIterator} implementation to provide
- * a one-arg constructor accepting its inner generator as an argument). This requirement enables it
- * to generate source code (since GWT cannot use reflection to generate the suites).
- *
- * @author Chris Povirk
- */
-@GwtCompatible
-public interface DerivedGenerator {
- TestSubjectGenerator<?> getInnerGenerator();
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/DerivedTestIteratorGenerator.java b/guava-testlib/src/com/google/common/collect/testing/DerivedTestIteratorGenerator.java
index cd23173..a1ff114 100644
--- a/guava-testlib/src/com/google/common/collect/testing/DerivedTestIteratorGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/DerivedTestIteratorGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Iterator;
/**
@@ -27,9 +25,8 @@ import java.util.Iterator;
*
* @author George van den Driessche
*/
-@GwtCompatible
public final class DerivedTestIteratorGenerator<E>
- implements TestIteratorGenerator<E>, DerivedGenerator {
+ implements TestIteratorGenerator<E> {
private final TestSubjectGenerator<? extends Iterable<E>>
collectionGenerator;
@@ -38,8 +35,7 @@ public final class DerivedTestIteratorGenerator<E>
this.collectionGenerator = collectionGenerator;
}
- @Override
- public TestSubjectGenerator<? extends Iterable<E>> getInnerGenerator() {
+ public TestSubjectGenerator<? extends Iterable<E>> getCollectionGenerator() {
return collectionGenerator;
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/ExampleIteratorTester.java b/guava-testlib/src/com/google/common/collect/testing/ExampleIteratorTester.java
index 92388e6..6fa6d40 100644
--- a/guava-testlib/src/com/google/common/collect/testing/ExampleIteratorTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/ExampleIteratorTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
/**
* A non-empty tester for {@link java.util.Iterator}.
*
@@ -25,7 +23,6 @@ import com.google.common.annotations.GwtCompatible;
*
* @author George van den Driessche
*/
-@GwtCompatible
public final class ExampleIteratorTester<E>
extends AbstractTester<TestIteratorGenerator<E>> {
public void testSomethingAboutIterators() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java
index 8163bb5..3cee7ce 100644
--- a/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java
@@ -34,9 +34,10 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
@@ -76,7 +77,7 @@ public abstract class FeatureSpecificTestSuiteBuilder<
return self();
}
- public G getSubjectGenerator() {
+ protected G getSubjectGenerator() {
return subjectGenerator;
}
@@ -100,25 +101,22 @@ public abstract class FeatureSpecificTestSuiteBuilder<
// Features
- private Set<Feature<?>> features = new LinkedHashSet<Feature<?>>();
+ private Set<Feature<?>> features;
/**
* Configures this builder to produce tests appropriate for the given
- * features. This method may be called more than once to add features
- * in multiple groups.
+ * features.
*/
public B withFeatures(Feature<?>... features) {
return withFeatures(Arrays.asList(features));
}
public B withFeatures(Iterable<? extends Feature<?>> features) {
- for (Feature<?> feature : features) {
- this.features.add(feature);
- }
+ this.features = Helpers.copyToSet(features);
return self();
}
- public Set<Feature<?>> getFeatures() {
+ protected Set<Feature<?>> getFeatures() {
return Collections.unmodifiableSet(features);
}
@@ -136,7 +134,7 @@ public abstract class FeatureSpecificTestSuiteBuilder<
return self();
}
- public String getName() {
+ protected String getName() {
return name;
}
@@ -161,7 +159,7 @@ public abstract class FeatureSpecificTestSuiteBuilder<
return self();
}
- public Set<Method> getSuppressedTests() {
+ protected Set<Method> getSuppressedTests() {
return suppressedTests;
}
@@ -274,10 +272,10 @@ public abstract class FeatureSpecificTestSuiteBuilder<
private static Method extractMethod(Test test) {
if (test instanceof AbstractTester) {
AbstractTester<?> tester = (AbstractTester<?>) test;
- return Helpers.getMethod(tester.getClass(), tester.getTestMethodName());
+ return Platform.getMethod(tester.getClass(), tester.getTestMethodName());
} else if (test instanceof TestCase) {
TestCase testCase = (TestCase) test;
- return Helpers.getMethod(testCase.getClass(), testCase.getName());
+ return Platform.getMethod(testCase.getClass(), testCase.getName());
} else {
throw new IllegalArgumentException(
"unable to extract method from test: not a TestCase.");
@@ -286,7 +284,7 @@ public abstract class FeatureSpecificTestSuiteBuilder<
protected TestSuite makeSuiteForTesterClass(
Class<? extends AbstractTester<?>> testerClass) {
- final TestSuite candidateTests = new TestSuite(testerClass);
+ final TestSuite candidateTests = getTemplateSuite(testerClass);
final TestSuite suite = filterSuite(candidateTests);
Enumeration<?> allTests = suite.tests();
@@ -302,6 +300,22 @@ public abstract class FeatureSpecificTestSuiteBuilder<
return suite;
}
+ private static final Map<Class<? extends AbstractTester<?>>, TestSuite>
+ templateSuiteForClass =
+ new HashMap<Class<? extends AbstractTester<?>>, TestSuite>();
+
+ private static TestSuite getTemplateSuite(
+ Class<? extends AbstractTester<?>> testerClass) {
+ synchronized (templateSuiteForClass) {
+ TestSuite suite = templateSuiteForClass.get(testerClass);
+ if (suite == null) {
+ suite = new TestSuite(testerClass);
+ templateSuiteForClass.put(testerClass, suite);
+ }
+ return suite;
+ }
+ }
+
private TestSuite filterSuite(TestSuite suite) {
TestSuite filtered = new TestSuite(suite.getName());
final Enumeration<?> tests = suite.tests();
diff --git a/guava-testlib/src/com/google/common/collect/testing/Helpers.java b/guava-testlib/src/com/google/common/collect/testing/Helpers.java
index 277f50d..9c0a5f5 100644
--- a/guava-testlib/src/com/google/common/collect/testing/Helpers.java
+++ b/guava-testlib/src/com/google/common/collect/testing/Helpers.java
@@ -16,19 +16,13 @@
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 com.google.common.annotations.GwtIncompatible;
-
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
-import java.io.Serializable;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -42,7 +36,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-@GwtCompatible(emulated = true)
+// This class is GWT compatible.
public class Helpers {
// Clone of Objects.equal
static boolean equal(Object a, Object b) {
@@ -72,7 +66,7 @@ public class Helpers {
}
// Would use Maps.immutableEntry
- public static <K, V> Entry<K, V> mapEntry(K key, V value) {
+ static <K, V> Entry<K, V> mapEntry(K key, V value) {
return Collections.singletonMap(key, value).entrySet().iterator().next();
}
@@ -171,11 +165,8 @@ public class Helpers {
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());
+ return keyComparator.compare(a.getKey(), b.getKey());
}
};
}
@@ -257,9 +248,9 @@ public class Helpers {
* 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,
+ public static <K, V> Map.Entry<K, V> nefariousMapEntry(final K key,
final V value) {
- return new Map.Entry<K, V>() {
+ return new Map.Entry<K, V>() {
@Override public K getKey() {
return key;
}
@@ -271,10 +262,10 @@ public class Helpers {
}
@SuppressWarnings("unchecked")
@Override public boolean equals(Object o) {
- if (o instanceof Map.Entry) {
+ 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());
}
@@ -295,120 +286,5 @@ public class Helpers {
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
- }
- }
-
- @GwtIncompatible("reflection")
- public static Method getMethod(Class<?> clazz, String name) {
- try {
- return clazz.getMethod(name);
- } catch (Exception e) {
- throw new IllegalArgumentException(e);
- }
- }
+ }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/IteratorFeature.java b/guava-testlib/src/com/google/common/collect/testing/IteratorFeature.java
index 145dfe2..bcf0fdf 100644
--- a/guava-testlib/src/com/google/common/collect/testing/IteratorFeature.java
+++ b/guava-testlib/src/com/google/common/collect/testing/IteratorFeature.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Collections;
import java.util.EnumSet;
import java.util.Iterator;
@@ -32,7 +30,6 @@ import java.util.Set;
*
* @author Chris Povirk
*/
-@GwtCompatible
public enum IteratorFeature {
/**
* Support for {@link Iterator#remove()}.
diff --git a/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java b/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java
index 2fa77fb..2a17dca 100644
--- a/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Collections;
import java.util.Iterator;
@@ -62,7 +60,6 @@ import java.util.Iterator;
* @author Kevin Bourrillion
* @author Chris Povirk
*/
-@GwtCompatible
public abstract class IteratorTester<E> extends
AbstractIteratorTester<E, Iterator<E>> {
/**
diff --git a/guava-testlib/src/com/google/common/collect/testing/ListIteratorTester.java b/guava-testlib/src/com/google/common/collect/testing/ListIteratorTester.java
index 620b3fd..87d7b71 100644
--- a/guava-testlib/src/com/google/common/collect/testing/ListIteratorTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/ListIteratorTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
@@ -39,7 +37,6 @@ import java.util.ListIterator;
*
* @author Chris Povirk
*/
-@GwtCompatible
public abstract class ListIteratorTester<E> extends
AbstractIteratorTester<E, ListIterator<E>> {
protected ListIteratorTester(int steps, Iterable<E> elementsToInsert,
diff --git a/guava-testlib/src/com/google/common/collect/testing/ListTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/ListTestSuiteBuilder.java
index 03f16cf..e8bdf78 100644
--- a/guava-testlib/src/com/google/common/collect/testing/ListTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/ListTestSuiteBuilder.java
@@ -18,7 +18,6 @@ package com.google.common.collect.testing;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.testers.CollectionSerializationEqualTester;
import com.google.common.collect.testing.testers.ListAddAllAtIndexTester;
import com.google.common.collect.testing.testers.ListAddAllTester;
import com.google.common.collect.testing.testers.ListAddAtIndexTester;
@@ -37,15 +36,10 @@ import com.google.common.collect.testing.testers.ListRetainAllTester;
import com.google.common.collect.testing.testers.ListSetTester;
import com.google.common.collect.testing.testers.ListSubListTester;
import com.google.common.collect.testing.testers.ListToArrayTester;
-import com.google.common.testing.SerializableTester;
import junit.framework.TestSuite;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
/**
* Creates, based on your criteria, a JUnit test suite that exhaustively tests
@@ -64,7 +58,6 @@ public final class ListTestSuiteBuilder<E> extends
List<Class<? extends AbstractTester>> testers
= Helpers.copyToList(super.getTesters());
- testers.add(CollectionSerializationEqualTester.class);
testers.add(ListAddAllAtIndexTester.class);
testers.add(ListAddAllTester.class);
testers.add(ListAddAtIndexTester.class);
@@ -91,64 +84,11 @@ public final class ListTestSuiteBuilder<E> extends
* lists have an iteration ordering corresponding to the insertion order.
*/
@Override public TestSuite createTestSuite() {
- withFeatures(CollectionFeature.KNOWN_ORDER);
- return super.createTestSuite();
- }
-
- @Override
- protected
- List<TestSuite>
- createDerivedSuites(
- FeatureSpecificTestSuiteBuilder<
- ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>> parentBuilder) {
- List<TestSuite> derivedSuites = new ArrayList<TestSuite>(
- super.createDerivedSuites(parentBuilder));
-
- if (parentBuilder.getFeatures().contains(CollectionFeature.SERIALIZABLE)) {
- derivedSuites.add(ListTestSuiteBuilder
- .using(new ReserializedListGenerator<E>(parentBuilder.getSubjectGenerator()))
- .named(getName() + " reserialized")
- .withFeatures(computeReserializedCollectionFeatures(parentBuilder.getFeatures()))
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
- }
- return derivedSuites;
- }
-
- static class ReserializedListGenerator<E> implements TestListGenerator<E>{
- final OneSizeTestContainerGenerator<Collection<E>, E> gen;
-
- private ReserializedListGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
- this.gen = gen;
- }
-
- @Override
- public SampleElements<E> samples() {
- return gen.samples();
+ if (!getFeatures().contains(CollectionFeature.KNOWN_ORDER)) {
+ List<Feature<?>> features = Helpers.copyToList(getFeatures());
+ features.add(CollectionFeature.KNOWN_ORDER);
+ withFeatures(features);
}
-
- @Override
- public List<E> create(Object... elements) {
- return (List<E>) SerializableTester.reserialize(gen.create(elements));
- }
-
- @Override
- public E[] createArray(int length) {
- return gen.createArray(length);
- }
-
- @Override
- public Iterable<E> order(List<E> insertionOrder) {
- return gen.order(insertionOrder);
- }
- }
-
- private static Set<Feature<?>> computeReserializedCollectionFeatures(
- Set<Feature<?>> features) {
- Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
- derivedFeatures.addAll(features);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);
- return derivedFeatures;
+ return super.createTestSuite();
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java b/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java
index d33f49e..e080157 100644
--- a/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java
+++ b/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java
@@ -18,8 +18,6 @@ package com.google.common.collect.testing;
import static java.util.Collections.singleton;
-import com.google.common.annotations.GwtCompatible;
-
import junit.framework.TestCase;
import java.util.Arrays;
@@ -49,7 +47,6 @@ import java.util.Set;
*
* @author George van den Driessche
*/
-@GwtCompatible
public abstract class MapInterfaceTest<K, V> extends TestCase {
/** A key type that is not assignable to any classes but Object. */
diff --git a/guava-testlib/src/com/google/common/collect/testing/MapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/MapTestSuiteBuilder.java
index aa5b050..dbb7fa2 100644
--- a/guava-testlib/src/com/google/common/collect/testing/MapTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/MapTestSuiteBuilder.java
@@ -16,9 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.collect.testing.DerivedCollectionGenerators.MapEntrySetGenerator;
-import com.google.common.collect.testing.DerivedCollectionGenerators.MapKeySetGenerator;
-import com.google.common.collect.testing.DerivedCollectionGenerators.MapValueCollectionGenerator;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.Feature;
@@ -34,16 +31,17 @@ import com.google.common.collect.testing.testers.MapIsEmptyTester;
import com.google.common.collect.testing.testers.MapPutAllTester;
import com.google.common.collect.testing.testers.MapPutTester;
import com.google.common.collect.testing.testers.MapRemoveTester;
-import com.google.common.collect.testing.testers.MapSerializationTester;
import com.google.common.collect.testing.testers.MapSizeTester;
-import com.google.common.testing.SerializableTester;
import junit.framework.TestSuite;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
/**
@@ -75,13 +73,11 @@ public class MapTestSuiteBuilder<K, V>
MapPutTester.class,
MapPutAllTester.class,
MapRemoveTester.class,
- MapSerializationTester.class,
MapSizeTester.class
);
}
- @Override
- protected List<TestSuite> createDerivedSuites(
+ @Override List<TestSuite> createDerivedSuites(
FeatureSpecificTestSuiteBuilder<
?,
? extends OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>>
@@ -92,15 +88,6 @@ public class MapTestSuiteBuilder<K, V>
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
- if (parentBuilder.getFeatures().contains(CollectionFeature.SERIALIZABLE)) {
- derivedSuites.add(MapTestSuiteBuilder.using(
- new ReserializedMapGenerator<K, V>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeReserializedMapFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + " reserialized")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
- }
-
derivedSuites.add(SetTestSuiteBuilder.using(
new MapEntrySetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
.withFeatures(computeEntrySetFeatures(parentBuilder.getFeatures()))
@@ -131,17 +118,9 @@ public class MapTestSuiteBuilder<K, V>
return SetTestSuiteBuilder.using(keySetGenerator);
}
- private static Set<Feature<?>> computeReserializedMapFeatures(
- Set<Feature<?>> mapFeatures) {
- Set<Feature<?>> derivedFeatures = Helpers.copyToSet(mapFeatures);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);
- return derivedFeatures;
- }
-
private static Set<Feature<?>> computeEntrySetFeatures(
Set<Feature<?>> mapFeatures) {
- Set<Feature<?>> entrySetFeatures =
+ Set<Feature<?>> entrySetFeatures =
computeCommonDerivedCollectionFeatures(mapFeatures);
entrySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
return entrySetFeatures;
@@ -165,9 +144,8 @@ public class MapTestSuiteBuilder<K, V>
Set<Feature<?>> mapFeatures) {
Set<Feature<?>> valuesCollectionFeatures =
computeCommonDerivedCollectionFeatures(mapFeatures);
- if (mapFeatures.contains(MapFeature.ALLOWS_NULL_QUERIES)) {
- valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
- }
+ valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
+
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
}
@@ -178,21 +156,17 @@ public class MapTestSuiteBuilder<K, V>
private static Set<Feature<?>> computeCommonDerivedCollectionFeatures(
Set<Feature<?>> mapFeatures) {
Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
- if (mapFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
- derivedFeatures.add(CollectionFeature.SERIALIZABLE);
- }
if (mapFeatures.contains(MapFeature.SUPPORTS_REMOVE)) {
derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE);
+ derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE_ALL);
+ derivedFeatures.add(CollectionFeature.SUPPORTS_RETAIN_ALL);
+ }
+ if (mapFeatures.contains(MapFeature.SUPPORTS_CLEAR)) {
+ derivedFeatures.add(CollectionFeature.SUPPORTS_CLEAR);
}
if (mapFeatures.contains(MapFeature.REJECTS_DUPLICATES_AT_CREATION)) {
derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
}
- if (mapFeatures.contains(MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION)) {
- derivedFeatures.add(CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION);
- }
- if (mapFeatures.contains(CollectionFeature.KNOWN_ORDER)) {
- derivedFeatures.add(CollectionFeature.KNOWN_ORDER);
- }
// add the intersection of CollectionSize.values() and mapFeatures
for (CollectionSize size : CollectionSize.values()) {
if (mapFeatures.contains(size)) {
@@ -202,12 +176,12 @@ public class MapTestSuiteBuilder<K, V>
return derivedFeatures;
}
- private static class ReserializedMapGenerator<K, V>
- implements TestMapGenerator<K, V> {
+ private static class MapEntrySetGenerator<K, V>
+ implements TestSetGenerator<Map.Entry<K, V>> {
private final OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>
mapGenerator;
- public ReserializedMapGenerator(
+ public MapEntrySetGenerator(
OneSizeTestContainerGenerator<
Map<K, V>, Map.Entry<K, V>> mapGenerator) {
this.mapGenerator = mapGenerator;
@@ -219,6 +193,11 @@ public class MapTestSuiteBuilder<K, V>
}
@Override
+ public Set<Map.Entry<K, V>> create(Object... elements) {
+ return mapGenerator.create(elements).entrySet();
+ }
+
+ @Override
public Map.Entry<K, V>[] createArray(int length) {
return mapGenerator.createArray(length);
}
@@ -228,22 +207,127 @@ public class MapTestSuiteBuilder<K, V>
List<Map.Entry<K, V>> insertionOrder) {
return mapGenerator.order(insertionOrder);
}
+ }
+
+ // TODO: investigate some API changes to SampleElements that would tidy up
+ // parts of the following classes.
+
+ private static class MapKeySetGenerator<K, V> implements TestSetGenerator<K> {
+ private final OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>
+ mapGenerator;
+ private final SampleElements<K> samples;
+
+ public MapKeySetGenerator(
+ OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>
+ mapGenerator) {
+ this.mapGenerator = mapGenerator;
+ final SampleElements<Map.Entry<K, V>> mapSamples =
+ this.mapGenerator.samples();
+ this.samples = new SampleElements<K>(
+ mapSamples.e0.getKey(),
+ mapSamples.e1.getKey(),
+ mapSamples.e2.getKey(),
+ mapSamples.e3.getKey(),
+ mapSamples.e4.getKey());
+ }
@Override
- public Map<K, V> create(Object... elements) {
- return SerializableTester.reserialize(mapGenerator.create(elements));
+ public SampleElements<K> samples() {
+ return samples;
}
@Override
- public K[] createKeyArray(int length) {
+ public Set<K> create(Object... elements) {
+ @SuppressWarnings("unchecked")
+ K[] keysArray = (K[]) elements;
+
+ // Start with a suitably shaped collection of entries
+ Collection<Map.Entry<K, V>> originalEntries =
+ mapGenerator.getSampleElements(elements.length);
+
+ // Create a copy of that, with the desired value for each key
+ Collection<Map.Entry<K, V>> entries =
+ new ArrayList<Entry<K, V>>(elements.length);
+ int i = 0;
+ for (Map.Entry<K, V> entry : originalEntries) {
+ entries.add(Helpers.mapEntry(keysArray[i++], entry.getValue()));
+ }
+
+ return mapGenerator.create(entries.toArray()).keySet();
+ }
+
+ @Override
+ public K[] createArray(int length) {
+ // TODO: with appropriate refactoring of OneSizeGenerator, we can perhaps
+ // tidy this up and get rid of the casts here and in
+ // MapValueCollectionGenerator.
+
return ((TestMapGenerator<K, V>) mapGenerator.getInnerGenerator())
.createKeyArray(length);
}
@Override
- public V[] createValueArray(int length) {
- return ((TestMapGenerator<K, V>) mapGenerator.getInnerGenerator())
- .createValueArray(length);
+ public Iterable<K> order(List<K> insertionOrder) {
+ return insertionOrder;
+ }
+ }
+
+ private static class MapValueCollectionGenerator<K, V>
+ implements TestCollectionGenerator<V> {
+ private final OneSizeTestContainerGenerator<Map<K, V>, Map.Entry<K, V>>
+ mapGenerator;
+ private final SampleElements<V> samples;
+
+ public MapValueCollectionGenerator(
+ OneSizeTestContainerGenerator<
+ Map<K, V>, Map.Entry<K, V>> mapGenerator) {
+ this.mapGenerator = mapGenerator;
+ final SampleElements<Map.Entry<K, V>> mapSamples =
+ this.mapGenerator.samples();
+ this.samples = new SampleElements<V>(
+ mapSamples.e0.getValue(),
+ mapSamples.e1.getValue(),
+ mapSamples.e2.getValue(),
+ mapSamples.e3.getValue(),
+ mapSamples.e4.getValue());
+ }
+
+ @Override
+ public SampleElements<V> samples() {
+ return samples;
+ }
+
+ @Override
+ public Collection<V> create(Object... elements) {
+ @SuppressWarnings("unchecked")
+ V[] valuesArray = (V[]) elements;
+
+ // Start with a suitably shaped collection of entries
+ Collection<Map.Entry<K, V>> originalEntries =
+ mapGenerator.getSampleElements(elements.length);
+
+ // Create a copy of that, with the desired value for each value
+ Collection<Map.Entry<K, V>> entries =
+ new ArrayList<Entry<K, V>>(elements.length);
+ int i = 0;
+ for (Map.Entry<K, V> entry : originalEntries) {
+ entries.add(Helpers.mapEntry(entry.getKey(), valuesArray[i++]));
+ }
+
+ return mapGenerator.create(entries.toArray()).values();
+ }
+
+ @Override
+ public V[] createArray(int length) {
+ //noinspection UnnecessaryLocalVariable
+ final V[] vs = ((TestMapGenerator<K, V>) mapGenerator.getInnerGenerator())
+ .createValueArray(length);
+ return vs;
+ }
+
+ @Override
+ public Iterable<V> order(List<V> insertionOrder) {
+ return insertionOrder;
}
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/MinimalCollection.java b/guava-testlib/src/com/google/common/collect/testing/MinimalCollection.java
index 6c30ab9..20c9db9 100644
--- a/guava-testlib/src/com/google/common/collect/testing/MinimalCollection.java
+++ b/guava-testlib/src/com/google/common/collect/testing/MinimalCollection.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.AbstractCollection;
import java.util.Arrays;
import java.util.Collection;
@@ -29,7 +27,6 @@ import java.util.Iterator;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public class MinimalCollection<E> extends AbstractCollection<E> {
// TODO: expose allow nulls parameter?
@@ -96,7 +93,7 @@ public class MinimalCollection<E> extends AbstractCollection<E> {
@Override public Object[] toArray() {
Object[] result = new Object[contents.length];
- System.arraycopy(contents, 0, result, 0, contents.length);
+ Platform.unsafeArrayCopy(contents, 0, result, 0, contents.length);
return result;
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/MinimalIterable.java b/guava-testlib/src/com/google/common/collect/testing/MinimalIterable.java
index 587e3d3..2d2cf10 100644
--- a/guava-testlib/src/com/google/common/collect/testing/MinimalIterable.java
+++ b/guava-testlib/src/com/google/common/collect/testing/MinimalIterable.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
@@ -50,7 +48,6 @@ import java.util.Iterator;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public final class MinimalIterable<E> implements Iterable<E> {
/**
* Returns an iterable whose iterator returns the given elements in order.
diff --git a/guava-testlib/src/com/google/common/collect/testing/MinimalSet.java b/guava-testlib/src/com/google/common/collect/testing/MinimalSet.java
index 06e4519..e8270dd 100644
--- a/guava-testlib/src/com/google/common/collect/testing/MinimalSet.java
+++ b/guava-testlib/src/com/google/common/collect/testing/MinimalSet.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -33,7 +31,6 @@ import java.util.Set;
*
* @author Regina O'Dell
*/
-@GwtCompatible
public class MinimalSet<E> extends MinimalCollection<E> implements Set<E> {
@SuppressWarnings("unchecked") // empty Object[] as E[]
diff --git a/guava-testlib/src/com/google/common/collect/testing/NavigableMapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/NavigableMapTestSuiteBuilder.java
index 64df720..1d38601 100644
--- a/guava-testlib/src/com/google/common/collect/testing/NavigableMapTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/NavigableMapTestSuiteBuilder.java
@@ -16,30 +16,28 @@
package com.google.common.collect.testing;
-import static com.google.common.collect.testing.Helpers.castOrCopyToList;
-import static java.util.Collections.reverse;
-
-import com.google.common.collect.testing.DerivedCollectionGenerators.Bound;
-import com.google.common.collect.testing.DerivedCollectionGenerators.SortedMapSubmapTestMapGenerator;
import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.testers.NavigableMapNavigationTester;
+import com.google.common.collect.testing.testers.MapNavigationTester;
import junit.framework.TestSuite;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
-import java.util.SortedMap;
+import java.util.Set;
/**
* Creates, based on your criteria, a JUnit test suite that exhaustively tests
* a NavigableMap implementation.
*/
-public class NavigableMapTestSuiteBuilder<K, V> extends SortedMapTestSuiteBuilder<K, V> {
+public class NavigableMapTestSuiteBuilder<K, V> extends MapTestSuiteBuilder<K, V> {
public static <K, V> NavigableMapTestSuiteBuilder<K, V> using(
- TestSortedMapGenerator<K, V> generator) {
+ TestMapGenerator<K, V> generator) {
NavigableMapTestSuiteBuilder<K, V> result = new NavigableMapTestSuiteBuilder<K, V>();
result.usingGenerator(generator);
return result;
@@ -47,12 +45,11 @@ public class NavigableMapTestSuiteBuilder<K, V> extends SortedMapTestSuiteBuilde
@Override protected List<Class<? extends AbstractTester>> getTesters() {
List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
- testers.add(NavigableMapNavigationTester.class);
+ testers.add(MapNavigationTester.class);
return testers;
}
- @Override
- protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?,
+ @Override List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?,
? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>> parentBuilder) {
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
@@ -61,52 +58,148 @@ public class NavigableMapTestSuiteBuilder<K, V> extends SortedMapTestSuiteBuilde
}
if (!parentBuilder.getFeatures().contains(NoRecurse.SUBMAP)) {
- // Other combinations are inherited from SortedMapTestSuiteBuilder.
+ derivedSuites.add(createSubmapSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE));
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.NO_BOUND, Bound.INCLUSIVE));
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.NO_BOUND));
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.EXCLUSIVE));
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.EXCLUSIVE, Bound.INCLUSIVE));
+ derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.NO_BOUND));
+ derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.EXCLUSIVE));
derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.INCLUSIVE));
}
return derivedSuites;
}
- @Override protected NavigableSetTestSuiteBuilder<K> createDerivedKeySetSuite(
+ @Override protected SetTestSuiteBuilder<K> createDerivedKeySetSuite(
TestSetGenerator<K> keySetGenerator) {
return NavigableSetTestSuiteBuilder.using(keySetGenerator);
}
- public static final class NavigableMapSubmapTestMapGenerator<K, V>
- extends SortedMapSubmapTestMapGenerator<K, V> {
- public NavigableMapSubmapTestMapGenerator(
- TestSortedMapGenerator<K, V> delegate, Bound to, Bound from) {
- super(delegate, to, from);
- }
+ /**
+ * To avoid infinite recursion, test suites with these marker features won't
+ * have derived suites created for them.
+ */
+ enum NoRecurse implements Feature<Void> {
+ SUBMAP,
+ DESCENDING;
- @Override NavigableMap<K, V> createSubMap(SortedMap<K, V> sortedMap, K firstExclusive,
- K lastExclusive) {
- NavigableMap<K, V> map = (NavigableMap<K, V>) sortedMap;
- if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) {
- return map.headMap(lastInclusive, true);
- } else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) {
- return map.tailMap(firstExclusive, false);
- } else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) {
- return map.subMap(firstExclusive, false, lastExclusive, false);
- } else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) {
- return map.subMap(firstExclusive, false, lastInclusive, true);
- } else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) {
- return map.subMap(firstInclusive, true, lastInclusive, true);
- } else {
- return (NavigableMap<K, V>) super.createSubMap(map, firstExclusive, lastExclusive);
- }
+ @Override
+ public Set<Feature<? super Void>> getImpliedFeatures() {
+ return Collections.emptySet();
}
}
- @Override
- public NavigableMapTestSuiteBuilder<K, V> newBuilderUsing(
- TestSortedMapGenerator<K, V> delegate, Bound to, Bound from) {
- return using(new NavigableMapSubmapTestMapGenerator<K, V>(delegate, to, from));
+ /**
+ * Two bounds (from and to) define how to build a subMap.
+ */
+ enum Bound {
+ INCLUSIVE,
+ EXCLUSIVE,
+ NO_BOUND;
+ }
+
+ /**
+ * Creates a suite whose map has some elements filtered out of view.
+ *
+ * <p>Because the map may be ascending or descending, this test must derive
+ * the relative order of these extreme values rather than relying on their
+ * regular sort ordering.
+ */
+ private TestSuite createSubmapSuite(final FeatureSpecificTestSuiteBuilder<?,
+ ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
+ parentBuilder, final Bound from, final Bound to) {
+ final TestMapGenerator<K, V> delegate
+ = (TestMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();
+
+ List<Feature<?>> features = new ArrayList<Feature<?>>();
+ features.add(NoRecurse.SUBMAP);
+ features.addAll(parentBuilder.getFeatures());
+
+ NavigableMap<K, V> emptyMap = (NavigableMap<K, V>) delegate.create();
+ final Comparator<Entry<K, V>> entryComparator = Helpers.entryComparator(emptyMap.comparator());
+
+ // derive values for inclusive filtering from the input samples
+ SampleElements<Entry<K, V>> samples = delegate.samples();
+ @SuppressWarnings("unchecked") // no elements are inserted into the array
+ List<Entry<K, V>> samplesList = Arrays.asList(
+ samples.e0, samples.e1, samples.e2, samples.e3, samples.e4);
+ Collections.sort(samplesList, entryComparator);
+ final K firstInclusive = samplesList.get(0).getKey();
+ final K lastInclusive = samplesList.get(samplesList.size() - 1).getKey();
+
+ return NavigableMapTestSuiteBuilder
+ .using(new ForwardingTestMapGenerator<K, V>(delegate) {
+ @Override public Map<K, V> create(Object... entries) {
+ @SuppressWarnings("unchecked") // we dangerously assume K and V are both strings
+ List<Entry<K, V>> extremeValues = (List) getExtremeValues();
+ @SuppressWarnings("unchecked") // map generators must past entry objects
+ List<Entry<K, V>> normalValues = (List) Arrays.asList(entries);
+
+ // prepare extreme values to be filtered out of view
+ Collections.sort(extremeValues, entryComparator);
+ K firstExclusive = extremeValues.get(1).getKey();
+ K lastExclusive = extremeValues.get(2).getKey();
+ if (from == Bound.NO_BOUND) {
+ extremeValues.remove(0);
+ extremeValues.remove(0);
+ }
+ if (to == Bound.NO_BOUND) {
+ extremeValues.remove(extremeValues.size() - 1);
+ extremeValues.remove(extremeValues.size() - 1);
+ }
+
+ // the regular values should be visible after filtering
+ List<Entry<K, V>> allEntries = new ArrayList<Entry<K, V>>();
+ allEntries.addAll(extremeValues);
+ allEntries.addAll(normalValues);
+ NavigableMap<K, V> map = (NavigableMap<K, V>)
+ delegate.create((Object[])
+ allEntries.toArray(new Entry[allEntries.size()]));
+
+ // call the smallest subMap overload that filters out the extreme values
+ if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) {
+ return map.headMap(lastExclusive);
+ } else if (from == Bound.NO_BOUND && to == Bound.INCLUSIVE) {
+ return map.headMap(lastInclusive, true);
+ } else if (from == Bound.EXCLUSIVE && to == Bound.NO_BOUND) {
+ return map.tailMap(firstExclusive, false);
+ } else if (from == Bound.EXCLUSIVE && to == Bound.EXCLUSIVE) {
+ return map.subMap(firstExclusive, false, lastExclusive, false);
+ } else if (from == Bound.EXCLUSIVE && to == Bound.INCLUSIVE) {
+ return map.subMap(firstExclusive, false, lastInclusive, true);
+ } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) {
+ return map.tailMap(firstInclusive);
+ } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) {
+ return map.subMap(firstInclusive, lastExclusive);
+ } else if (from == Bound.INCLUSIVE && to == Bound.INCLUSIVE) {
+ return map.subMap(firstInclusive, true, lastInclusive, true);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+ })
+ .named(parentBuilder.getName() + " subMap " + from + "-" + to)
+ .withFeatures(features)
+ .suppressing(parentBuilder.getSuppressedTests())
+ .createTestSuite();
+ }
+
+ /**
+ * Returns an array of four bogus elements that will always be too high or
+ * too low for the display. This includes two values for each extreme.
+ *
+ * <p>This method (dangerously) assume that the strings {@code "!! a"} and
+ * {@code "~~ z"} will work for this purpose, which may cause problems for
+ * navigable maps with non-string or unicode generators.
+ */
+ private List<Entry<String, String>> getExtremeValues() {
+ List<Entry<String, String>> result = new ArrayList<Entry<String, String>>();
+ result.add(Helpers.mapEntry("!! a", "below view"));
+ result.add(Helpers.mapEntry("!! b", "below view"));
+ result.add(Helpers.mapEntry("~~ y", "above view"));
+ result.add(Helpers.mapEntry("~~ z", "above view"));
+ return result;
}
/**
@@ -127,13 +220,6 @@ public class NavigableMapTestSuiteBuilder<K, V> extends SortedMapTestSuiteBuilde
NavigableMap<K, V> map = (NavigableMap<K, V>) delegate.create(entries);
return map.descendingMap();
}
-
- @Override
- public Iterable<Entry<K, V>> order(List<Entry<K, V>> insertionOrder) {
- insertionOrder = castOrCopyToList(delegate.order(insertionOrder));
- reverse(insertionOrder);
- return insertionOrder;
- }
})
.named(parentBuilder.getName() + " descending")
.withFeatures(features)
diff --git a/guava-testlib/src/com/google/common/collect/testing/NavigableSetTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/NavigableSetTestSuiteBuilder.java
index 7ef68bb..3e0f8b9 100644
--- a/guava-testlib/src/com/google/common/collect/testing/NavigableSetTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/NavigableSetTestSuiteBuilder.java
@@ -16,7 +16,7 @@
package com.google.common.collect.testing;
-import com.google.common.collect.testing.testers.NavigableSetNavigationTester;
+import com.google.common.collect.testing.testers.SetNavigationTester;
import java.util.List;
@@ -25,7 +25,7 @@ import java.util.List;
* a NavigableSet implementation.
*/
public final class NavigableSetTestSuiteBuilder<E>
- extends SortedSetTestSuiteBuilder<E> {
+ extends SetTestSuiteBuilder<E> {
public static <E> NavigableSetTestSuiteBuilder<E> using(
TestSetGenerator<E> generator) {
NavigableSetTestSuiteBuilder<E> builder =
@@ -37,7 +37,7 @@ public final class NavigableSetTestSuiteBuilder<E>
@Override protected List<Class<? extends AbstractTester>> getTesters() {
List<Class<? extends AbstractTester>> testers =
Helpers.copyToList(super.getTesters());
- testers.add(NavigableSetNavigationTester.class);
+ testers.add(SetNavigationTester.class);
return testers;
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/OneSizeGenerator.java b/guava-testlib/src/com/google/common/collect/testing/OneSizeGenerator.java
index a5d9fbc..7d3a50b 100644
--- a/guava-testlib/src/com/google/common/collect/testing/OneSizeGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/OneSizeGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.features.CollectionSize;
import java.util.ArrayList;
@@ -31,7 +30,6 @@ import java.util.List;
*
* @author George van den Driessche
*/
-@GwtCompatible
public final class OneSizeGenerator<T, E>
implements OneSizeTestContainerGenerator<T, E> {
private final TestContainerGenerator<T, E> generator;
diff --git a/guava-testlib/src/com/google/common/collect/testing/OneSizeTestContainerGenerator.java b/guava-testlib/src/com/google/common/collect/testing/OneSizeTestContainerGenerator.java
index c3350dc..5296be6 100644
--- a/guava-testlib/src/com/google/common/collect/testing/OneSizeTestContainerGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/OneSizeTestContainerGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.features.CollectionSize;
import java.util.Collection;
@@ -33,7 +32,6 @@ import java.util.Collection;
*
* @author George van den Driessche
*/
-@GwtCompatible
public interface OneSizeTestContainerGenerator<T, E>
extends TestSubjectGenerator<T>, TestContainerGenerator<T, E> {
TestContainerGenerator<T, E> getInnerGenerator();
diff --git a/guava-testlib/src/com/google/common/collect/testing/PerCollectionSizeTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/PerCollectionSizeTestSuiteBuilder.java
index ef3f384..8c219e8 100644
--- a/guava-testlib/src/com/google/common/collect/testing/PerCollectionSizeTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/PerCollectionSizeTestSuiteBuilder.java
@@ -115,7 +115,7 @@ public abstract class PerCollectionSizeTestSuiteBuilder<
return suite;
}
- protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<
+ List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<
?, ? extends OneSizeTestContainerGenerator<T, E>> parentBuilder) {
return new ArrayList<TestSuite>();
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/Platform.java b/guava-testlib/src/com/google/common/collect/testing/Platform.java
index 78d14af..e7ac3ea 100644
--- a/guava-testlib/src/com/google/common/collect/testing/Platform.java
+++ b/guava-testlib/src/com/google/common/collect/testing/Platform.java
@@ -16,7 +16,7 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
+import java.lang.reflect.Method;
/**
* Methods factored out so that they can be emulated differently in GWT.
@@ -25,7 +25,6 @@ import com.google.common.annotations.GwtCompatible;
*
* @author Hayward Chan
*/
-@GwtCompatible
class Platform {
/**
@@ -51,6 +50,31 @@ class Platform {
return String.format(template, args);
}
+ /**
+ * Wrapper around {@link System#arraycopy} so that it can be emulated
+ * correctly in GWT.
+ *
+ * <p>It is only intended for the case {@code src} and {@code dest} are
+ * different. It also doesn't validate the types and indices.
+ *
+ * <p>As of GWT 2.0, The built-in {@link System#arraycopy} doesn't work
+ * in general case. See
+ * http://code.google.com/p/google-web-toolkit/issues/detail?id=3621
+ * for more details.
+ */
+ static void unsafeArrayCopy(
+ Object[] src, int srcPos, Object[] dest, int destPos, int length) {
+ System.arraycopy(src, srcPos, dest, destPos, length);
+ }
+
+ static Method getMethod(Class<?> clazz, String name) {
+ try {
+ return clazz.getMethod(name);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
static String classGetSimpleName(Class<?> clazz) {
return clazz.getSimpleName();
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/SampleElements.java b/guava-testlib/src/com/google/common/collect/testing/SampleElements.java
index 30ddf65..2674dbb 100644
--- a/guava-testlib/src/com/google/common/collect/testing/SampleElements.java
+++ b/guava-testlib/src/com/google/common/collect/testing/SampleElements.java
@@ -16,10 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
-import java.util.Arrays;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -29,8 +25,7 @@ import java.util.Map;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
-public class SampleElements<E> implements Iterable<E> {
+public class SampleElements<E> {
// TODO: rename e3, e4 => missing1, missing2
public final E e0;
public final E e1;
@@ -46,11 +41,6 @@ public class SampleElements<E> implements Iterable<E> {
this.e4 = e4;
}
- @Override
- public Iterator<E> iterator() {
- return Arrays.asList(e0, e1, e2, e3, e4).iterator();
- }
-
public static class Strings extends SampleElements<String> {
public Strings() {
// elements aren't sorted, to better test SortedSet iteration ordering
@@ -65,13 +55,6 @@ public class SampleElements<E> implements Iterable<E> {
public static final String AFTER_LAST_2 = "zz";
}
- public static class Chars extends SampleElements<Character> {
- public Chars() {
- // elements aren't sorted, to better test SortedSet iteration ordering
- super('b', 'a', 'c', 'd', 'e');
- }
- }
-
public static class Enums extends SampleElements<AnEnum> {
public Enums() {
// elements aren't sorted, to better test SortedSet iteration ordering
@@ -79,13 +62,6 @@ public class SampleElements<E> implements Iterable<E> {
}
}
- public static class Ints extends SampleElements<Integer> {
- public Ints() {
- // elements aren't sorted, to better test SortedSet iteration ordering
- super(1, 0, 2, 3, 4);
- }
- }
-
public static <K, V> SampleElements<Map.Entry<K, V>> mapEntries(
SampleElements<K> keys, SampleElements<V> values) {
return new SampleElements<Map.Entry<K, V>>(
diff --git a/guava-testlib/src/com/google/common/collect/testing/SetTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/SetTestSuiteBuilder.java
index 7437760..5440d72 100644
--- a/guava-testlib/src/com/google/common/collect/testing/SetTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/SetTestSuiteBuilder.java
@@ -16,24 +16,14 @@
package com.google.common.collect.testing;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.testers.CollectionSerializationEqualTester;
import com.google.common.collect.testing.testers.SetAddAllTester;
import com.google.common.collect.testing.testers.SetAddTester;
import com.google.common.collect.testing.testers.SetCreationTester;
import com.google.common.collect.testing.testers.SetEqualsTester;
import com.google.common.collect.testing.testers.SetHashCodeTester;
import com.google.common.collect.testing.testers.SetRemoveTester;
-import com.google.common.testing.SerializableTester;
-import junit.framework.TestSuite;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
/**
* Creates, based on your criteria, a JUnit test suite that exhaustively tests
@@ -51,8 +41,7 @@ public class SetTestSuiteBuilder<E>
@Override protected List<Class<? extends AbstractTester>> getTesters() {
List<Class<? extends AbstractTester>> testers
= Helpers.copyToList(super.getTesters());
-
- testers.add(CollectionSerializationEqualTester.class);
+
testers.add(SetAddAllTester.class);
testers.add(SetAddTester.class);
testers.add(SetCreationTester.class);
@@ -64,61 +53,4 @@ public class SetTestSuiteBuilder<E>
// covered by CollectionRemoveAllTester.
return testers;
}
-
- @Override
- protected
- List<TestSuite>
- createDerivedSuites(
- FeatureSpecificTestSuiteBuilder<
- ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>> parentBuilder) {
- List<TestSuite> derivedSuites = new ArrayList<TestSuite>(
- super.createDerivedSuites(parentBuilder));
-
- if (parentBuilder.getFeatures().contains(CollectionFeature.SERIALIZABLE)) {
- derivedSuites.add(SetTestSuiteBuilder
- .using(new ReserializedSetGenerator<E>(parentBuilder.getSubjectGenerator()))
- .named(getName() + " reserialized")
- .withFeatures(computeReserializedCollectionFeatures(parentBuilder.getFeatures()))
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
- }
- return derivedSuites;
- }
-
- static class ReserializedSetGenerator<E> implements TestSetGenerator<E>{
- final OneSizeTestContainerGenerator<Collection<E>, E> gen;
-
- private ReserializedSetGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
- this.gen = gen;
- }
-
- @Override
- public SampleElements<E> samples() {
- return gen.samples();
- }
-
- @Override
- public Set<E> create(Object... elements) {
- return (Set<E>) SerializableTester.reserialize(gen.create(elements));
- }
-
- @Override
- public E[] createArray(int length) {
- return gen.createArray(length);
- }
-
- @Override
- public Iterable<E> order(List<E> insertionOrder) {
- return gen.order(insertionOrder);
- }
- }
-
- private static Set<Feature<?>> computeReserializedCollectionFeatures(
- Set<Feature<?>> features) {
- Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
- derivedFeatures.addAll(features);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);
- return derivedFeatures;
- }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/SortedMapInterfaceTest.java b/guava-testlib/src/com/google/common/collect/testing/SortedMapInterfaceTest.java
index 10e5d1b..fdf6632 100644
--- a/guava-testlib/src/com/google/common/collect/testing/SortedMapInterfaceTest.java
+++ b/guava-testlib/src/com/google/common/collect/testing/SortedMapInterfaceTest.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -40,7 +38,6 @@ import java.util.SortedMap;
* @author Jared Levy
*/
// TODO: Use this class to test classes besides ImmutableSortedMap.
-@GwtCompatible
public abstract class SortedMapInterfaceTest<K, V>
extends MapInterfaceTest<K, V> {
diff --git a/guava-testlib/src/com/google/common/collect/testing/SortedMapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/SortedMapTestSuiteBuilder.java
deleted file mode 100644
index 11774ef..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/SortedMapTestSuiteBuilder.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (C) 2010 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import com.google.common.collect.testing.DerivedCollectionGenerators.Bound;
-import com.google.common.collect.testing.DerivedCollectionGenerators.SortedMapSubmapTestMapGenerator;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.testers.SortedMapNavigationTester;
-
-import junit.framework.TestSuite;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.SortedSet;
-
-/**
- * Creates, based on your criteria, a JUnit test suite that exhaustively tests
- * a SortedMap implementation.
- */
-public class SortedMapTestSuiteBuilder<K, V> extends MapTestSuiteBuilder<K, V> {
- public static <K, V> SortedMapTestSuiteBuilder<K, V> using(
- TestSortedMapGenerator<K, V> generator) {
- SortedMapTestSuiteBuilder<K, V> result = new SortedMapTestSuiteBuilder<K, V>();
- result.usingGenerator(generator);
- return result;
- }
-
- @Override protected List<Class<? extends AbstractTester>> getTesters() {
- List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
- testers.add(SortedMapNavigationTester.class);
- return testers;
- }
-
- @Override public TestSuite createTestSuite() {
- if (!getFeatures().contains(CollectionFeature.KNOWN_ORDER)) {
- List<Feature<?>> features = Helpers.copyToList(getFeatures());
- features.add(CollectionFeature.KNOWN_ORDER);
- withFeatures(features);
- }
- return super.createTestSuite();
- }
-
- @Override
- protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?,
- ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>> parentBuilder) {
- List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
-
- if (!parentBuilder.getFeatures().contains(NoRecurse.SUBMAP)) {
- derivedSuites.add(createSubmapSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE));
- derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.NO_BOUND));
- derivedSuites.add(createSubmapSuite(parentBuilder, Bound.INCLUSIVE, Bound.EXCLUSIVE));
- }
-
- return derivedSuites;
- }
-
- @Override protected SetTestSuiteBuilder<K> createDerivedKeySetSuite(
- TestSetGenerator<K> keySetGenerator) {
- /*
- * TODO(cpovirk): Consider requiring a SortedSet by default and requiring tests of a given
- * implementation to opt out if they wish to return Set. This would encourage us to return
- * keySets that implement SortedSet
- */
- return (keySetGenerator.create() instanceof SortedSet)
- ? SortedSetTestSuiteBuilder.using(keySetGenerator)
- : SetTestSuiteBuilder.using(keySetGenerator);
- }
-
- /**
- * To avoid infinite recursion, test suites with these marker features won't
- * have derived suites created for them.
- */
- enum NoRecurse implements Feature<Void> {
- SUBMAP,
- DESCENDING;
-
- @Override
- public Set<Feature<? super Void>> getImpliedFeatures() {
- return Collections.emptySet();
- }
- }
-
- /**
- * Creates a suite whose map has some elements filtered out of view.
- *
- * <p>Because the map may be ascending or descending, this test must derive
- * the relative order of these extreme values rather than relying on their
- * regular sort ordering.
- */
- final TestSuite createSubmapSuite(final FeatureSpecificTestSuiteBuilder<?,
- ? extends OneSizeTestContainerGenerator<Map<K, V>, Entry<K, V>>>
- parentBuilder, final Bound from, final Bound to) {
- final TestSortedMapGenerator<K, V> delegate
- = (TestSortedMapGenerator<K, V>) parentBuilder.getSubjectGenerator().getInnerGenerator();
-
- List<Feature<?>> features = new ArrayList<Feature<?>>();
- features.add(NoRecurse.SUBMAP);
- features.addAll(parentBuilder.getFeatures());
-
- return newBuilderUsing(delegate, to, from)
- .named(parentBuilder.getName() + " subMap " + from + "-" + to)
- .withFeatures(features)
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- /** Like using() but overrideable by NavigableMapTestSuiteBuilder. */
- SortedMapTestSuiteBuilder<K, V> newBuilderUsing(
- TestSortedMapGenerator<K, V> delegate, Bound to, Bound from) {
- return using(new SortedMapSubmapTestMapGenerator<K, V>(delegate, to, from));
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java
deleted file mode 100644
index 2f457a1..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/SortedSetTestSuiteBuilder.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2010 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.testers.SortedSetNavigationTester;
-
-import junit.framework.TestSuite;
-
-import java.util.List;
-
-/**
- * Creates, based on your criteria, a JUnit test suite that exhaustively tests
- * a SortedSet implementation.
- */
-public class SortedSetTestSuiteBuilder<E> extends SetTestSuiteBuilder<E> {
- public static <E> SortedSetTestSuiteBuilder<E> using(
- TestSetGenerator<E> generator) {
- SortedSetTestSuiteBuilder<E> builder =
- new SortedSetTestSuiteBuilder<E>();
- builder.usingGenerator(generator);
- return builder;
- }
-
- @Override protected List<Class<? extends AbstractTester>> getTesters() {
- List<Class<? extends AbstractTester>> testers =
- Helpers.copyToList(super.getTesters());
- testers.add(SortedSetNavigationTester.class);
- return testers;
- }
-
- @Override public TestSuite createTestSuite() {
- if (!getFeatures().contains(CollectionFeature.KNOWN_ORDER)) {
- List<Feature<?>> features = Helpers.copyToList(getFeatures());
- features.add(CollectionFeature.KNOWN_ORDER);
- withFeatures(features);
- }
- return super.createTestSuite();
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestCharacterListGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestCharacterListGenerator.java
deleted file mode 100644
index 9f9befe..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/TestCharacterListGenerator.java
+++ /dev/null
@@ -1,66 +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;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.testing.SampleElements.Chars;
-
-import java.util.List;
-
-/**
- * Generates {@code List<Character>} instances for test suites.
- *
- * <p>This class is GWT compatible.
- *
- * @author Kevin Bourrillion
- * @author Louis Wasserman
- */
-@GwtCompatible
-public abstract class TestCharacterListGenerator
- implements TestListGenerator<Character> {
- @Override
- public SampleElements<Character> samples() {
- return new Chars();
- }
-
- @Override
- public List<Character> create(Object... elements) {
- Character[] array = new Character[elements.length];
- int i = 0;
- for (Object e : elements) {
- array[i++] = (Character) e;
- }
- return create(array);
- }
-
- /**
- * Creates a new collection containing the given elements; implement this
- * method instead of {@link #create(Object...)}.
- */
- protected abstract List<Character> create(Character[] elements);
-
- @Override
- public Character[] createArray(int length) {
- return new Character[length];
- }
-
- /** Returns the original element list, unchanged. */
- @Override
- public List<Character> order(List<Character> insertionOrder) {
- return insertionOrder;
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestCollectionGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestCollectionGenerator.java
index f50b695..92367a2 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestCollectionGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestCollectionGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Collection;
/**
@@ -27,7 +25,6 @@ import java.util.Collection;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public interface TestCollectionGenerator<E>
extends TestContainerGenerator<Collection<E>, E> {
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestCollidingSetGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestCollidingSetGenerator.java
index f053f4e..ed26b65 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestCollidingSetGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestCollidingSetGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.SampleElements.Colliders;
import java.util.List;
@@ -28,7 +27,6 @@ import java.util.List;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public abstract class TestCollidingSetGenerator
implements TestSetGenerator<Object> {
@Override
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestContainerGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestContainerGenerator.java
index 00d167c..1511040 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestContainerGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestContainerGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -32,7 +30,6 @@ import java.util.Map;
*
* @author George van den Driessche
*/
-@GwtCompatible
public interface TestContainerGenerator<T, E> {
/**
* Returns the sample elements that this generate populates its container
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestEnumMapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestEnumMapGenerator.java
index 579c522..42bc48a 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestEnumMapGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestEnumMapGenerator.java
@@ -16,10 +16,6 @@
package com.google.common.collect.testing;
-import static com.google.common.collect.testing.Helpers.orderEntriesByKey;
-
-import com.google.common.annotations.GwtCompatible;
-
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -31,7 +27,6 @@ import java.util.Map.Entry;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public abstract class TestEnumMapGenerator
implements TestMapGenerator<AnEnum, String> {
@@ -78,10 +73,10 @@ public abstract class TestEnumMapGenerator
return new String[length];
}
- /** Returns the elements sorted in natural order. */
+ /** Returns the original element list, unchanged. */
@Override
public Iterable<Entry<AnEnum, String>> order(
List<Entry<AnEnum, String>> insertionOrder) {
- return orderEntriesByKey(insertionOrder);
+ return insertionOrder;
}
-}
+} \ No newline at end of file
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestEnumSetGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestEnumSetGenerator.java
index f4b9c80..fd7155c 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestEnumSetGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestEnumSetGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.SampleElements.Enums;
import java.util.Collections;
@@ -30,7 +29,6 @@ import java.util.Set;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public abstract class TestEnumSetGenerator implements TestSetGenerator<AnEnum> {
@Override
public SampleElements<AnEnum> samples() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestIntegerSetGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestIntegerSetGenerator.java
deleted file mode 100644
index 7e11e3a..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/TestIntegerSetGenerator.java
+++ /dev/null
@@ -1,68 +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;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.testing.SampleElements.Ints;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * Create integer sets for collection tests.
- *
- * <p>This class is GWT compatible.
- *
- * @author Gregory Kick
- */
-@GwtCompatible
-public abstract class TestIntegerSetGenerator implements TestSetGenerator<Integer> {
- @Override public SampleElements<Integer> samples() {
- return new Ints();
- }
-
- @Override public Set<Integer> create(Object... elements) {
- Integer[] array = new Integer[elements.length];
- int i = 0;
- for (Object e : elements) {
- array[i++] = (Integer) e;
- }
- return create(array);
- }
-
- protected abstract Set<Integer> create(Integer[] elements);
-
- @Override public Integer[] createArray(int length) {
- return new Integer[length];
- }
-
- /**
- * {@inheritDoc}
- *
- * <p>By default, returns the supplied elements in their given order; however,
- * generators for containers with a known order other than insertion order
- * must override this method.
- *
- * <p>Note: This default implementation is overkill (but valid) for an
- * unordered container. An equally valid implementation for an unordered
- * container is to throw an exception. The chosen implementation, however, has
- * the advantage of working for insertion-ordered containers, as well.
- */
- @Override public List<Integer> order(List<Integer> insertionOrder) {
- return insertionOrder;
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestIntegerSortedSetGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestIntegerSortedSetGenerator.java
deleted file mode 100644
index 8e577e8..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/TestIntegerSortedSetGenerator.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import com.google.common.annotations.GwtCompatible;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.SortedSet;
-
-/**
- * Create integer sets for testing collections that are sorted by natural
- * ordering.
- *
- * <p>This class is GWT compatible.
- *
- * @author Chris Povirk
- * @author Jared Levy
- */
-@GwtCompatible
-public abstract class TestIntegerSortedSetGenerator
- extends TestIntegerSetGenerator {
- @Override protected abstract SortedSet<Integer> create(Integer[] elements);
-
- /** Sorts the elements by their natural ordering. */
- @Override public List<Integer> order(List<Integer> insertionOrder) {
- Collections.sort(insertionOrder);
- return insertionOrder;
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestIteratorGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestIteratorGenerator.java
index 8304364..1c718c5 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestIteratorGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestIteratorGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Iterator;
/**
@@ -29,7 +27,6 @@ import java.util.Iterator;
*
* @author George van den Driessche
*/
-@GwtCompatible
public interface TestIteratorGenerator<E> {
Iterator<E> get();
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestListGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestListGenerator.java
index 2027ce4..11e2604 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestListGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestListGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.List;
/**
@@ -27,7 +25,6 @@ import java.util.List;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public interface TestListGenerator<E> extends TestCollectionGenerator<E> {
@Override
List<E> create(Object... elements);
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestMapEntrySetGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestMapEntrySetGenerator.java
index c57f7ac..e1a9611 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestMapEntrySetGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestMapEntrySetGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -29,7 +27,6 @@ import java.util.Set;
*
* @author Jesse Wilson
*/
-@GwtCompatible
public abstract class TestMapEntrySetGenerator<K, V>
implements TestSetGenerator<Map.Entry<K, V>> {
private final SampleElements<K> keys;
@@ -49,7 +46,7 @@ public abstract class TestMapEntrySetGenerator<K, V>
@Override
public Set<Map.Entry<K, V>> create(Object... elements) {
Map.Entry<K, V>[] entries = createArray(elements.length);
- System.arraycopy(elements, 0, entries, 0, elements.length);
+ Platform.unsafeArrayCopy(elements, 0, entries, 0, elements.length);
return createFromEntries(entries);
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestMapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestMapGenerator.java
index 2d18e06..e7add5a 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestMapGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestMapGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Map;
/**
@@ -27,7 +25,6 @@ import java.util.Map;
*
* @author George van den Driessche
*/
-@GwtCompatible
public interface TestMapGenerator<K, V>
extends TestContainerGenerator<Map<K, V>, Map.Entry<K, V>> {
K[] createKeyArray(int length);
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestQueueGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestQueueGenerator.java
index 5bb3188..f8d8dc6 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestQueueGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestQueueGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Queue;
/**
@@ -27,7 +25,6 @@ import java.util.Queue;
*
* @author Jared Levy
*/
-@GwtCompatible
public interface TestQueueGenerator<E> extends TestCollectionGenerator<E> {
@Override
Queue<E> create(Object... elements);
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestSetGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestSetGenerator.java
index 2586f70..106112b 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestSetGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestSetGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Set;
/**
@@ -27,7 +25,6 @@ import java.util.Set;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public interface TestSetGenerator<E> extends TestCollectionGenerator<E> {
@Override
Set<E> create(Object... elements);
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestSortedMapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestSortedMapGenerator.java
deleted file mode 100644
index 9a9ab73..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/TestSortedMapGenerator.java
+++ /dev/null
@@ -1,59 +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;
-
-import com.google.common.annotations.GwtCompatible;
-
-import java.util.Map;
-import java.util.SortedMap;
-
-/**
- * Creates sorted maps, containing sample elements, to be tested.
- *
- * <p>This class is GWT compatible.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public interface TestSortedMapGenerator<K, V> extends TestMapGenerator<K, V> {
- @Override
- SortedMap<K, V> create(Object... elements);
-
- /**
- * Returns an entry with a key less than the keys of the {@link #samples()}
- * and less than the key of {@link #belowSamplesGreater()}.
- */
- Map.Entry<K, V> belowSamplesLesser();
-
- /**
- * Returns an entry with a key less than the keys of the {@link #samples()}
- * but greater than the key of {@link #belowSamplesLesser()}.
- */
- Map.Entry<K, V> belowSamplesGreater();
-
- /**
- * Returns an entry with a key greater than the keys of the {@link #samples()}
- * but less than the key of {@link #aboveSamplesGreater()}.
- */
- Map.Entry<K, V> aboveSamplesLesser();
-
- /**
- * Returns an entry with a key greater than the keys of the {@link #samples()}
- * and greater than the key of {@link #aboveSamplesLesser()}.
- */
- Map.Entry<K, V> aboveSamplesGreater();
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestStringCollectionGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestStringCollectionGenerator.java
index fa4b8f6..2248853 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestStringCollectionGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestStringCollectionGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.SampleElements.Strings;
import java.util.Collection;
@@ -29,7 +28,6 @@ import java.util.List;
*
* @author Jared Levy
*/
-@GwtCompatible
public abstract class TestStringCollectionGenerator
implements TestCollectionGenerator<String> {
@Override
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestStringListGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestStringListGenerator.java
index 842d653..ea024ad 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestStringListGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestStringListGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.SampleElements.Strings;
import java.util.List;
@@ -28,7 +27,6 @@ import java.util.List;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public abstract class TestStringListGenerator
implements TestListGenerator<String> {
@Override
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestStringMapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestStringMapGenerator.java
index 9505c8e..2f9b51b 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestStringMapGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestStringMapGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -32,7 +30,6 @@ import java.util.Map.Entry;
* @author Jared Levy
* @author George van den Driessche
*/
-@GwtCompatible
public abstract class TestStringMapGenerator
implements TestMapGenerator<String, String> {
@@ -48,7 +45,7 @@ public abstract class TestStringMapGenerator
}
@Override
- public Map<String, String> create(Object... entries) {
+ public final Map<String, String> create(Object... entries) {
@SuppressWarnings("unchecked")
Entry<String, String>[] array = new Entry[entries.length];
int i = 0;
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestStringQueueGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestStringQueueGenerator.java
index d2ba7ce..d116044 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestStringQueueGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestStringQueueGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.SampleElements.Strings;
import java.util.List;
@@ -29,7 +28,6 @@ import java.util.Queue;
*
* @author Jared Levy
*/
-@GwtCompatible
public abstract class TestStringQueueGenerator
implements TestQueueGenerator<String>
{
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestStringSetGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestStringSetGenerator.java
index 339a79e..712b533 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestStringSetGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestStringSetGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.SampleElements.Strings;
import java.util.List;
@@ -29,7 +28,6 @@ import java.util.Set;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public abstract class TestStringSetGenerator implements TestSetGenerator<String>
{
@Override
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestStringSortedMapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestStringSortedMapGenerator.java
deleted file mode 100644
index 6c357e6..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/TestStringSortedMapGenerator.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2008 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing;
-
-import static com.google.common.collect.testing.Helpers.orderEntriesByKey;
-
-import com.google.common.annotations.GwtCompatible;
-
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.SortedMap;
-
-/**
- * Implementation helper for {@link TestMapGenerator} for use with sorted maps of strings.
- *
- * <p>This class is GWT compatible.
- *
- * @author Chris Povirk
- */
-@GwtCompatible
-public abstract class TestStringSortedMapGenerator extends TestStringMapGenerator
- implements TestSortedMapGenerator<String, String> {
- @Override
- public Entry<String, String> belowSamplesLesser() {
- return Helpers.mapEntry("!! a", "below view");
- }
-
- @Override
- public Entry<String, String> belowSamplesGreater() {
- return Helpers.mapEntry("!! b", "below view");
- }
-
- @Override
- public Entry<String, String> aboveSamplesLesser() {
- return Helpers.mapEntry("~~ a", "above view");
- }
-
- @Override
- public Entry<String, String> aboveSamplesGreater() {
- return Helpers.mapEntry("~~ b", "above view");
- }
-
- @Override
- public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
- return orderEntriesByKey(insertionOrder);
- }
-
- @Override
- protected abstract SortedMap<String, String> create(Entry<String, String>[] entries);
-
- @Override
- public SortedMap<String, String> create(Object... entries) {
- return (SortedMap<String, String>) super.create(entries);
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestStringSortedSetGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestStringSortedSetGenerator.java
index c2e7cc0..833ffe9 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestStringSortedSetGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestStringSortedSetGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Collections;
import java.util.List;
import java.util.SortedSet;
@@ -30,7 +28,6 @@ import java.util.SortedSet;
*
* @author Jared Levy
*/
-@GwtCompatible
public abstract class TestStringSortedSetGenerator
extends TestStringSetGenerator {
@Override protected abstract SortedSet<String> create(String[] elements);
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestSubjectGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestSubjectGenerator.java
index 3b968e5..fa8970d 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestSubjectGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestSubjectGenerator.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
/**
* To be implemented by test generators that can produce test subjects without
* requiring any parameters.
@@ -28,7 +26,6 @@ import com.google.common.annotations.GwtCompatible;
*
* @author George van den Driessche
*/
-@GwtCompatible
public interface TestSubjectGenerator<T> {
T createTestSubject();
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestUnhashableCollectionGenerator.java b/guava-testlib/src/com/google/common/collect/testing/TestUnhashableCollectionGenerator.java
index 92020c9..3010b47 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestUnhashableCollectionGenerator.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestUnhashableCollectionGenerator.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.SampleElements.Unhashables;
import java.util.Collection;
@@ -29,7 +28,6 @@ import java.util.List;
*
* @author Regina O'Dell
*/
-@GwtCompatible
public abstract class
TestUnhashableCollectionGenerator<T extends Collection<UnhashableObject>>
implements TestCollectionGenerator<UnhashableObject> {
@@ -64,4 +62,4 @@ public abstract class
List<UnhashableObject> insertionOrder) {
return insertionOrder;
}
-}
+} \ No newline at end of file
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java b/guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java
index 8191d70..c9961f3 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestsForListsInJavaUtil.java
@@ -102,7 +102,7 @@ public class TestsForListsInJavaUtil {
})
.named("emptyList")
.withFeatures(
- CollectionFeature.SERIALIZABLE,
+ CollectionFeature.NONE,
CollectionSize.ZERO)
.suppressing(suppressForEmptyList())
.createTestSuite();
@@ -117,7 +117,7 @@ public class TestsForListsInJavaUtil {
})
.named("singletonList")
.withFeatures(
- CollectionFeature.SERIALIZABLE,
+ CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionSize.ONE)
.suppressing(suppressForSingletonList())
@@ -134,7 +134,6 @@ public class TestsForListsInJavaUtil {
.named("Arrays.asList")
.withFeatures(
ListFeature.SUPPORTS_SET,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionSize.ANY)
.suppressing(suppressForArraysAsList())
@@ -151,9 +150,7 @@ public class TestsForListsInJavaUtil {
.named("ArrayList")
.withFeatures(
ListFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
- CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionSize.ANY)
.suppressing(suppressForArrayList())
.createTestSuite();
@@ -169,9 +166,7 @@ public class TestsForListsInJavaUtil {
.named("LinkedList")
.withFeatures(
ListFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
- CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionSize.ANY)
.suppressing(suppressForLinkedList())
.createTestSuite();
@@ -188,7 +183,6 @@ public class TestsForListsInJavaUtil {
.named("CopyOnWriteArrayList")
.withFeatures(
ListFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionSize.ANY)
.suppressing(suppressForCopyOnWriteArrayList())
@@ -206,7 +200,7 @@ public class TestsForListsInJavaUtil {
})
.named("unmodifiableList/ArrayList")
.withFeatures(
- CollectionFeature.SERIALIZABLE,
+ CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionSize.ANY)
.suppressing(suppressForUnmodifiableList())
@@ -225,7 +219,6 @@ public class TestsForListsInJavaUtil {
.named("checkedList/ArrayList")
.withFeatures(
ListFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.RESTRICTS_ELEMENTS,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionSize.ANY)
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java b/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java
index fa996b3..6b71f22 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestsForMapsInJavaUtil.java
@@ -23,7 +23,6 @@ import com.google.common.collect.testing.features.MapFeature;
import junit.framework.Test;
import junit.framework.TestSuite;
-import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
@@ -31,12 +30,11 @@ import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentSkipListMap;
/**
* Generates a test suite covering the {@link Map} implementations in the
@@ -46,7 +44,6 @@ import java.util.concurrent.ConcurrentSkipListMap;
* @author Kevin Bourrillion
*/
public class TestsForMapsInJavaUtil {
-
public static Test suite() {
return new TestsForMapsInJavaUtil().allTests();
}
@@ -57,12 +54,9 @@ public class TestsForMapsInJavaUtil {
suite.addTest(testsForSingletonMap());
suite.addTest(testsForHashMap());
suite.addTest(testsForLinkedHashMap());
- suite.addTest(testsForTreeMapNatural());
- suite.addTest(testsForTreeMapWithComparator());
+ suite.addTest(testsForTreeMap());
suite.addTest(testsForEnumMap());
suite.addTest(testsForConcurrentHashMap());
- suite.addTest(testsForConcurrentSkipListMapNatural());
- suite.addTest(testsForConcurrentSkipListMapWithComparator());
return suite;
}
@@ -78,10 +72,7 @@ public class TestsForMapsInJavaUtil {
protected Collection<Method> suppressForLinkedHashMap() {
return Collections.emptySet();
}
- protected Collection<Method> suppressForTreeMapNatural() {
- return Collections.emptySet();
- }
- protected Collection<Method> suppressForTreeMapWithComparator() {
+ protected Collection<Method> suppressForTreeMap() {
return Collections.emptySet();
}
protected Collection<Method> suppressForEnumMap() {
@@ -90,9 +81,6 @@ public class TestsForMapsInJavaUtil {
protected Collection<Method> suppressForConcurrentHashMap() {
return Collections.emptySet();
}
- protected Collection<Method> suppressForConcurrentSkipListMap() {
- return Collections.emptySet();
- }
public Test testsForEmptyMap() {
return MapTestSuiteBuilder
@@ -104,7 +92,7 @@ public class TestsForMapsInJavaUtil {
})
.named("emptyMap")
.withFeatures(
- CollectionFeature.SERIALIZABLE,
+ CollectionFeature.NONE,
CollectionSize.ZERO)
.suppressing(suppressForEmptyMap())
.createTestSuite();
@@ -123,7 +111,6 @@ public class TestsForMapsInJavaUtil {
.withFeatures(
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ONE)
.suppressing(suppressForSingletonMap())
.createTestSuite();
@@ -136,14 +123,20 @@ public class TestsForMapsInJavaUtil {
Entry<String, String>[] entries) {
return toHashMap(entries);
}
+ @Override public Iterable<Entry<String, String>> order(
+ List<Entry<String, String>> insertionOrder) {
+ /*
+ * For convenience, make this test double as a test that no tester
+ * calls order() on a container without the KNOWN_ORDER feature.
+ */
+ throw new UnsupportedOperationException();
+ }
})
.named("HashMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForHashMap())
.createTestSuite();
@@ -162,57 +155,29 @@ public class TestsForMapsInJavaUtil {
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForLinkedHashMap())
.createTestSuite();
}
- public Test testsForTreeMapNatural() {
+ public Test testsForTreeMap() {
return NavigableMapTestSuiteBuilder
- .using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
- Entry<String, String>[] entries) {
- /*
- * TODO(cpovirk): it would be nice to create an input Map and use
- * the copy constructor here and in the other tests
- */
- return populate(new TreeMap<String, String>(), entries);
- }
- })
- .named("TreeMap, natural")
- .withFeatures(
- MapFeature.GENERAL_PURPOSE,
- MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
- CollectionSize.ANY)
- .suppressing(suppressForTreeMapNatural())
- .createTestSuite();
- }
-
- public Test testsForTreeMapWithComparator() {
- return NavigableMapTestSuiteBuilder
- .using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
+ .using(new TestStringMapGenerator() {
+ @Override protected Map<String, String> create(
Entry<String, String>[] entries) {
return populate(new TreeMap<String, String>(
arbitraryNullFriendlyComparator()), entries);
}
})
- .named("TreeMap, with comparator")
+ .named("TreeMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
MapFeature.ALLOWS_NULL_KEYS,
MapFeature.ALLOWS_NULL_VALUES,
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
- .suppressing(suppressForTreeMapWithComparator())
+ .suppressing(suppressForTreeMap())
.createTestSuite();
}
@@ -231,7 +196,6 @@ public class TestsForMapsInJavaUtil {
MapFeature.ALLOWS_NULL_VALUES,
MapFeature.RESTRICTS_KEYS,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForEnumMap())
.createTestSuite();
@@ -248,49 +212,11 @@ public class TestsForMapsInJavaUtil {
.named("ConcurrentHashMap")
.withFeatures(
MapFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionSize.ANY)
.suppressing(suppressForConcurrentHashMap())
.createTestSuite();
}
- public Test testsForConcurrentSkipListMapNatural() {
- return NavigableMapTestSuiteBuilder
- .using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
- Entry<String, String>[] entries) {
- return populate(new ConcurrentSkipListMap<String, String>(), entries);
- }
- })
- .named("ConcurrentSkipListMap, natural")
- .withFeatures(
- MapFeature.GENERAL_PURPOSE,
- CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
- CollectionSize.ANY)
- .suppressing(suppressForConcurrentSkipListMap())
- .createTestSuite();
- }
-
- public Test testsForConcurrentSkipListMapWithComparator() {
- return NavigableMapTestSuiteBuilder
- .using(new TestStringSortedMapGenerator() {
- @Override protected SortedMap<String, String> create(
- Entry<String, String>[] entries) {
- return populate(new ConcurrentSkipListMap<String, String>(
- arbitraryNullFriendlyComparator()), entries);
- }
- })
- .named("ConcurrentSkipListMap, with comparator")
- .withFeatures(
- MapFeature.GENERAL_PURPOSE,
- CollectionFeature.KNOWN_ORDER,
- CollectionFeature.SERIALIZABLE,
- CollectionSize.ANY)
- .suppressing(suppressForConcurrentSkipListMap())
- .createTestSuite();
- }
-
// TODO: IdentityHashMap, AbstractMap
private static Map<String, String> toHashMap(
@@ -300,8 +226,8 @@ public class TestsForMapsInJavaUtil {
// TODO: call conversion constructors or factory methods instead of using
// populate() on an empty map
- private static <T, M extends Map<T, String>> M populate(
- M map, Entry<T, String>[] entries) {
+ private static <T> Map<T, String> populate(
+ Map<T, String> map, Entry<T, String>[] entries) {
for (Entry<T, String> entry : entries) {
map.put(entry.getKey(), entry.getValue());
}
@@ -309,13 +235,11 @@ public class TestsForMapsInJavaUtil {
}
static <T> Comparator<T> arbitraryNullFriendlyComparator() {
- return new NullFriendlyComparator<T>();
- }
-
- private static final class NullFriendlyComparator<T> implements Comparator<T>, Serializable {
- @Override
- public int compare(T left, T right) {
- return String.valueOf(left).compareTo(String.valueOf(right));
- }
+ return new Comparator<T>() {
+ @Override
+ public int compare(T left, T right) {
+ return String.valueOf(left).compareTo(String.valueOf(right));
+ }
+ };
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/TestsForSetsInJavaUtil.java b/guava-testlib/src/com/google/common/collect/testing/TestsForSetsInJavaUtil.java
index b6484ac..4b4b924 100644
--- a/guava-testlib/src/com/google/common/collect/testing/TestsForSetsInJavaUtil.java
+++ b/guava-testlib/src/com/google/common/collect/testing/TestsForSetsInJavaUtil.java
@@ -19,12 +19,10 @@ package com.google.common.collect.testing;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.SetFeature;
-import com.google.common.collect.testing.testers.CollectionIteratorTester;
import junit.framework.Test;
import junit.framework.TestSuite;
-import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.AbstractSet;
import java.util.Collection;
@@ -37,7 +35,6 @@ import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArraySet;
/**
@@ -66,8 +63,6 @@ public class TestsForSetsInJavaUtil {
suite.addTest(testsForCheckedSet());
suite.addTest(testsForAbstractSet());
suite.addTest(testsForBadlyCollidingHashSet());
- suite.addTest(testsForConcurrentSkipListSetNatural());
- suite.addTest(testsForConcurrentSkipListSetWithComparator());
return suite;
}
@@ -94,8 +89,7 @@ public class TestsForSetsInJavaUtil {
return Collections.emptySet();
}
protected Collection<Method> suppressForCopyOnWriteArraySet() {
- return Collections.singleton(CollectionIteratorTester
- .getIteratorKnownOrderRemoveSupportedMethod());
+ return Collections.emptySet();
}
protected Collection<Method> suppressForUnmodifiableSet() {
return Collections.emptySet();
@@ -106,12 +100,6 @@ public class TestsForSetsInJavaUtil {
protected Collection<Method> suppressForAbstractSet() {
return Collections.emptySet();
}
- protected Collection<Method> suppressForConcurrentSkipListSetNatural() {
- return Collections.emptySet();
- }
- protected Collection<Method> suppressForConcurrentSkipListSetWithComparator() {
- return Collections.emptySet();
- }
public Test testsForEmptySet() {
return SetTestSuiteBuilder
@@ -122,7 +110,7 @@ public class TestsForSetsInJavaUtil {
})
.named("emptySet")
.withFeatures(
- CollectionFeature.SERIALIZABLE,
+ CollectionFeature.NONE,
CollectionSize.ZERO)
.suppressing(suppressForEmptySet())
.createTestSuite();
@@ -137,7 +125,7 @@ public class TestsForSetsInJavaUtil {
})
.named("singleton")
.withFeatures(
- CollectionFeature.SERIALIZABLE,
+ CollectionFeature.NONE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionSize.ONE)
.suppressing(suppressForSingletonSet())
@@ -154,9 +142,7 @@ public class TestsForSetsInJavaUtil {
.named("HashSet")
.withFeatures(
SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
- CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionSize.ANY)
.suppressing(suppressForHashSet())
.createTestSuite();
@@ -172,10 +158,8 @@ public class TestsForSetsInJavaUtil {
.named("LinkedHashSet")
.withFeatures(
SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionSize.ANY)
.suppressing(suppressForLinkedHashSet())
.createTestSuite();
@@ -193,7 +177,6 @@ public class TestsForSetsInJavaUtil {
.named("EnumSet")
.withFeatures(
SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.KNOWN_ORDER,
CollectionFeature.RESTRICTS_ELEMENTS,
CollectionSize.ANY)
@@ -211,9 +194,7 @@ public class TestsForSetsInJavaUtil {
.named("TreeSet, natural")
.withFeatures(
SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionSize.ANY)
.suppressing(suppressForTreeSetNatural())
.createTestSuite();
@@ -232,10 +213,8 @@ public class TestsForSetsInJavaUtil {
.named("TreeSet, with comparator")
.withFeatures(
SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionFeature.KNOWN_ORDER,
- CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
CollectionSize.ANY)
.suppressing(suppressForTreeSetWithComparator())
.createTestSuite();
@@ -252,7 +231,6 @@ public class TestsForSetsInJavaUtil {
.named("CopyOnWriteArraySet")
.withFeatures(
SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionFeature.KNOWN_ORDER,
CollectionSize.ANY)
@@ -272,7 +250,6 @@ public class TestsForSetsInJavaUtil {
.named("unmodifiableSet/HashSet")
.withFeatures(
CollectionFeature.NONE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionSize.ANY)
.suppressing(suppressForUnmodifiableSet())
@@ -291,7 +268,6 @@ public class TestsForSetsInJavaUtil {
.named("checkedSet/HashSet")
.withFeatures(
SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
CollectionFeature.ALLOWS_NULL_VALUES,
CollectionFeature.RESTRICTS_ELEMENTS,
CollectionSize.ANY)
@@ -341,43 +317,6 @@ public class TestsForSetsInJavaUtil {
.createTestSuite();
}
- public Test testsForConcurrentSkipListSetNatural() {
- return SetTestSuiteBuilder
- .using(new TestStringSortedSetGenerator() {
- @Override public SortedSet<String> create(String[] elements) {
- return new ConcurrentSkipListSet<String>(MinimalCollection.of(elements));
- }
- })
- .named("ConcurrentSkipListSet, natural")
- .withFeatures(
- SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
- CollectionFeature.KNOWN_ORDER,
- CollectionSize.ANY)
- .suppressing(suppressForConcurrentSkipListSetNatural())
- .createTestSuite();
- }
-
- public Test testsForConcurrentSkipListSetWithComparator() {
- return SetTestSuiteBuilder
- .using(new TestStringSortedSetGenerator() {
- @Override public SortedSet<String> create(String[] elements) {
- SortedSet<String> set
- = new ConcurrentSkipListSet<String>(arbitraryNullFriendlyComparator());
- Collections.addAll(set, elements);
- return set;
- }
- })
- .named("ConcurrentSkipListSet, with comparator")
- .withFeatures(
- SetFeature.GENERAL_PURPOSE,
- CollectionFeature.SERIALIZABLE,
- CollectionFeature.KNOWN_ORDER,
- CollectionSize.ANY)
- .suppressing(suppressForConcurrentSkipListSetWithComparator())
- .createTestSuite();
- }
-
private static String[] dedupe(String[] elements) {
Set<String> tmp = new LinkedHashSet<String>();
Collections.addAll(tmp, elements);
@@ -385,14 +324,11 @@ public class TestsForSetsInJavaUtil {
}
static <T> Comparator<T> arbitraryNullFriendlyComparator() {
- return new NullFriendlyComparator<T>();
- }
-
- private static final class NullFriendlyComparator<T>
- implements Comparator<T>, Serializable {
- @Override
- public int compare(T left, T right) {
- return String.valueOf(left).compareTo(String.valueOf(right));
- }
+ return new Comparator<T>() {
+ @Override
+ public int compare(T left, T right) {
+ return String.valueOf(left).compareTo(String.valueOf(right));
+ }
+ };
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/UnhashableObject.java b/guava-testlib/src/com/google/common/collect/testing/UnhashableObject.java
index 014995d..d038cfb 100644
--- a/guava-testlib/src/com/google/common/collect/testing/UnhashableObject.java
+++ b/guava-testlib/src/com/google/common/collect/testing/UnhashableObject.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
/**
* An unhashable object to be used in testing as values in our collections.
*
@@ -25,7 +23,6 @@ import com.google.common.annotations.GwtCompatible;
*
* @author Regina O'Dell
*/
-@GwtCompatible
public class UnhashableObject implements Comparable<UnhashableObject> {
private final int value;
diff --git a/guava-testlib/src/com/google/common/collect/testing/WrongType.java b/guava-testlib/src/com/google/common/collect/testing/WrongType.java
index d49e942..0fecaba 100644
--- a/guava-testlib/src/com/google/common/collect/testing/WrongType.java
+++ b/guava-testlib/src/com/google/common/collect/testing/WrongType.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing;
-import com.google.common.annotations.GwtCompatible;
-
/**
* A type which will never be used as the element type of any collection in our
* tests, and so can be used to test how a Collection behaves when given input
@@ -25,7 +23,6 @@ import com.google.common.annotations.GwtCompatible;
*
* <p>This class is GWT compatible.
*/
-@GwtCompatible
public enum WrongType {
VALUE
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/CollectionFeature.java b/guava-testlib/src/com/google/common/collect/testing/features/CollectionFeature.java
index 831c99f..4f14c3c 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/CollectionFeature.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/CollectionFeature.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.Helpers;
import java.lang.annotation.Inherited;
@@ -36,8 +35,7 @@ import java.util.SortedSet;
*/
// Enum values use constructors with generic varargs.
@SuppressWarnings("unchecked")
-@GwtCompatible
-public enum CollectionFeature implements Feature<Collection> {
+public enum CollectionFeature implements Feature<Collection> {
/**
* The collection must not throw {@code NullPointerException} on calls
* such as {@code contains(null)} or {@code remove(null)}, but instead
@@ -63,7 +61,7 @@ public enum CollectionFeature implements Feature<Collection> {
* Indicates that a collection has a well-defined ordering of its elements.
* The ordering may depend on the element values, such as a {@link SortedSet},
* or on the insertion ordering, such as a {@link LinkedHashSet}. All list
- * tests and sorted-collection tests automatically specify this feature.
+ * tests automatically specify this feature.
*/
KNOWN_ORDER,
@@ -84,7 +82,10 @@ public enum CollectionFeature implements Feature<Collection> {
SUPPORTS_ADD,
SUPPORTS_REMOVE,
- FAILS_FAST_ON_CONCURRENT_MODIFICATION,
+ SUPPORTS_ADD_ALL,
+ SUPPORTS_REMOVE_ALL,
+ SUPPORTS_RETAIN_ALL,
+ SUPPORTS_CLEAR,
/**
* Features supported by general-purpose collections -
@@ -93,13 +94,18 @@ public enum CollectionFeature implements Feature<Collection> {
*/
GENERAL_PURPOSE(
SUPPORTS_ADD,
- SUPPORTS_REMOVE),
+ SUPPORTS_REMOVE,
+ SUPPORTS_ADD_ALL,
+ SUPPORTS_REMOVE_ALL,
+ SUPPORTS_RETAIN_ALL,
+ SUPPORTS_CLEAR),
/** Features supported by collections where only removal is allowed. */
REMOVE_OPERATIONS(
- SUPPORTS_REMOVE),
-
- SERIALIZABLE, SERIALIZABLE_INCLUDING_VIEWS(SERIALIZABLE),
+ SUPPORTS_REMOVE,
+ SUPPORTS_REMOVE_ALL,
+ SUPPORTS_RETAIN_ALL,
+ SUPPORTS_CLEAR),
/**
* For documenting collections that support no optional features, such as
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/CollectionSize.java b/guava-testlib/src/com/google/common/collect/testing/features/CollectionSize.java
index b919850..f986d35 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/CollectionSize.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/CollectionSize.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.Helpers;
import java.lang.annotation.Inherited;
@@ -48,7 +47,6 @@ import java.util.Set;
*/
// Enum values use constructors with generic varargs.
@SuppressWarnings("unchecked")
-@GwtCompatible
public enum CollectionSize implements Feature<Collection>,
Comparable<CollectionSize> {
/** Test an empty collection. */
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/ConflictingRequirementsException.java b/guava-testlib/src/com/google/common/collect/testing/features/ConflictingRequirementsException.java
index ace5afc..e70ed0d 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/ConflictingRequirementsException.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/ConflictingRequirementsException.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Set;
/**
@@ -28,7 +26,6 @@ import java.util.Set;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class ConflictingRequirementsException extends Exception {
private Set<Feature<?>> conflicts;
private Object source;
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/Feature.java b/guava-testlib/src/com/google/common/collect/testing/features/Feature.java
index db7c9ee..b185803 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/Feature.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/Feature.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
-
import java.util.Set;
/**
@@ -28,7 +26,6 @@ import java.util.Set;
* @param <T> The interface whose features are to be enumerated.
* @author George van den Driessche
*/
-@GwtCompatible
public interface Feature<T> {
/** Returns the set of features that are implied by this feature. */
Set<Feature<? super T>> getImpliedFeatures();
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/FeatureUtil.java b/guava-testlib/src/com/google/common/collect/testing/features/FeatureUtil.java
index 0351b16..3edffa3 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/FeatureUtil.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/FeatureUtil.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.Helpers;
import java.lang.annotation.Annotation;
@@ -36,7 +35,6 @@ import java.util.Set;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class FeatureUtil {
/**
* A cache of annotated objects (typically a Class or Method) to its
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/ListFeature.java b/guava-testlib/src/com/google/common/collect/testing/features/ListFeature.java
index 14ae4c0..095723f 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/ListFeature.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/ListFeature.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.Helpers;
import java.lang.annotation.Inherited;
@@ -34,22 +33,23 @@ import java.util.Set;
*/
// Enum values use constructors with generic varargs.
@SuppressWarnings("unchecked")
-@GwtCompatible
public enum ListFeature implements Feature<List> {
SUPPORTS_SET,
- SUPPORTS_ADD_WITH_INDEX(CollectionFeature.SUPPORTS_ADD),
- SUPPORTS_REMOVE_WITH_INDEX(CollectionFeature.SUPPORTS_REMOVE),
+ SUPPORTS_ADD_WITH_INDEX,
+ SUPPORTS_ADD_ALL_WITH_INDEX,
+ SUPPORTS_REMOVE_WITH_INDEX,
GENERAL_PURPOSE(
CollectionFeature.GENERAL_PURPOSE,
SUPPORTS_SET,
SUPPORTS_ADD_WITH_INDEX,
+ SUPPORTS_ADD_ALL_WITH_INDEX,
SUPPORTS_REMOVE_WITH_INDEX
),
/** Features supported by lists where only removal is allowed. */
REMOVE_OPERATIONS(
- CollectionFeature.SUPPORTS_REMOVE,
+ CollectionFeature.REMOVE_OPERATIONS,
SUPPORTS_REMOVE_WITH_INDEX
);
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/MapFeature.java b/guava-testlib/src/com/google/common/collect/testing/features/MapFeature.java
index 482d5b9..8d97a09 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/MapFeature.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/MapFeature.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.Helpers;
import java.lang.annotation.Inherited;
@@ -34,7 +33,6 @@ import java.util.Set;
*/
// Enum values use constructors with generic varargs.
@SuppressWarnings("unchecked")
-@GwtCompatible
public enum MapFeature implements Feature<Map> {
/**
* The map does not throw {@code NullPointerException} on calls such as
@@ -46,8 +44,9 @@ public enum MapFeature implements Feature<Map> {
RESTRICTS_KEYS,
RESTRICTS_VALUES,
SUPPORTS_PUT,
+ SUPPORTS_PUT_ALL,
SUPPORTS_REMOVE,
- FAILS_FAST_ON_CONCURRENT_MODIFICATION,
+ SUPPORTS_CLEAR,
/**
* Indicates that the constructor or factory method of a map, usually an
* immutable map, throws an {@link IllegalArgumentException} when presented
@@ -57,8 +56,16 @@ public enum MapFeature implements Feature<Map> {
GENERAL_PURPOSE(
SUPPORTS_PUT,
- SUPPORTS_REMOVE
- );
+ SUPPORTS_PUT_ALL,
+ SUPPORTS_REMOVE,
+ SUPPORTS_CLEAR
+ ),
+
+ /** Features supported by maps where only removal is allowed. */
+ REMOVE_OPERATIONS(
+ SUPPORTS_REMOVE,
+ SUPPORTS_CLEAR
+ );
private final Set<Feature<? super Map>> implied;
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/SetFeature.java b/guava-testlib/src/com/google/common/collect/testing/features/SetFeature.java
index 977eefa..7b6c069 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/SetFeature.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/SetFeature.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.Helpers;
import java.lang.annotation.Inherited;
@@ -33,7 +32,6 @@ import java.util.Set;
*/
// Enum values use constructors with generic varargs.
@SuppressWarnings("unchecked")
-@GwtCompatible
public enum SetFeature implements Feature<Set> {
GENERAL_PURPOSE(
CollectionFeature.GENERAL_PURPOSE
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java b/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java
index 850124e..bec249c 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/TesterAnnotation.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
-
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -41,6 +39,5 @@ import java.lang.annotation.Target;
@Target(value = {java.lang.annotation.ElementType.ANNOTATION_TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
@Documented
-@GwtCompatible
public @interface TesterAnnotation {
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/features/TesterRequirements.java b/guava-testlib/src/com/google/common/collect/testing/features/TesterRequirements.java
index 82c542a..1d72e3d 100644
--- a/guava-testlib/src/com/google/common/collect/testing/features/TesterRequirements.java
+++ b/guava-testlib/src/com/google/common/collect/testing/features/TesterRequirements.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.features;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.Helpers;
import java.util.Collections;
@@ -30,7 +29,6 @@ import java.util.Set;
*
* @author George van den Driessche
*/
-@GwtCompatible
public final class TesterRequirements {
private final Set<Feature<?>> presentFeatures;
private final Set<Feature<?>> absentFeatures;
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/AbstractBiMapTester.java b/guava-testlib/src/com/google/common/collect/testing/google/AbstractBiMapTester.java
deleted file mode 100644
index 88f1b24..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/AbstractBiMapTester.java
+++ /dev/null
@@ -1,77 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.testing.AbstractMapTester;
-import com.google.common.collect.testing.Helpers;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map.Entry;
-
-/**
- * Skeleton for a tester of a {@code BiMap}.
- */
-@GwtCompatible
-public abstract class AbstractBiMapTester<K, V> extends AbstractMapTester<K, V> {
-
- @Override
- protected BiMap<K, V> getMap() {
- return (BiMap<K, V>) super.getMap();
- }
-
- static <K, V> Entry<V, K> reverseEntry(Entry<K, V> entry) {
- return Helpers.mapEntry(entry.getValue(), entry.getKey());
- }
-
- @Override
- protected void expectContents(Collection<Entry<K, V>> expected) {
- super.expectContents(expected);
- List<Entry<V, K>> reversedEntries = new ArrayList<Entry<V, K>>();
- for (Entry<K, V> entry : expected) {
- reversedEntries.add(reverseEntry(entry));
- }
- Helpers.assertEqualIgnoringOrder(getMap().inverse().entrySet(), reversedEntries);
-
- for (Entry<K, V> entry : expected) {
- assertEquals("Wrong key for value " + entry.getValue(), entry.getKey(), getMap()
- .inverse()
- .get(entry.getValue()));
- }
- }
-
- @Override
- protected void expectMissing(Entry<K, V>... entries) {
- super.expectMissing(entries);
- for (Entry<K, V> entry : entries) {
- Entry<V, K> reversed = reverseEntry(entry);
- BiMap<V, K> inv = getMap().inverse();
- assertFalse("Inverse should not contain entry " + reversed,
- inv.entrySet().contains(entry));
- assertFalse("Inverse should not contain key " + entry.getValue(),
- inv.containsKey(entry.getValue()));
- assertFalse("Inverse should not contain value " + entry.getKey(),
- inv.containsValue(entry.getKey()));
- assertNull("Inverse should not return a mapping for key " + entry.getValue(),
- getMap().get(entry.getValue()));
- }
- }
-
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/AbstractListMultimapTester.java b/guava-testlib/src/com/google/common/collect/testing/google/AbstractListMultimapTester.java
deleted file mode 100644
index 9f81b4c..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/AbstractListMultimapTester.java
+++ /dev/null
@@ -1,54 +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 org.truth0.Truth.ASSERT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ListMultimap;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-/**
- * Superclass for all {@code ListMultimap} testers.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class AbstractListMultimapTester<K, V>
- extends AbstractMultimapTester<K, V, ListMultimap<K, V>> {
-
- protected void assertGet(K key, V... values) {
- assertGet(key, Arrays.asList(values));
- }
-
- protected void assertGet(K key, Collection<V> values) {
- ASSERT.that(multimap().get(key)).has().allFrom(values).inOrder();
-
- if (!values.isEmpty()) {
- ASSERT.that(multimap().asMap().get(key)).has().allFrom(values).inOrder();
- assertFalse(multimap().isEmpty());
- } else {
- ASSERT.that(multimap().asMap().get(key)).isNull();
- }
-
- assertEquals(values.size(), multimap().get(key).size());
- assertEquals(values.size() > 0, multimap().containsKey(key));
- assertEquals(values.size() > 0, multimap().keySet().contains(key));
- assertEquals(values.size() > 0, multimap().keys().contains(key));
- }
-}
-
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/AbstractMultimapTester.java b/guava-testlib/src/com/google/common/collect/testing/google/AbstractMultimapTester.java
deleted file mode 100644
index a0c0b89..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/AbstractMultimapTester.java
+++ /dev/null
@@ -1,166 +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 java.util.Arrays.asList;
-import static org.truth0.Truth.ASSERT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.AbstractContainerTester;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.SampleElements;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * Superclass for all {@code Multimap} testers.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public abstract class AbstractMultimapTester<K, V, M extends Multimap<K, V>>
- extends AbstractContainerTester<M, Map.Entry<K, V>> {
-
- private M multimap;
-
- protected M multimap() {
- return multimap;
- }
-
- /**
- * @return an array of the proper size with {@code null} as the key of the
- * middle element.
- */
- protected Map.Entry<K, V>[] createArrayWithNullKey() {
- Map.Entry<K, V>[] array = createSamplesArray();
- final int nullKeyLocation = getNullLocation();
- final Map.Entry<K, V> oldEntry = array[nullKeyLocation];
- array[nullKeyLocation] = Helpers.mapEntry(null, oldEntry.getValue());
- return array;
- }
-
- /**
- * @return an array of the proper size with {@code null} as the value of the
- * middle element.
- */
- protected Map.Entry<K, V>[] createArrayWithNullValue() {
- Map.Entry<K, V>[] array = createSamplesArray();
- final int nullValueLocation = getNullLocation();
- final Map.Entry<K, V> oldEntry = array[nullValueLocation];
- array[nullValueLocation] = Helpers.mapEntry(oldEntry.getKey(), null);
- return array;
- }
-
- /**
- * @return an array of the proper size with {@code null} as the key and value of the
- * middle element.
- */
- protected Map.Entry<K, V>[] createArrayWithNullKeyAndValue() {
- Map.Entry<K, V>[] array = createSamplesArray();
- final int nullValueLocation = getNullLocation();
- array[nullValueLocation] = Helpers.mapEntry(null, null);
- return array;
- }
-
- protected V getValueForNullKey() {
- return getEntryNullReplaces().getValue();
- }
-
- protected K getKeyForNullValue() {
- return getEntryNullReplaces().getKey();
- }
-
- private Entry<K, V> getEntryNullReplaces() {
- Iterator<Entry<K, V>> entries = getSampleElements().iterator();
- for (int i = 0; i < getNullLocation(); i++) {
- entries.next();
- }
- return entries.next();
- }
-
- protected void initMultimapWithNullKey() {
- resetContainer(getSubjectGenerator().create(createArrayWithNullKey()));
- }
-
- protected void initMultimapWithNullValue() {
- resetContainer(getSubjectGenerator().create(createArrayWithNullValue()));
- }
-
- protected void initMultimapWithNullKeyAndValue() {
- resetContainer(getSubjectGenerator().create(createArrayWithNullKeyAndValue()));
- }
-
- protected SampleElements<K> sampleKeys() {
- return ((TestMultimapGenerator<K, V, ? extends Multimap<K, V>>) getSubjectGenerator()
- .getInnerGenerator()).sampleKeys();
- }
-
- protected SampleElements<V> sampleValues() {
- return ((TestMultimapGenerator<K, V, ? extends Multimap<K, V>>) getSubjectGenerator()
- .getInnerGenerator()).sampleValues();
- }
-
- @Override
- protected Collection<Entry<K, V>> actualContents() {
- return multimap.entries();
- }
-
- // TODO: dispose of this once collection is encapsulated.
- @Override
- protected M resetContainer(M newContents) {
- multimap = super.resetContainer(newContents);
- return multimap;
- }
-
- protected Multimap<K, V> resetContainer(Entry<K, V>... newContents) {
- multimap = super.resetContainer(getSubjectGenerator().create(newContents));
- return multimap;
- }
-
- /** @see AbstractContainerTester#resetContainer() */
- protected void resetCollection() {
- resetContainer();
- }
-
- protected void assertGet(K key, V... values) {
- assertGet(key, Arrays.asList(values));
- }
-
- protected void assertGet(K key, Collection<V> values) {
- ASSERT.that(multimap().get(key)).has().allFrom(values);
-
- if (!values.isEmpty()) {
- ASSERT.that(multimap().asMap().get(key)).has().allFrom(values);
- assertFalse(multimap().isEmpty());
- } else {
- ASSERT.that(multimap().asMap().get(key)).isNull();
- }
-
- // TODO(user): Add proper overrides to prevent autoboxing.
- // Truth+autoboxing == compile error. Cast int to long to fix:
- ASSERT.that(multimap().get(key).size()).is((long) values.size());
-
- assertEquals(values.size() > 0, multimap().containsKey(key));
- assertEquals(values.size() > 0, multimap().keySet().contains(key));
- assertEquals(values.size() > 0, multimap().keys().contains(key));
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java b/guava-testlib/src/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java
index 55749b2..9219e3e 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java
@@ -17,7 +17,6 @@
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;
@@ -25,17 +24,12 @@ 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.annotations.GwtIncompatible;
import com.google.common.collect.Multiset;
-import com.google.common.collect.Multiset.Entry;
-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.lang.reflect.Method;
import java.util.Arrays;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
import java.util.List;
/**
@@ -47,7 +41,7 @@ import java.util.List;
*
* @author Chris Povirk
*/
-@GwtCompatible(emulated = true)
+@GwtCompatible
public abstract class AbstractMultisetSetCountTester<E>
extends AbstractMultisetTester<E> {
/*
@@ -191,32 +185,6 @@ public abstract class AbstractMultisetSetCountTester<E>
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);
@@ -252,33 +220,6 @@ public abstract class AbstractMultisetSetCountTester<E>
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() {
@@ -394,7 +335,6 @@ public abstract class AbstractMultisetSetCountTester<E>
* assume multisets support duplicates so that the test of {@code
* Multisets.forSet()} can suppress them.
*/
- @GwtIncompatible("reflection")
public static List<Method> getSetCountDuplicateInitializingMethods() {
return Arrays.asList(
getMethod("testSetCount_threeToThree_removeSupported"),
@@ -402,8 +342,7 @@ public abstract class AbstractMultisetSetCountTester<E>
getMethod("testSetCount_threeToOne_supported"));
}
- @GwtIncompatible("reflection")
private static Method getMethod(String methodName) {
- return Helpers.getMethod(AbstractMultisetSetCountTester.class, methodName);
+ return Platform.getMethod(AbstractMultisetSetCountTester.class, methodName);
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/BiMapClearTester.java b/guava-testlib/src/com/google/common/collect/testing/google/BiMapClearTester.java
deleted file mode 100644
index 5d0d7a5..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/BiMapClearTester.java
+++ /dev/null
@@ -1,79 +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.MapFeature.SUPPORTS_REMOVE;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.testing.features.MapFeature;
-
-/**
- * Tester for {@code BiMap.clear}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class BiMapClearTester<K, V> extends AbstractBiMapTester<K, V> {
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testClearClearsInverse() {
- BiMap<V, K> inv = getMap().inverse();
- getMap().clear();
- assertTrue(getMap().isEmpty());
- assertTrue(inv.isEmpty());
- }
-
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testKeySetClearClearsInverse() {
- BiMap<V, K> inv = getMap().inverse();
- getMap().keySet().clear();
- assertTrue(getMap().isEmpty());
- assertTrue(inv.isEmpty());
- }
-
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testValuesClearClearsInverse() {
- BiMap<V, K> inv = getMap().inverse();
- getMap().values().clear();
- assertTrue(getMap().isEmpty());
- assertTrue(inv.isEmpty());
- }
-
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testClearInverseClears() {
- BiMap<V, K> inv = getMap().inverse();
- inv.clear();
- assertTrue(getMap().isEmpty());
- assertTrue(inv.isEmpty());
- }
-
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testClearInverseKeySetClears() {
- BiMap<V, K> inv = getMap().inverse();
- inv.keySet().clear();
- assertTrue(getMap().isEmpty());
- assertTrue(inv.isEmpty());
- }
-
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testClearInverseValuesClears() {
- BiMap<V, K> inv = getMap().inverse();
- inv.values().clear();
- assertTrue(getMap().isEmpty());
- assertTrue(inv.isEmpty());
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java
index db19baa..987ae9c 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/BiMapGenerators.java
@@ -16,11 +16,18 @@
package com.google.common.collect.testing.google;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.testing.SampleElements;
+import com.google.common.collect.testing.TestMapEntrySetGenerator;
+import com.google.common.collect.testing.TestStringSetGenerator;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
/**
* Generators of various {@link com.google.common.collect.BiMap}s and derived
@@ -31,13 +38,82 @@ import java.util.Map.Entry;
*/
@GwtCompatible
public class BiMapGenerators {
- public static class ImmutableBiMapGenerator extends TestStringBiMapGenerator {
- @Override protected BiMap<String, String> create(Entry<String, String>[] entries) {
- ImmutableBiMap.Builder<String, String> builder = ImmutableBiMap.builder();
+
+ public static class ImmutableBiMapKeySetGenerator
+ extends TestStringSetGenerator {
+ @Override protected Set<String> create(String[] elements) {
+ Map<String, Integer> map = Maps.newLinkedHashMap();
+ for (int i = 0; i < elements.length; i++) {
+ map.put(elements[i], i);
+ }
+ return ImmutableBiMap.copyOf(map).keySet();
+ }
+ }
+
+ public static class ImmutableBiMapValuesGenerator
+ extends TestStringSetGenerator {
+ @Override protected Set<String> create(String[] elements) {
+ Map<Integer, String> map = Maps.newLinkedHashMap();
+ for (int i = 0; i < elements.length; i++) {
+ map.put(i, elements[i]);
+ }
+ return ImmutableBiMap.copyOf(map).values();
+ }
+ }
+
+ public static class ImmutableBiMapInverseEntrySetGenerator
+ extends TestMapEntrySetGenerator<String, String> {
+
+ public ImmutableBiMapInverseEntrySetGenerator() {
+ super(new SampleElements.Strings(), new SampleElements.Strings());
+ }
+ @Override public Set<Entry<String, String>> createFromEntries(
+ Entry<String, String>[] entries) {
+ Map<String, String> map = Maps.newLinkedHashMap();
+ for (Entry<String, String> entry : entries) {
+ checkNotNull(entry);
+ map.put(entry.getValue(), entry.getKey());
+ }
+ return ImmutableBiMap.copyOf(map).inverse().entrySet();
+ }
+ }
+
+ public static class ImmutableBiMapInverseKeySetGenerator
+ extends TestStringSetGenerator {
+ @Override protected Set<String> create(String[] elements) {
+ Map<Integer, String> map = Maps.newLinkedHashMap();
+ for (int i = 0; i < elements.length; i++) {
+ map.put(i, elements[i]);
+ }
+ return ImmutableBiMap.copyOf(map).inverse().keySet();
+ }
+ }
+
+ public static class ImmutableBiMapInverseValuesGenerator
+ extends TestStringSetGenerator {
+ @Override protected Set<String> create(String[] elements) {
+ Map<String, Integer> map = Maps.newLinkedHashMap();
+ for (int i = 0; i < elements.length; i++) {
+ map.put(elements[i], i);
+ }
+ return ImmutableBiMap.copyOf(map).inverse().values();
+ }
+ }
+
+ public static class ImmutableBiMapEntrySetGenerator
+ extends TestMapEntrySetGenerator<String, String> {
+
+ public ImmutableBiMapEntrySetGenerator() {
+ super(new SampleElements.Strings(), new SampleElements.Strings());
+ }
+ @Override public Set<Entry<String, String>> createFromEntries(
+ Entry<String, String>[] entries) {
+ Map<String, String> map = Maps.newLinkedHashMap();
for (Entry<String, String> entry : entries) {
- builder.put(entry.getKey(), entry.getValue());
+ checkNotNull(entry);
+ map.put(entry.getKey(), entry.getValue());
}
- return builder.build();
+ return ImmutableBiMap.copyOf(map).entrySet();
}
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/BiMapInverseTester.java b/guava-testlib/src/com/google/common/collect/testing/google/BiMapInverseTester.java
deleted file mode 100644
index c7cdbf9..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/BiMapInverseTester.java
+++ /dev/null
@@ -1,84 +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.annotations.GwtIncompatible;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.testing.SerializableTester;
-
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * 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;
- }
-
- /**
- * Returns {@link Method} instances for the tests that assume that the inverse will be the same
- * after serialization.
- */
- @GwtIncompatible("reflection")
- public static List<Method> getInverseSameAfterSerializingMethods() {
- return Collections.singletonList(getMethod("testInverseSerialization"));
- }
-
- @GwtIncompatible("reflection")
- private static Method getMethod(String methodName) {
- return Helpers.getMethod(BiMapInverseTester.class, methodName);
- }
-
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/BiMapPutTester.java b/guava-testlib/src/com/google/common/collect/testing/google/BiMapPutTester.java
deleted file mode 100644
index 8c31aa3..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/BiMapPutTester.java
+++ /dev/null
@@ -1,99 +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_PUT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-/**
- * Tester for {@code BiMap.put} and {@code BiMap.forcePut}.
- */
-@GwtCompatible
-public class BiMapPutTester<K, V> extends AbstractBiMapTester<K, V> {
-
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(ZERO)
- public void testPutWithSameValueFails() {
- K k0 = samples.e0.getKey();
- K k1 = samples.e1.getKey();
- V v0 = samples.e0.getValue();
- getMap().put(k0, v0);
- try {
- getMap().put(k1, v0);
- fail("Expected IllegalArgumentException");
- } catch (IllegalArgumentException expected) {
- // success
- }
- // verify that the bimap is unchanged
- expectAdded(samples.e0);
- }
-
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(ZERO)
- public void testPutPresentKeyDifferentValue() {
- K k0 = samples.e0.getKey();
- V v0 = samples.e0.getValue();
- V v1 = samples.e1.getValue();
- getMap().put(k0, v0);
- getMap().put(k0, v1);
- // verify that the bimap is changed, and that the old inverse mapping
- // from v1 -> v0 is deleted
- expectContents(Helpers.mapEntry(k0, v1));
- }
-
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(ZERO)
- public void putDistinctKeysDistinctValues() {
- getMap().put(samples.e0.getKey(), samples.e0.getValue());
- getMap().put(samples.e1.getKey(), samples.e1.getValue());
- expectAdded(samples.e0, samples.e1);
- }
-
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(ZERO)
- public void testForcePutOverwritesOldValueEntry() {
- K k0 = samples.e0.getKey();
- K k1 = samples.e1.getKey();
- V v0 = samples.e0.getValue();
- getMap().put(k0, v0);
- getMap().forcePut(k1, v0);
- // verify that the bimap is unchanged
- expectAdded(Helpers.mapEntry(k1, v0));
- }
-
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(ZERO)
- public void testInversePut() {
- K k0 = samples.e0.getKey();
- V v0 = samples.e0.getValue();
- K k1 = samples.e1.getKey();
- V v1 = samples.e1.getValue();
- getMap().put(k0, v0);
- getMap().inverse().put(v1, k1);
- expectAdded(samples.e0, samples.e1);
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/BiMapRemoveTester.java b/guava-testlib/src/com/google/common/collect/testing/google/BiMapRemoveTester.java
deleted file mode 100644
index fe3893b..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/BiMapRemoveTester.java
+++ /dev/null
@@ -1,107 +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.annotations.GwtIncompatible;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.lang.reflect.Method;
-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());
- }
-
- /**
- * Returns the {@link Method} instance for
- * {@link #testKeySetIteratorRemove()} so that tests of
- * {@code Maps.filterEntries(BiMap, Predicate)} can suppress
- * it with {@code FeatureSpecificTestSuiteBuilder.suppressing()}.
- */
- @GwtIncompatible("reflection")
- public static Method getKeySetIteratorRemoveMethod() {
- return Helpers.getMethod(BiMapRemoveTester.class, "testKeySetIteratorRemove");
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/BiMapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/google/BiMapTestSuiteBuilder.java
deleted file mode 100644
index 30ffdaa..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/BiMapTestSuiteBuilder.java
+++ /dev/null
@@ -1,173 +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 com.google.common.collect.BiMap;
-import com.google.common.collect.testing.AbstractTester;
-import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
-import com.google.common.collect.testing.MapTestSuiteBuilder;
-import com.google.common.collect.testing.OneSizeTestContainerGenerator;
-import com.google.common.collect.testing.PerCollectionSizeTestSuiteBuilder;
-import com.google.common.collect.testing.SetTestSuiteBuilder;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.features.MapFeature;
-import com.google.common.collect.testing.google.DerivedGoogleCollectionGenerators.BiMapValueSetGenerator;
-import com.google.common.collect.testing.google.DerivedGoogleCollectionGenerators.InverseBiMapGenerator;
-import com.google.common.collect.testing.google.DerivedGoogleCollectionGenerators.MapGenerator;
-import com.google.common.collect.testing.testers.SetCreationTester;
-
-import junit.framework.TestSuite;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * Creates, based on your criteria, a JUnit test suite that exhaustively tests a {@code BiMap}
- * implementation.
- *
- * @author Louis Wasserman
- */
-public class BiMapTestSuiteBuilder<K, V>
- extends PerCollectionSizeTestSuiteBuilder<BiMapTestSuiteBuilder<K, V>,
- TestBiMapGenerator<K, V>, BiMap<K, V>, Map.Entry<K, V>> {
- public static <K, V> BiMapTestSuiteBuilder<K, V> using(TestBiMapGenerator<K, V> generator) {
- return new BiMapTestSuiteBuilder<K, V>().usingGenerator(generator);
- }
-
- @Override
- protected List<Class<? extends AbstractTester>> getTesters() {
- List<Class<? extends AbstractTester>> testers =
- new ArrayList<Class<? extends AbstractTester>>();
- testers.add(BiMapPutTester.class);
- testers.add(BiMapInverseTester.class);
- testers.add(BiMapRemoveTester.class);
- testers.add(BiMapClearTester.class);
- return testers;
- }
-
- enum NoRecurse implements Feature<Void> {
- INVERSE;
-
- @Override
- public Set<Feature<? super Void>> getImpliedFeatures() {
- return Collections.emptySet();
- }
- }
-
- @Override
- protected
- List<TestSuite>
- createDerivedSuites(
- FeatureSpecificTestSuiteBuilder<?,
- ? extends OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>>> parentBuilder) {
- List<TestSuite> derived = super.createDerivedSuites(parentBuilder);
- // TODO(cpovirk): consider using this approach (derived suites instead of extension) in
- // ListTestSuiteBuilder, etc.?
- derived.add(MapTestSuiteBuilder
- .using(new MapGenerator<K, V>(parentBuilder.getSubjectGenerator()))
- .withFeatures(parentBuilder.getFeatures())
- .named(parentBuilder.getName() + " [Map]")
- .suppressing(parentBuilder.getSuppressedTests())
- .suppressing(SetCreationTester.class.getMethods())
- // BiMap.entrySet() duplicate-handling behavior is too confusing for SetCreationTester
- .createTestSuite());
- /*
- * TODO(cpovirk): the Map tests duplicate most of this effort by using a
- * CollectionTestSuiteBuilder on values(). It would be nice to avoid that
- */
- derived.add(SetTestSuiteBuilder
- .using(new BiMapValueSetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeValuesSetFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + " values [Set]")
- .suppressing(parentBuilder.getSuppressedTests())
- .suppressing(SetCreationTester.class.getMethods())
- // BiMap.values() duplicate-handling behavior is too confusing for SetCreationTester
- .createTestSuite());
- if (!parentBuilder.getFeatures().contains(NoRecurse.INVERSE)) {
- derived.add(BiMapTestSuiteBuilder
- .using(new InverseBiMapGenerator<K, V>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeInverseFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + " inverse")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
- }
-
- return derived;
- }
-
- private static Set<Feature<?>> computeInverseFeatures(Set<Feature<?>> mapFeatures) {
- Set<Feature<?>> inverseFeatures = new HashSet<Feature<?>>(mapFeatures);
-
- boolean nullKeys = inverseFeatures.remove(MapFeature.ALLOWS_NULL_KEYS);
- boolean nullValues = inverseFeatures.remove(MapFeature.ALLOWS_NULL_VALUES);
-
- if (nullKeys) {
- inverseFeatures.add(MapFeature.ALLOWS_NULL_VALUES);
- }
- if (nullValues) {
- inverseFeatures.add(MapFeature.ALLOWS_NULL_KEYS);
- }
-
- inverseFeatures.add(NoRecurse.INVERSE);
- inverseFeatures.remove(CollectionFeature.KNOWN_ORDER);
- inverseFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION);
-
- return inverseFeatures;
- }
-
- // TODO(user): can we eliminate the duplication from MapTestSuiteBuilder here?
-
- private static Set<Feature<?>> computeValuesSetFeatures(
- Set<Feature<?>> mapFeatures) {
- Set<Feature<?>> valuesCollectionFeatures =
- computeCommonDerivedCollectionFeatures(mapFeatures);
- valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
-
- if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
- valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
- }
-
- valuesCollectionFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
-
- return valuesCollectionFeatures;
- }
-
- private static Set<Feature<?>> computeCommonDerivedCollectionFeatures(
- Set<Feature<?>> mapFeatures) {
- Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
- if (mapFeatures.contains(MapFeature.SUPPORTS_REMOVE)) {
- derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE);
- }
- if (mapFeatures.contains(MapFeature.REJECTS_DUPLICATES_AT_CREATION)) {
- derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
- }
- // add the intersection of CollectionSize.values() and mapFeatures
- for (CollectionSize size : CollectionSize.values()) {
- if (mapFeatures.contains(size)) {
- derivedFeatures.add(size);
- }
- }
- return derivedFeatures;
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java
deleted file mode 100644
index e3178b4..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/DerivedGoogleCollectionGenerators.java
+++ /dev/null
@@ -1,211 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.testing.DerivedGenerator;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.OneSizeTestContainerGenerator;
-import com.google.common.collect.testing.SampleElements;
-import com.google.common.collect.testing.TestMapGenerator;
-import com.google.common.collect.testing.TestSetGenerator;
-import com.google.common.collect.testing.TestSubjectGenerator;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * Derived suite generators for Guava collection interfaces, split out of the suite builders so that
- * they are available to GWT.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public final class DerivedGoogleCollectionGenerators {
- public static class MapGenerator<K, V> implements TestMapGenerator<K, V>, DerivedGenerator {
-
- private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> generator;
-
- public MapGenerator(
- OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> oneSizeTestContainerGenerator) {
- this.generator = oneSizeTestContainerGenerator;
- }
-
- @Override
- public SampleElements<Map.Entry<K, V>> samples() {
- return generator.samples();
- }
-
- @Override
- public Map<K, V> create(Object... elements) {
- return generator.create(elements);
- }
-
- @Override
- public Map.Entry<K, V>[] createArray(int length) {
- return generator.createArray(length);
- }
-
- @Override
- public Iterable<Map.Entry<K, V>> order(List<Map.Entry<K, V>> insertionOrder) {
- return generator.order(insertionOrder);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public K[] createKeyArray(int length) {
- return (K[]) new Object[length];
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public V[] createValueArray(int length) {
- return (V[]) new Object[length];
- }
-
- public TestSubjectGenerator<?> getInnerGenerator() {
- return generator;
- }
- }
-
- public static class InverseBiMapGenerator<K, V>
- implements TestBiMapGenerator<V, K>, DerivedGenerator {
-
- private final OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> generator;
-
- public InverseBiMapGenerator(
- OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> oneSizeTestContainerGenerator) {
- this.generator = oneSizeTestContainerGenerator;
- }
-
- @Override
- public SampleElements<Map.Entry<V, K>> samples() {
- SampleElements<Entry<K, V>> samples = generator.samples();
- return new SampleElements<Map.Entry<V, K>>(reverse(samples.e0), reverse(samples.e1),
- reverse(samples.e2), reverse(samples.e3), reverse(samples.e4));
- }
-
- private Map.Entry<V, K> reverse(Map.Entry<K, V> entry) {
- return Helpers.mapEntry(entry.getValue(), entry.getKey());
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public BiMap<V, K> create(Object... elements) {
- Entry[] entries = new Entry[elements.length];
- for (int i = 0; i < elements.length; i++) {
- entries[i] = reverse((Entry<K, V>) elements[i]);
- }
- return generator.create((Object[]) entries).inverse();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Map.Entry<V, K>[] createArray(int length) {
- return new Entry[length];
- }
-
- @Override
- public Iterable<Entry<V, K>> order(List<Entry<V, K>> insertionOrder) {
- return insertionOrder;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public V[] createKeyArray(int length) {
- return (V[]) new Object[length];
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public K[] createValueArray(int length) {
- return (K[]) new Object[length];
- }
-
- public TestSubjectGenerator<?> getInnerGenerator() {
- return generator;
- }
- }
-
- public static class BiMapValueSetGenerator<K, V>
- implements TestSetGenerator<V>, DerivedGenerator {
- private final OneSizeTestContainerGenerator<BiMap<K, V>, Map.Entry<K, V>>
- mapGenerator;
- private final SampleElements<V> samples;
-
- public BiMapValueSetGenerator(
- OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>> mapGenerator) {
- this.mapGenerator = mapGenerator;
- final SampleElements<Map.Entry<K, V>> mapSamples =
- this.mapGenerator.samples();
- this.samples = new SampleElements<V>(
- mapSamples.e0.getValue(),
- mapSamples.e1.getValue(),
- mapSamples.e2.getValue(),
- mapSamples.e3.getValue(),
- mapSamples.e4.getValue());
- }
-
- @Override
- public SampleElements<V> samples() {
- return samples;
- }
-
- @Override
- public Set<V> create(Object... elements) {
- @SuppressWarnings("unchecked")
- V[] valuesArray = (V[]) elements;
-
- // Start with a suitably shaped collection of entries
- Collection<Map.Entry<K, V>> originalEntries =
- mapGenerator.getSampleElements(elements.length);
-
- // Create a copy of that, with the desired value for each value
- Collection<Map.Entry<K, V>> entries =
- new ArrayList<Entry<K, V>>(elements.length);
- int i = 0;
- for (Map.Entry<K, V> entry : originalEntries) {
- entries.add(Helpers.mapEntry(entry.getKey(), valuesArray[i++]));
- }
-
- return mapGenerator.create(entries.toArray()).values();
- }
-
- @Override
- public V[] createArray(int length) {
- final V[] vs = ((TestBiMapGenerator<K, V>) mapGenerator.getInnerGenerator())
- .createValueArray(length);
- return vs;
- }
-
- @Override
- public Iterable<V> order(List<V> insertionOrder) {
- return insertionOrder;
- }
-
- public TestSubjectGenerator<?> getInnerGenerator() {
- return mapGenerator;
- }
- }
-
- private DerivedGoogleCollectionGenerators() {}
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/ListGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/ListGenerators.java
index fb14416..e0b7691 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/ListGenerators.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/ListGenerators.java
@@ -20,15 +20,12 @@ import static java.util.Arrays.asList;
import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.collect.testing.TestCharacterListGenerator;
+import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.testing.TestListGenerator;
import com.google.common.collect.testing.TestStringListGenerator;
import com.google.common.collect.testing.TestUnhashableCollectionGenerator;
import com.google.common.collect.testing.UnhashableObject;
-import com.google.common.primitives.Chars;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -50,7 +47,7 @@ public final class ListGenerators {
public static class BuilderAddListGenerator extends TestStringListGenerator {
@Override protected List<String> create(String[] elements) {
- ImmutableList.Builder<String> builder = ImmutableList.<String>builder();
+ Builder<String> builder = ImmutableList.<String>builder();
for (String element : elements) {
builder.add(element);
}
@@ -66,7 +63,7 @@ public final class ListGenerators {
.build();
}
}
-
+
public static class BuilderReversedListGenerator
extends TestStringListGenerator {
@Override protected List<String> create(String[] elements) {
@@ -116,24 +113,6 @@ public final class ListGenerators {
}
}
- public static class CharactersOfStringGenerator
- extends TestCharacterListGenerator {
- @Override public List<Character> create(Character[] elements) {
- char[] chars = Chars.toArray(Arrays.asList(elements));
- return Lists.charactersOf(String.copyValueOf(chars));
- }
- }
-
- public static class CharactersOfCharSequenceGenerator
- extends TestCharacterListGenerator {
- @Override public List<Character> create(Character[] elements) {
- char[] chars = Chars.toArray(Arrays.asList(elements));
- StringBuilder str = new StringBuilder();
- str.append(chars);
- return Lists.charactersOf(str);
- }
- }
-
private abstract static class TestUnhashableListGenerator
extends TestUnhashableCollectionGenerator<List<UnhashableObject>>
implements TestListGenerator<UnhashableObject> {
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapPutAllTester.java b/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapPutAllTester.java
deleted file mode 100644
index 228d61d..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapPutAllTester.java
+++ /dev/null
@@ -1,53 +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.Helpers.copyToList;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Testers for {@link ListMultimap#putAll(Object, Iterable)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class ListMultimapPutAllTester<K, V> extends AbstractListMultimapTester<K, V> {
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutAllAddsAtEndInOrder() {
- @SuppressWarnings("unchecked")
- List<V> values = Arrays.asList(
- sampleValues().e3,
- sampleValues().e1,
- sampleValues().e4);
-
- for (K k : sampleKeys()) {
- resetContainer();
-
- List<V> expectedValues = copyToList(multimap().get(k));
-
- multimap().putAll(k, values);
- expectedValues.addAll(values);
-
- assertGet(k, expectedValues);
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapPutTester.java b/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapPutTester.java
deleted file mode 100644
index 2941612..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapPutTester.java
+++ /dev/null
@@ -1,77 +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.Helpers.copyToList;
-import static com.google.common.collect.testing.features.CollectionSize.ZERO;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.List;
-import java.util.Map.Entry;
-
-/**
- * Testers for {@link ListMultimap#put(Object, Object)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class ListMultimapPutTester<K, V> extends AbstractListMultimapTester<K, V> {
- // MultimapPutTester tests non-duplicate values, but ignores ordering
-
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutAddsValueAtEnd() {
- for (K key : sampleKeys()) {
- for (V value : sampleValues()) {
- resetContainer();
-
- List<V> values = multimap().get(key);
- List<V> expectedValues = Helpers.copyToList(values);
-
- multimap().put(key, value);
- expectedValues.add(value);
-
- assertGet(key, expectedValues);
- assertEquals(value, values.get(values.size() - 1));
- }
- }
- }
-
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(absent = ZERO)
- public void testPutDuplicateValue() {
- List<Entry<K, V>> entries = copyToList(multimap().entries());
-
- for (Entry<K, V> entry : entries) {
- resetContainer();
-
- K k = entry.getKey();
- V v = entry.getValue();
-
- List<V> values = multimap().get(k);
- List<V> expectedValues = copyToList(values);
-
- assertTrue(multimap().put(k, v));
- expectedValues.add(v);
- assertGet(k, expectedValues);
- assertEquals(v, values.get(values.size() - 1));
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapRemoveTester.java b/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapRemoveTester.java
deleted file mode 100644
index 18f9b3a..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapRemoveTester.java
+++ /dev/null
@@ -1,116 +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.Helpers.copyToList;
-import static com.google.common.collect.testing.Helpers.mapEntry;
-import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
-import static org.truth0.Truth.ASSERT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Testers for {@link ListMultimap#remove(Object, Object)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class ListMultimapRemoveTester<K, V> extends AbstractListMultimapTester<K, V> {
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_REMOVE)
- @CollectionSize.Require(SEVERAL)
- public void testMultimapRemoveDeletesFirstOccurrence() {
- K k = sampleKeys().e0;
- V v0 = sampleValues().e0;
- V v1 = sampleValues().e2;
- resetContainer(mapEntry(k, v0), mapEntry(k, v1), mapEntry(k, v0));
-
- List<V> list = multimap().get(k);
- multimap().remove(k, v0);
- ASSERT.that(list).has().allOf(v1, v0).inOrder();
- }
-
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_REMOVE)
- @CollectionSize.Require(SEVERAL)
- public void testRemoveAtIndexFromGetPropagates() {
- K k = sampleKeys().e0;
- V v0 = sampleValues().e0;
- V v1 = sampleValues().e2;
- List<V> values = Arrays.asList(v0, v1, v0);
-
- for (int i = 0; i < 3; i++) {
- resetContainer(mapEntry(k, v0), mapEntry(k, v1), mapEntry(k, v0));
- List<V> expectedValues = copyToList(values);
-
- multimap().get(k).remove(i);
- expectedValues.remove(i);
-
- assertGet(k, expectedValues);
- }
- }
-
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_REMOVE)
- @CollectionSize.Require(SEVERAL)
- public void testRemoveAtIndexFromAsMapPropagates() {
- K k = sampleKeys().e0;
- V v0 = sampleValues().e0;
- V v1 = sampleValues().e2;
- List<V> values = Arrays.asList(v0, v1, v0);
-
- for (int i = 0; i < 3; i++) {
- resetContainer(mapEntry(k, v0), mapEntry(k, v1), mapEntry(k, v0));
- List<V> expectedValues = copyToList(values);
-
- List<V> asMapValue = (List<V>) multimap().asMap().get(k);
- asMapValue.remove(i);
- expectedValues.remove(i);
-
- assertGet(k, expectedValues);
- }
- }
-
- @SuppressWarnings("unchecked")
- @MapFeature.Require(SUPPORTS_REMOVE)
- @CollectionSize.Require(SEVERAL)
- public void testRemoveAtIndexFromAsMapEntrySetPropagates() {
- K k = sampleKeys().e0;
- V v0 = sampleValues().e0;
- V v1 = sampleValues().e2;
- List<V> values = Arrays.asList(v0, v1, v0);
-
- for (int i = 0; i < 3; i++) {
- resetContainer(mapEntry(k, v0), mapEntry(k, v1), mapEntry(k, v0));
- List<V> expectedValues = copyToList(values);
-
- Map.Entry<K, Collection<V>> asMapEntry = multimap().asMap().entrySet().iterator().next();
- List<V> asMapValue = (List<V>) asMapEntry.getValue();
- asMapValue.remove(i);
- expectedValues.remove(i);
-
- assertGet(k, expectedValues);
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapReplaceValuesTester.java b/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapReplaceValuesTester.java
deleted file mode 100644
index b7551af..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapReplaceValuesTester.java
+++ /dev/null
@@ -1,48 +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.MapFeature.SUPPORTS_PUT;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Testers for {@link ListMultimap#replaceValues(Object, Iterable)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class ListMultimapReplaceValuesTester<K, V> extends AbstractListMultimapTester<K, V> {
- @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
- public void testReplaceValuesPreservesOrder() {
- @SuppressWarnings("unchecked")
- List<V> values = Arrays.asList(
- sampleValues().e3,
- sampleValues().e1,
- sampleValues().e4);
-
- for (K k : sampleKeys()) {
- resetContainer();
- multimap().replaceValues(k, values);
- assertGet(k, values);
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java
deleted file mode 100644
index 87f84d6..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/ListMultimapTestSuiteBuilder.java
+++ /dev/null
@@ -1,100 +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 com.google.common.collect.ListMultimap;
-import com.google.common.collect.testing.AbstractTester;
-import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.ListTestSuiteBuilder;
-import com.google.common.collect.testing.OneSizeTestContainerGenerator;
-import com.google.common.collect.testing.TestListGenerator;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.features.ListFeature;
-
-import junit.framework.TestSuite;
-
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * Creates, based on your criteria, a JUnit test suite that exhaustively tests
- * a {@code ListMultimap} implementation.
- *
- * @author Louis Wasserman
- */
-public class ListMultimapTestSuiteBuilder<K, V> extends
- MultimapTestSuiteBuilder<K, V, ListMultimap<K, V>> {
-
- public static <K, V> ListMultimapTestSuiteBuilder<K, V> using(
- TestListMultimapGenerator<K, V> generator) {
- ListMultimapTestSuiteBuilder<K, V> result = new ListMultimapTestSuiteBuilder<K, V>();
- result.usingGenerator(generator);
- return result;
- }
-
- @Override protected List<Class<? extends AbstractTester>> getTesters() {
- List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
- testers.add(ListMultimapPutTester.class);
- testers.add(ListMultimapPutAllTester.class);
- testers.add(ListMultimapRemoveTester.class);
- testers.add(ListMultimapReplaceValuesTester.class);
- return testers;
- }
-
- @Override
- TestSuite computeMultimapGetTestSuite(
- FeatureSpecificTestSuiteBuilder<?, ? extends
- OneSizeTestContainerGenerator<ListMultimap<K, V>, Entry<K, V>>> parentBuilder) {
- return ListTestSuiteBuilder.using(
- new MultimapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeMultimapGetFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".get[key]")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- @Override
- Set<Feature<?>> computeMultimapGetFeatures(
- Set<Feature<?>> multimapFeatures) {
- Set<Feature<?>> derivedFeatures = super.computeMultimapGetFeatures(multimapFeatures);
- if (derivedFeatures.contains(CollectionFeature.SUPPORTS_ADD)) {
- derivedFeatures.add(ListFeature.SUPPORTS_ADD_WITH_INDEX);
- }
- if (derivedFeatures.contains(CollectionFeature.GENERAL_PURPOSE)) {
- derivedFeatures.add(ListFeature.GENERAL_PURPOSE);
- }
- return derivedFeatures;
- }
-
- private static class MultimapGetGenerator<K, V>
- extends MultimapTestSuiteBuilder.MultimapGetGenerator<K, V, ListMultimap<K, V>>
- implements TestListGenerator<V> {
- public MultimapGetGenerator(
- OneSizeTestContainerGenerator<ListMultimap<K, V>, Entry<K, V>> multimapGenerator) {
- super(multimapGenerator);
- }
-
- @Override
- public List<V> create(Object... elements) {
- return (List<V>) super.create(elements);
- }
-
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java
index fa4b91d..2dd9f54 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/MapGenerators.java
@@ -16,26 +16,23 @@
package com.google.common.collect.testing.google;
-import static com.google.common.collect.testing.Helpers.mapEntry;
+import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Ordering;
-import com.google.common.collect.testing.AnEnum;
+import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.testing.SampleElements;
-import com.google.common.collect.testing.TestEnumMapGenerator;
+import com.google.common.collect.testing.TestCollectionGenerator;
import com.google.common.collect.testing.TestListGenerator;
-import com.google.common.collect.testing.TestStringListGenerator;
-import com.google.common.collect.testing.TestStringMapGenerator;
+import com.google.common.collect.testing.TestMapEntrySetGenerator;
+import com.google.common.collect.testing.TestStringSetGenerator;
import com.google.common.collect.testing.TestUnhashableCollectionGenerator;
import com.google.common.collect.testing.UnhashableObject;
import java.util.Collection;
-import java.util.EnumMap;
import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
/**
* Generators of different types of map and related collections, such as
@@ -45,121 +42,105 @@ import java.util.Map.Entry;
*/
@GwtCompatible
public class MapGenerators {
- public static class ImmutableMapGenerator
- extends TestStringMapGenerator {
- @Override protected Map<String, String> create(Entry<String, String>[] entries) {
- ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
- for (Entry<String, String> entry : entries) {
- builder.put(entry.getKey(), entry.getValue());
+
+ public static class ImmutableMapKeySetGenerator
+ extends TestStringSetGenerator {
+ @Override protected Set<String> create(String[] elements) {
+ Builder<String, Integer> builder = ImmutableMap.builder();
+ for (String key : elements) {
+ builder.put(key, 4);
}
- return builder.build();
+ return builder.build().keySet();
}
}
- public static class ImmutableMapUnhashableValuesGenerator
- extends TestUnhashableCollectionGenerator<Collection<UnhashableObject>> {
+ public static class ImmutableMapValuesGenerator
+ implements TestCollectionGenerator<String> {
- @Override public Collection<UnhashableObject> create(
- UnhashableObject[] elements) {
- ImmutableMap.Builder<Integer, UnhashableObject> builder = ImmutableMap.builder();
- int key = 1;
- for (UnhashableObject value : elements) {
- builder.put(key++, value);
+ @Override
+ public SampleElements<String> samples() {
+ return new SampleElements.Strings();
+ }
+
+ @Override
+ public Collection<String> create(Object... elements) {
+ Builder<Object, String> builder = ImmutableMap.builder();
+ for (Object key : elements) {
+ builder.put(key, String.valueOf(key));
}
return builder.build().values();
}
- }
- public static class ImmutableMapKeyListGenerator extends TestStringListGenerator {
@Override
- public List<String> create(String[] elements) {
- ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder();
- for (int i = 0; i < elements.length; i++) {
- builder.put(elements[i], i);
- }
- return builder.build().keySet().asList();
+ public String[] createArray(int length) {
+ return new String[length];
}
- }
- public static class ImmutableMapValueListGenerator extends TestStringListGenerator {
@Override
- public List<String> create(String[] elements) {
- ImmutableMap.Builder<Integer, String> builder = ImmutableMap.builder();
- for (int i = 0; i < elements.length; i++) {
- builder.put(i, elements[i]);
- }
- return builder.build().values().asList();
+ public List<String> order(List<String> insertionOrder) {
+ return insertionOrder;
}
}
- public static class ImmutableMapEntryListGenerator
- implements TestListGenerator<Entry<String, Integer>> {
+ public static class ImmutableMapUnhashableValuesGenerator
+ extends TestUnhashableCollectionGenerator<Collection<UnhashableObject>> {
- @Override
- public SampleElements<Entry<String, Integer>> samples() {
- return new SampleElements<Entry<String, Integer>>(
- mapEntry("foo", 5),
- mapEntry("bar", 3),
- mapEntry("baz", 17),
- mapEntry("quux", 1),
- mapEntry("toaster", -2));
+ @Override public Collection<UnhashableObject> create(
+ UnhashableObject[] elements) {
+ Builder<Integer, UnhashableObject> builder = ImmutableMap.builder();
+ int key = 1;
+ for (UnhashableObject value : elements) {
+ builder.put(key++, value);
+ }
+ return builder.build().values();
}
+ }
- @SuppressWarnings("unchecked")
- @Override
- public Entry<String, Integer>[] createArray(int length) {
- return new Entry[length];
- }
+ public static class ImmutableMapEntrySetGenerator
+ extends TestMapEntrySetGenerator<String, String> {
- @Override
- public Iterable<Entry<String, Integer>> order(List<Entry<String, Integer>> insertionOrder) {
- return insertionOrder;
+ public ImmutableMapEntrySetGenerator() {
+ super(new SampleElements.Strings(), new SampleElements.Strings());
}
- @Override
- public List<Entry<String, Integer>> create(Object... elements) {
- ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder();
- for (Object o : elements) {
- @SuppressWarnings("unchecked")
- Entry<String, Integer> entry = (Entry<String, Integer>) o;
- builder.put(entry);
+ @Override public Set<Entry<String, String>> createFromEntries(
+ Entry<String, String>[] entries) {
+ Builder<String, String> builder = ImmutableMap.builder();
+ for (Entry<String, String> entry : entries) {
+ // This null-check forces NPE to be thrown for tests with null
+ // elements. Those tests aren't useful in testing entry sets
+ // because entry sets never have null elements.
+ checkNotNull(entry);
+ builder.put(entry.getKey(), entry.getValue());
}
- return builder.build().entrySet().asList();
+ return builder.build().entrySet();
}
}
- public static class ImmutableEnumMapGenerator extends TestEnumMapGenerator {
+ public static class ImmutableMapValueListGenerator
+ implements TestListGenerator<String> {
@Override
- protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
- Map<AnEnum, String> map = Maps.newHashMap();
- for (Entry<AnEnum, String> entry : entries) {
- // checkArgument(!map.containsKey(entry.getKey()));
- map.put(entry.getKey(), entry.getValue());
- }
- return Maps.immutableEnumMap(map);
+ public SampleElements<String> samples() {
+ return new SampleElements.Strings();
}
- }
- public static class ImmutableMapCopyOfEnumMapGenerator extends TestEnumMapGenerator {
@Override
- protected Map<AnEnum, String> create(Entry<AnEnum, String>[] entries) {
- EnumMap<AnEnum, String> map = new EnumMap<AnEnum, String>(AnEnum.class);
- for (Entry<AnEnum, String> entry : entries) {
- map.put(entry.getKey(), entry.getValue());
+ public List<String> create(Object... elements) {
+ Builder<Integer, String> builder = ImmutableMap.builder();
+ for (int i = 0; i < elements.length; i++) {
+ builder.put(i, toStringOrNull(elements[i]));
}
- return ImmutableMap.copyOf(map);
+ return builder.build().values().asList();
}
@Override
- public Iterable<Entry<AnEnum, String>> order(List<Entry<AnEnum, String>> insertionOrder) {
- return new Ordering<Entry<AnEnum, String>>() {
-
- @Override
- public int compare(Entry<AnEnum, String> left, Entry<AnEnum, String> right) {
- return left.getKey().compareTo(right.getKey());
- }
+ public String[] createArray(int length) {
+ return new String[length];
+ }
- }.sortedCopy(insertionOrder);
+ @Override
+ public Iterable<String> order(List<String> insertionOrder) {
+ return insertionOrder;
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsEntryTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsEntryTester.java
deleted file mode 100644
index aeabd99..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsEntryTester.java
+++ /dev/null
@@ -1,76 +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.ALLOWS_NULL_KEYS;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_QUERIES;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-/**
- * Tester for {@link Multimap#containsEntry}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapContainsEntryTester<K, V>
- extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- @CollectionSize.Require(absent = ZERO)
- public void testContainsEntryYes() {
- assertTrue(multimap().containsEntry(sampleKeys().e0, sampleValues().e0));
- }
-
- public void testContainsEntryNo() {
- assertFalse(multimap().containsEntry(sampleKeys().e3, sampleValues().e3));
- }
-
- public void testContainsEntryAgreesWithGet() {
- for (K k : sampleKeys()) {
- for (V v : sampleValues()) {
- assertEquals(multimap().get(k).contains(v),
- multimap().containsEntry(k, v));
- }
- }
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require({ ALLOWS_NULL_KEYS, ALLOWS_NULL_VALUES })
- public void testContainsEntryNullYes() {
- initMultimapWithNullKeyAndValue();
- assertTrue(multimap().containsEntry(null, null));
- }
-
- @MapFeature.Require(ALLOWS_NULL_QUERIES)
- public void testContainsEntryNullNo() {
- assertFalse(multimap().containsEntry(null, null));
- }
-
- @MapFeature.Require(absent = ALLOWS_NULL_QUERIES)
- public void testContainsEntryNullDisallowed() {
- try {
- multimap().containsEntry(null, null);
- fail("Expected NullPointerException");
- } catch (NullPointerException expected) {
- // success
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsKeyTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsKeyTester.java
deleted file mode 100644
index 1d2e7d9..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsKeyTester.java
+++ /dev/null
@@ -1,90 +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.ALLOWS_NULL_KEYS;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_QUERIES;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-/**
- * Tester for the {@code containsKey} methods of {@code Multimap} and its {@code asMap()} view.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapContainsKeyTester<K, V>
- extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- @CollectionSize.Require(absent = ZERO)
- public void testContainsKeyYes() {
- assertTrue(multimap().containsKey(sampleKeys().e0));
- }
-
- public void testContainsKeyNo() {
- assertFalse(multimap().containsKey(sampleKeys().e3));
- }
-
- public void testContainsKeysFromKeySet() {
- for (K k : multimap().keySet()) {
- assertTrue(multimap().containsKey(k));
- }
- }
-
- public void testContainsKeyAgreesWithGet() {
- for (K k : sampleKeys()) {
- assertEquals(!multimap().get(k).isEmpty(), multimap().containsKey(k));
- }
- }
-
- public void testContainsKeyAgreesWithAsMap() {
- for (K k : sampleKeys()) {
- assertEquals(multimap().containsKey(k), multimap().asMap().containsKey(k));
- }
- }
-
- public void testContainsKeyAgreesWithKeySet() {
- for (K k : sampleKeys()) {
- assertEquals(multimap().containsKey(k), multimap().keySet().contains(k));
- }
- }
-
- @MapFeature.Require(ALLOWS_NULL_KEYS)
- @CollectionSize.Require(absent = ZERO)
- public void testContainsKeyNullPresent() {
- initMultimapWithNullKey();
- assertTrue(multimap().containsKey(null));
- }
-
- @MapFeature.Require(ALLOWS_NULL_QUERIES)
- public void testContainsKeyNullAbsent() {
- assertFalse(multimap().containsKey(null));
- }
-
- @MapFeature.Require(absent = ALLOWS_NULL_QUERIES)
- public void testContainsKeyNullDisallowed() {
- try {
- multimap().containsKey(null);
- fail("Expected NullPointerException");
- } catch (NullPointerException expected) {
- // success
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsValueTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsValueTester.java
deleted file mode 100644
index 4b0d51a..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapContainsValueTester.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.CollectionSize.ZERO;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_QUERIES;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-/**
- * Tester for {@link Multimap#containsValue}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapContainsValueTester<K, V>
- extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- @CollectionSize.Require(absent = ZERO)
- public void testContainsValueYes() {
- assertTrue(multimap().containsValue(sampleValues().e0));
- }
-
- public void testContainsValueNo() {
- assertFalse(multimap().containsValue(sampleValues().e3));
- }
-
- @MapFeature.Require(ALLOWS_NULL_VALUES)
- @CollectionSize.Require(absent = ZERO)
- public void testContainsNullValueYes() {
- initMultimapWithNullValue();
- assertTrue(multimap().containsValue(null));
- }
-
- @MapFeature.Require(ALLOWS_NULL_QUERIES)
- public void testContainsNullValueNo() {
- assertFalse(multimap().containsValue(null));
- }
-
- @MapFeature.Require(absent = ALLOWS_NULL_QUERIES)
- public void testContainsNullValueFails() {
- try {
- multimap().containsValue(null);
- fail("Expected NullPointerException");
- } catch (NullPointerException expected) {
- // success
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapGetTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapGetTester.java
deleted file mode 100644
index f57928a..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapGetTester.java
+++ /dev/null
@@ -1,122 +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.Helpers.assertContentsAnyOrder;
-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_QUERIES;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
-import static org.truth0.Truth.ASSERT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Collection;
-
-/**
- * Tests for {@link Multimap#get(Object)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapGetTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- public void testGetEmpty() {
- Collection<V> result = multimap().get(sampleKeys().e3);
- assertTrue(result.isEmpty());
- assertEquals(0, result.size());
- }
-
- @CollectionSize.Require(absent = ZERO)
- public void testGetNonEmpty() {
- Collection<V> result = multimap().get(sampleKeys().e0);
- assertFalse(result.isEmpty());
- assertContentsAnyOrder(result, sampleValues().e0);
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testGetPropagatesRemove() {
- Collection<V> result = multimap().get(sampleKeys().e0);
- assertTrue(result.remove(sampleValues().e0));
- assertFalse(multimap().containsKey(sampleKeys().e0));
- assertTrue(result.isEmpty());
- assertTrue(multimap().get(sampleKeys().e0).isEmpty());
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require({ SUPPORTS_REMOVE, SUPPORTS_PUT })
- public void testGetRemoveThenAddPropagates() {
- int oldSize = getNumElements();
-
- K k0 = sampleKeys().e0;
- V v0 = sampleValues().e0;
-
- Collection<V> result = multimap().get(k0);
- assertTrue(result.remove(v0));
-
- assertFalse(multimap().containsKey(k0));
- assertFalse(multimap().containsEntry(k0, v0));
- ASSERT.that(result).isEmpty();
-
- V v1 = sampleValues().e1;
- V v2 = sampleValues().e2;
-
- assertTrue(result.add(v1));
- assertTrue(result.add(v2));
-
- ASSERT.that(result).has().allOf(v1, v2);
- ASSERT.that(multimap().get(k0)).has().allOf(v1, v2);
- assertTrue(multimap().containsKey(k0));
- assertFalse(multimap().containsEntry(k0, v0));
- assertTrue(multimap().containsEntry(k0, v2));
- assertEquals(oldSize + 1, multimap().size());
- }
-
- @MapFeature.Require(ALLOWS_NULL_KEYS)
- @CollectionSize.Require(absent = ZERO)
- public void testGetNullPresent() {
- initMultimapWithNullKey();
- ASSERT.that(multimap().get(null)).has().item(getValueForNullKey());
- }
-
- @MapFeature.Require(ALLOWS_NULL_QUERIES)
- public void testGetNullAbsent() {
- ASSERT.that(multimap().get(null)).isEmpty();
- }
-
- @MapFeature.Require(absent = ALLOWS_NULL_QUERIES)
- public void testGetNullForbidden() {
- try {
- multimap().get(null);
- fail("Expected NullPointerException");
- } catch (NullPointerException expected) {
- // success
- }
- }
-
- @MapFeature.Require(ALLOWS_NULL_VALUES)
- @CollectionSize.Require(absent = ZERO)
- public void testGetWithNullValue() {
- initMultimapWithNullValue();
- ASSERT.that(multimap().get(getKeyForNullValue()))
- .has().item(null);
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java
deleted file mode 100644
index 39acf99..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutIterableTester.java
+++ /dev/null
@@ -1,76 +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_PUT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Collections;
-import java.util.Iterator;
-
-/**
- * Tests for {@link Multimap#putAll(Object, Iterable)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapPutIterableTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutAllNonEmptyOnPresentKey() {
- multimap().putAll(sampleKeys().e0, new Iterable<V>() {
- @Override
- public Iterator<V> iterator() {
- return Lists.newArrayList(sampleValues().e3, sampleValues().e4).iterator();
- }
- });
- assertGet(sampleKeys().e0, sampleValues().e0, sampleValues().e3, sampleValues().e4);
- }
-
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutAllNonEmptyOnAbsentKey() {
- multimap().putAll(sampleKeys().e3, new Iterable<V>() {
- @Override
- public Iterator<V> iterator() {
- return Lists.newArrayList(sampleValues().e3, sampleValues().e4).iterator();
- }
- });
- assertGet(sampleKeys().e3, sampleValues().e3, sampleValues().e4);
- }
-
- private static final Object[] EMPTY = new Object[0];
-
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutAllEmptyIterableOnAbsentKey() {
- Iterable<V> iterable = Collections.emptyList();
-
- multimap().putAll(sampleKeys().e3, iterable);
- expectUnchanged();
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutAllEmptyIterableOnPresentKey() {
- multimap().putAll(sampleKeys().e0, Collections.<V>emptyList());
- expectUnchanged();
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutTester.java
deleted file mode 100644
index 9e113cf..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapPutTester.java
+++ /dev/null
@@ -1,194 +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.ALLOWS_NULL_KEYS;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
-import static org.truth0.Truth.ASSERT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-
-/**
- * Tester for {@link Multimap#put}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapPutTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutEmpty() {
- int size = getNumElements();
-
- K key = sampleKeys().e3;
- V value = sampleValues().e3;
-
- assertGet(key, ImmutableList.<V>of());
-
- assertTrue(multimap().put(key, value));
-
- assertGet(key, value);
- assertEquals(size + 1, multimap().size());
- }
-
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(absent = ZERO)
- public void testPutPresent() {
- int size = getNumElements();
-
- K key = sampleKeys().e0;
- V oldValue = sampleValues().e0;
- V newValue = sampleValues().e3;
-
- assertGet(key, oldValue);
-
- assertTrue(multimap().put(key, newValue));
-
- assertGet(key, oldValue, newValue);
- assertEquals(size + 1, multimap().size());
- }
-
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutTwoElements() {
- int size = getNumElements();
-
- K key = sampleKeys().e0;
- V v1 = sampleValues().e3;
- V v2 = sampleValues().e4;
-
- List<V> values = Helpers.copyToList(multimap().get(key));
-
- assertTrue(multimap().put(key, v1));
- assertTrue(multimap().put(key, v2));
-
- values.add(v1);
- values.add(v2);
-
- assertGet(key, values);
- assertEquals(size + 2, multimap().size());
- }
-
- @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
- public void testPutNullValue() {
- int size = getNumElements();
-
- multimap().put(sampleKeys().e3, null);
-
- assertGet(sampleKeys().e3, Lists.newArrayList((V)null)); // ImmutableList.of can't take null.
- assertEquals(size + 1, multimap().size());
- }
-
- @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS})
- public void testPutNullKey() {
- int size = getNumElements();
-
- multimap().put(null, sampleValues().e3);
-
- assertGet(null, sampleValues().e3);
- assertEquals(size + 1, multimap().size());
- }
-
- @MapFeature.Require(SUPPORTS_PUT)
- public void testPutNotPresentKeyPropagatesToGet() {
- int size = getNumElements();
- Collection<V> collection = multimap().get(sampleKeys().e3);
- ASSERT.that(collection).isEmpty();
- multimap().put(sampleKeys().e3, sampleValues().e3);
- ASSERT.that(collection).has().item(sampleValues().e3);
- assertEquals(size + 1, multimap().size());
- }
-
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(absent = ZERO)
- public void testPutPresentKeyPropagatesToGet() {
- List<K> keys = Helpers.copyToList(multimap().keySet());
- for (K key : keys) {
- resetContainer();
-
- int size = getNumElements();
-
- Collection<V> collection = multimap().get(key);
- Collection<V> expectedCollection = Helpers.copyToList(collection);
-
- multimap().put(key, sampleValues().e3);
- expectedCollection.add(sampleValues().e3);
- ASSERT.that(collection).has().allFrom(expectedCollection);
- assertEquals(size + 1, multimap().size());
- }
- }
-
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(absent = ZERO)
- public void testPutPresentKeyPropagatesToAsMapGet() {
- List<K> keys = Helpers.copyToList(multimap().keySet());
- for (K key : keys) {
- resetContainer();
-
- int size = getNumElements();
-
- Collection<V> collection = multimap().asMap().get(key);
- assertNotNull(collection);
- Collection<V> expectedCollection = Helpers.copyToList(collection);
-
- multimap().put(key, sampleValues().e3);
- expectedCollection.add(sampleValues().e3);
- ASSERT.that(collection).has().allFrom(expectedCollection);
- assertEquals(size + 1, multimap().size());
- }
- }
-
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(absent = ZERO)
- public void testPutPresentKeyPropagatesToAsMapEntrySet() {
- List<K> keys = Helpers.copyToList(multimap().keySet());
- for (K key : keys) {
- resetContainer();
-
- int size = getNumElements();
-
- Iterator<Entry<K, Collection<V>>> asMapItr = multimap().asMap().entrySet().iterator();
- Collection<V> collection = null;
- while (asMapItr.hasNext()) {
- Entry<K, Collection<V>> asMapEntry = asMapItr.next();
- if (key.equals(asMapEntry.getKey())) {
- collection = asMapEntry.getValue();
- break;
- }
- }
- assertNotNull(collection);
- Collection<V> expectedCollection = Helpers.copyToList(collection);
-
- multimap().put(key, sampleValues().e3);
- expectedCollection.add(sampleValues().e3);
- ASSERT.that(collection).has().allFrom(expectedCollection);
- assertEquals(size + 1, multimap().size());
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveAllTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveAllTester.java
deleted file mode 100644
index 7c209a7..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveAllTester.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.SEVERAL;
-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_QUERIES;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
-import static org.truth0.Truth.ASSERT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Collection;
-
-/**
- * Tests for {@link Multimap#removeAll(Object)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapRemoveAllTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testRemoveAllAbsentKey() {
- ASSERT.that(multimap().removeAll(sampleKeys().e3)).isEmpty();
- expectUnchanged();
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testRemoveAllPresentKey() {
- ASSERT.that(multimap().removeAll(sampleKeys().e0))
- .has().allOf(sampleValues().e0).inOrder();
- expectMissing(samples.e0);
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testRemoveAllPropagatesToGet() {
- Collection<V> getResult = multimap().get(sampleKeys().e0);
-
- multimap().removeAll(sampleKeys().e0);
-
- ASSERT.that(getResult).isEmpty();
- expectMissing(samples.e0);
- }
-
- @CollectionSize.Require(SEVERAL)
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testRemoveAllMultipleValues() {
- resetContainer(
- Helpers.mapEntry(sampleKeys().e0, sampleValues().e0),
- Helpers.mapEntry(sampleKeys().e0, sampleValues().e1),
- Helpers.mapEntry(sampleKeys().e0, sampleValues().e2));
-
- ASSERT.that(multimap().removeAll(sampleKeys().e0))
- .has().allOf(sampleValues().e0, sampleValues().e1, sampleValues().e2);
- assertTrue(multimap().isEmpty());
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require({ SUPPORTS_REMOVE, ALLOWS_NULL_KEYS })
- public void testRemoveAllNullKeyPresent() {
- initMultimapWithNullKey();
-
- ASSERT.that(multimap().removeAll(null)).has().allOf(getValueForNullKey()).inOrder();
-
- expectMissing(Helpers.mapEntry((K) null, getValueForNullKey()));
- }
-
- @MapFeature.Require({ SUPPORTS_REMOVE, ALLOWS_NULL_QUERIES })
- public void testRemoveAllNullKeyAbsent() {
- ASSERT.that(multimap().removeAll(null)).isEmpty();
- expectUnchanged();
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveEntryTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveEntryTester.java
deleted file mode 100644
index 7245f77..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapRemoveEntryTester.java
+++ /dev/null
@@ -1,187 +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.ALLOWS_NULL_KEYS;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_QUERIES;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
-import static org.truth0.Truth.ASSERT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-
-/**
- * Tests for {@link Multimap#remove(Object, Object)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapRemoveEntryTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testRemoveAbsent() {
- assertFalse(multimap().remove(sampleKeys().e0, sampleValues().e1));
- expectUnchanged();
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require(SUPPORTS_REMOVE)
- public void testRemovePresent() {
- assertTrue(multimap().remove(sampleKeys().e0, sampleValues().e0));
-
- expectMissing(samples.e0);
- assertGet(sampleKeys().e0, ImmutableList.<V>of());
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require({ SUPPORTS_REMOVE, ALLOWS_NULL_KEYS })
- public void testRemoveNullKeyPresent() {
- initMultimapWithNullKey();
-
- assertTrue(multimap().remove(null, getValueForNullKey()));
-
- expectMissing(Helpers.mapEntry((K) null, getValueForNullKey()));
- assertGet(getKeyForNullValue(), ImmutableList.<V>of());
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require({ SUPPORTS_REMOVE, ALLOWS_NULL_VALUES })
- public void testRemoveNullValuePresent() {
- initMultimapWithNullValue();
-
- assertTrue(multimap().remove(getKeyForNullValue(), null));
-
- expectMissing(Helpers.mapEntry(getKeyForNullValue(), (V) null));
- assertGet(getKeyForNullValue(), ImmutableList.<V>of());
- }
-
- @MapFeature.Require({ SUPPORTS_REMOVE, ALLOWS_NULL_QUERIES})
- public void testRemoveNullKeyAbsent() {
- assertFalse(multimap().remove(null, sampleValues().e0));
- expectUnchanged();
- }
-
- @MapFeature.Require({ SUPPORTS_REMOVE, ALLOWS_NULL_QUERIES})
- public void testRemoveNullValueAbsent() {
- assertFalse(multimap().remove(sampleKeys().e0, null));
- expectUnchanged();
- }
-
- @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_QUERIES)
- public void testRemoveNullValueForbidden() {
- try {
- multimap().remove(sampleKeys().e0, null);
- fail("Expected NullPointerException");
- } catch (NullPointerException expected) {
- // success
- }
- expectUnchanged();
- }
-
- @MapFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_QUERIES)
- public void testRemoveNullKeyForbidden() {
- try {
- multimap().remove(null, sampleValues().e0);
- fail("Expected NullPointerException");
- } catch (NullPointerException expected) {
- // success
- }
- expectUnchanged();
- }
-
- @MapFeature.Require(SUPPORTS_REMOVE)
- @CollectionSize.Require(absent = ZERO)
- public void testRemovePropagatesToGet() {
- List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries());
- for (Entry<K, V> entry : entries) {
- resetContainer();
-
- K key = entry.getKey();
- V value = entry.getValue();
- Collection<V> collection = multimap().get(key);
- assertNotNull(collection);
- Collection<V> expectedCollection = Helpers.copyToList(collection);
-
- multimap().remove(key, value);
- expectedCollection.remove(value);
-
- ASSERT.that(collection).has().allFrom(expectedCollection);
- assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
- }
- }
-
- @MapFeature.Require(SUPPORTS_REMOVE)
- @CollectionSize.Require(absent = ZERO)
- public void testRemovePropagatesToAsMap() {
- List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries());
- for (Entry<K, V> entry : entries) {
- resetContainer();
-
- K key = entry.getKey();
- V value = entry.getValue();
- Collection<V> collection = multimap().asMap().get(key);
- assertNotNull(collection);
- Collection<V> expectedCollection = Helpers.copyToList(collection);
-
- multimap().remove(key, value);
- expectedCollection.remove(value);
-
- ASSERT.that(collection).has().allFrom(expectedCollection);
- assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
- }
- }
-
- @MapFeature.Require(SUPPORTS_REMOVE)
- @CollectionSize.Require(absent = ZERO)
- public void testRemovePropagatesToAsMapEntrySet() {
- List<Entry<K, V>> entries = Helpers.copyToList(multimap().entries());
- for (Entry<K, V> entry : entries) {
- resetContainer();
-
- K key = entry.getKey();
- V value = entry.getValue();
-
- Iterator<Entry<K, Collection<V>>> asMapItr = multimap().asMap().entrySet().iterator();
- Collection<V> collection = null;
- while (asMapItr.hasNext()) {
- Entry<K, Collection<V>> asMapEntry = asMapItr.next();
- if (key.equals(asMapEntry.getKey())) {
- collection = asMapEntry.getValue();
- break;
- }
- }
- assertNotNull(collection);
- Collection<V> expectedCollection = Helpers.copyToList(collection);
-
- multimap().remove(key, value);
- expectedCollection.remove(value);
-
- ASSERT.that(collection).has().allFrom(expectedCollection);
- assertEquals(!expectedCollection.isEmpty(), multimap().containsKey(key));
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapReplaceValuesTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapReplaceValuesTester.java
deleted file mode 100644
index 85dc6b9..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapReplaceValuesTester.java
+++ /dev/null
@@ -1,93 +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_PUT;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Tests for {@link Multimap#replaceValues(Object, Iterable)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapReplaceValuesTester<K, V>
- extends AbstractMultimapTester<K, V, Multimap<K, V>> {
- @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
- public void testReplaceEmptyValues() {
- int size = multimap().size();
- K key = sampleKeys().e3;
- @SuppressWarnings("unchecked")
- List<V> values = Arrays.asList(sampleValues().e0, sampleValues().e2, sampleValues().e3);
- multimap().replaceValues(key, values);
- assertGet(key, values);
- assertEquals(size + values.size(), multimap().size());
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
- public void testReplaceNonEmptyValues() {
- List<K> keys = Helpers.copyToList(multimap().keySet());
- @SuppressWarnings("unchecked")
- List<V> values = Arrays.asList(sampleValues().e0, sampleValues().e2, sampleValues().e3);
-
- for (K k : keys) {
- resetContainer();
-
- int size = multimap().size();
- Collection<V> oldKeyValues = Helpers.copyToList(multimap().get(k));
- multimap().replaceValues(k, values);
- assertGet(k, values);
- assertEquals(size + values.size() - oldKeyValues.size(), multimap().size());
- }
- }
-
- @MapFeature.Require(absent = SUPPORTS_REMOVE)
- @CollectionSize.Require(absent = ZERO)
- public void testReplaceValuesRemoveNotSupported() {
- List<V> values = Collections.singletonList(sampleValues().e3);
- try {
- multimap().replaceValues(sampleKeys().e0, values);
- fail("Expected UnsupportedOperationException");
- } catch (UnsupportedOperationException expected) {
- // success
- }
- }
-
- @MapFeature.Require(absent = SUPPORTS_PUT)
- public void testReplaceValuesPutNotSupported() {
- List<V> values = Collections.singletonList(sampleValues().e3);
- try {
- multimap().replaceValues(sampleKeys().e0, values);
- fail("Expected UnsupportedOperationException");
- } catch (UnsupportedOperationException expected) {
- // success
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapSizeTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapSizeTester.java
deleted file mode 100644
index 0f63789..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapSizeTester.java
+++ /dev/null
@@ -1,91 +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.Helpers.mapEntry;
-import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
-import static com.google.common.collect.testing.features.CollectionSize.ZERO;
-import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Collection;
-import java.util.Map.Entry;
-
-/**
- * Tester for the {@code size} methods of {@code Multimap} and its views.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MultimapSizeTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
-
- public void testSize() {
- int expectedSize = getNumElements();
- Multimap<K, V> multimap = multimap();
- assertEquals(expectedSize, multimap.size());
-
- int size = 0;
- for (Entry<K, V> entry : multimap.entries()) {
- assertTrue(multimap.containsEntry(entry.getKey(), entry.getValue()));
- size++;
- }
- assertEquals(expectedSize, size);
-
- int size2 = 0;
- for (Entry<K, Collection<V>> entry2 : multimap.asMap().entrySet()) {
- size2 += entry2.getValue().size();
- }
- assertEquals(expectedSize, size2);
- }
-
- @CollectionSize.Require(ZERO)
- public void testIsEmptyYes() {
- assertTrue(multimap().isEmpty());
- }
-
- @CollectionSize.Require(absent = ZERO)
- public void testIsEmptyNo() {
- assertFalse(multimap().isEmpty());
- }
-
- @CollectionSize.Require(absent = ZERO)
- @MapFeature.Require(ALLOWS_NULL_KEYS)
- public void testSizeNullEntry() {
- initMultimapWithNullKey();
- assertEquals(getNumElements(), multimap().size());
- assertFalse(multimap().isEmpty());
- }
-
- @CollectionSize.Require(SEVERAL)
- public void testSizeMultipleValues() {
- resetContainer(
- mapEntry(sampleKeys().e0, sampleValues().e0),
- mapEntry(sampleKeys().e0, sampleValues().e1),
- mapEntry(sampleKeys().e0, sampleValues().e2));
-
- assertEquals(3, multimap().size());
- assertEquals(3, multimap().entries().size());
- assertEquals(3, multimap().keys().size());
-
- assertEquals(1, multimap().keySet().size());
- assertEquals(1, multimap().asMap().size());
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultimapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/google/MultimapTestSuiteBuilder.java
deleted file mode 100644
index b3886cb..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultimapTestSuiteBuilder.java
+++ /dev/null
@@ -1,600 +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.base.Preconditions.checkArgument;
-import static com.google.common.collect.testing.Helpers.mapEntry;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multiset;
-import com.google.common.collect.testing.AbstractTester;
-import com.google.common.collect.testing.CollectionTestSuiteBuilder;
-import com.google.common.collect.testing.DerivedGenerator;
-import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.MapTestSuiteBuilder;
-import com.google.common.collect.testing.OneSizeTestContainerGenerator;
-import com.google.common.collect.testing.PerCollectionSizeTestSuiteBuilder;
-import com.google.common.collect.testing.SampleElements;
-import com.google.common.collect.testing.TestCollectionGenerator;
-import com.google.common.collect.testing.TestMapGenerator;
-import com.google.common.collect.testing.TestSubjectGenerator;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.features.MapFeature;
-import com.google.common.testing.SerializableTester;
-
-import junit.framework.TestSuite;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * Creates, based on your criteria, a JUnit test suite that exhaustively tests
- * a {@code Multimap} implementation.
- *
- * @author Louis Wasserman
- */
-public class MultimapTestSuiteBuilder<K, V, M extends Multimap<K, V>> extends
- PerCollectionSizeTestSuiteBuilder<
- MultimapTestSuiteBuilder<K, V, M>,
- TestMultimapGenerator<K, V, M>, M, Map.Entry<K, V>> {
-
- public static <K, V, M extends Multimap<K, V>> MultimapTestSuiteBuilder<K, V, M> using(
- TestMultimapGenerator<K, V, M> generator) {
- return new MultimapTestSuiteBuilder<K, V, M>().usingGenerator(generator);
- }
-
- // Class parameters must be raw.
- @Override
- protected List<Class<? extends AbstractTester>> getTesters() {
- return ImmutableList.<Class<? extends AbstractTester>> of(
- MultimapSizeTester.class,
- MultimapContainsKeyTester.class,
- MultimapContainsValueTester.class,
- MultimapContainsEntryTester.class,
- MultimapGetTester.class,
- MultimapPutTester.class,
- MultimapPutIterableTester.class,
- MultimapReplaceValuesTester.class,
- MultimapRemoveEntryTester.class,
- MultimapRemoveAllTester.class);
- }
-
- @Override
- protected List<TestSuite> createDerivedSuites(
- FeatureSpecificTestSuiteBuilder<
- ?,
- ? extends OneSizeTestContainerGenerator<M, Map.Entry<K, V>>>
- parentBuilder) {
- // TODO: Once invariant support is added, supply invariants to each of the
- // derived suites, to check that mutations to the derived collections are
- // reflected in the underlying map.
-
- List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
-
- if (parentBuilder.getFeatures().contains(CollectionFeature.SERIALIZABLE)) {
- derivedSuites.add(MultimapTestSuiteBuilder.using(
- new ReserializedMultimapGenerator<K, V, M>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeReserializedMultimapFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + " reserialized")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
- }
-
- derivedSuites.add(MapTestSuiteBuilder.using(
- new AsMapGenerator<K, V, M>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeAsMapFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".asMap")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
-
- derivedSuites.add(computeEntriesTestSuite(parentBuilder));
- derivedSuites.add(computeMultimapGetTestSuite(parentBuilder));
- derivedSuites.add(computeKeysTestSuite(parentBuilder));
-
- return derivedSuites;
- }
-
- TestSuite computeValuesTestSuite(
- FeatureSpecificTestSuiteBuilder<?, ?
- extends OneSizeTestContainerGenerator<M, Map.Entry<K, V>>> parentBuilder) {
- return CollectionTestSuiteBuilder.using(
- new ValuesGenerator<K, V, M>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeValuesFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".entries")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- TestSuite computeEntriesTestSuite(
- FeatureSpecificTestSuiteBuilder<?, ?
- extends OneSizeTestContainerGenerator<M, Map.Entry<K, V>>> parentBuilder) {
- return CollectionTestSuiteBuilder.using(
- new EntriesGenerator<K, V, M>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeEntriesFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".entries")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- TestSuite computeMultimapGetTestSuite(
- FeatureSpecificTestSuiteBuilder<?, ? extends
- OneSizeTestContainerGenerator<M, Map.Entry<K, V>>> parentBuilder) {
- return CollectionTestSuiteBuilder.using(
- new MultimapGetGenerator<K, V, M>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeMultimapGetFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".get[key]")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- TestSuite computeKeysTestSuite(
- FeatureSpecificTestSuiteBuilder<?, ? extends
- OneSizeTestContainerGenerator<M, Map.Entry<K, V>>> parentBuilder) {
- return MultisetTestSuiteBuilder.using(
- new KeysGenerator<K, V, M>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeKeysFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".keys")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- static Set<Feature<?>> computeDerivedCollectionFeatures(Set<Feature<?>> multimapFeatures) {
- Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
- if (!derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- }
- if (derivedFeatures.remove(MapFeature.ALLOWS_NULL_QUERIES)) {
- derivedFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
- }
- if (derivedFeatures.remove(MapFeature.SUPPORTS_REMOVE)) {
- derivedFeatures.add(CollectionFeature.SUPPORTS_REMOVE);
- }
- return derivedFeatures;
- }
-
- static Set<Feature<?>> computeEntriesFeatures(
- Set<Feature<?>> multimapFeatures) {
- return computeDerivedCollectionFeatures(multimapFeatures);
- }
-
- static Set<Feature<?>> computeValuesFeatures(
- Set<Feature<?>> multimapFeatures) {
- return computeDerivedCollectionFeatures(multimapFeatures);
- }
-
- static Set<Feature<?>> computeKeysFeatures(
- Set<Feature<?>> multimapFeatures) {
- Set<Feature<?>> result = computeDerivedCollectionFeatures(multimapFeatures);
- if (multimapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) {
- result.add(CollectionFeature.ALLOWS_NULL_VALUES);
- }
- return result;
- }
-
- private static Set<Feature<?>> computeReserializedMultimapFeatures(
- Set<Feature<?>> multimapFeatures) {
- Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);
- return derivedFeatures;
- }
-
- private static Set<Feature<?>> computeAsMapFeatures(
- Set<Feature<?>> multimapFeatures) {
- Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
- derivedFeatures.remove(MapFeature.GENERAL_PURPOSE);
- derivedFeatures.remove(MapFeature.SUPPORTS_PUT);
- derivedFeatures.remove(MapFeature.ALLOWS_NULL_VALUES);
- derivedFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION);
- if (!derivedFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- }
- return derivedFeatures;
- }
-
- private static final Multimap<Feature<?>, Feature<?>> GET_FEATURE_MAP = ImmutableMultimap
- .<Feature<?>, Feature<?>> builder()
- .put(
- MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION)
- .put(MapFeature.GENERAL_PURPOSE, CollectionFeature.GENERAL_PURPOSE)
- .put(MapFeature.ALLOWS_NULL_QUERIES, CollectionFeature.ALLOWS_NULL_QUERIES)
- .put(MapFeature.ALLOWS_NULL_VALUES, CollectionFeature.ALLOWS_NULL_VALUES)
- .put(MapFeature.SUPPORTS_REMOVE, CollectionFeature.SUPPORTS_REMOVE)
- .put(MapFeature.SUPPORTS_PUT, CollectionFeature.SUPPORTS_ADD)
- .build();
-
- Set<Feature<?>> computeMultimapGetFeatures(
- Set<Feature<?>> multimapFeatures) {
- Set<Feature<?>> derivedFeatures = Helpers.copyToSet(multimapFeatures);
- for (Map.Entry<Feature<?>, Feature<?>> entry : GET_FEATURE_MAP.entries()) {
- if (derivedFeatures.contains(entry.getKey())) {
- derivedFeatures.add(entry.getValue());
- }
- }
- if (!derivedFeatures.contains(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- }
- derivedFeatures.removeAll(GET_FEATURE_MAP.keySet());
- return derivedFeatures;
- }
-
- private static class AsMapGenerator<K, V, M extends Multimap<K, V>> implements
- TestMapGenerator<K, Collection<V>>, DerivedGenerator {
- private final OneSizeTestContainerGenerator<M, Map.Entry<K, V>> multimapGenerator;
-
- public AsMapGenerator(
- OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator) {
- this.multimapGenerator = multimapGenerator;
- }
-
- @Override
- public TestSubjectGenerator<?> getInnerGenerator() {
- return multimapGenerator;
- }
-
- private Collection<V> createCollection(V v) {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .createCollection(Collections.singleton(v));
- }
-
- @Override
- public SampleElements<Entry<K, Collection<V>>> samples() {
- SampleElements<K> sampleKeys =
- ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleKeys();
- SampleElements<V> sampleValues =
- ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleValues();
- return new SampleElements<Entry<K, Collection<V>>>(
- mapEntry(sampleKeys.e0, createCollection(sampleValues.e0)),
- mapEntry(sampleKeys.e1, createCollection(sampleValues.e1)),
- mapEntry(sampleKeys.e2, createCollection(sampleValues.e2)),
- mapEntry(sampleKeys.e3, createCollection(sampleValues.e3)),
- mapEntry(sampleKeys.e4, createCollection(sampleValues.e4)));
- }
-
- @Override
- public Map<K, Collection<V>> create(Object... elements) {
- Set<K> keySet = new HashSet<K>();
- List<Map.Entry<K, V>> builder = new ArrayList<Entry<K, V>>();
- for (Object o : elements) {
- Map.Entry<K, Collection<V>> entry = (Entry<K, Collection<V>>) o;
- keySet.add(entry.getKey());
- for (V v : entry.getValue()) {
- builder.add(mapEntry(entry.getKey(), v));
- }
- }
- checkArgument(keySet.size() == elements.length, "Duplicate keys");
- return multimapGenerator.create(builder.toArray()).asMap();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Entry<K, Collection<V>>[] createArray(int length) {
- return new Entry[length];
- }
-
- @Override
- public Iterable<Entry<K, Collection<V>>> order(List<Entry<K, Collection<V>>> insertionOrder) {
- Map<K, Collection<V>> map = new HashMap<K, Collection<V>>();
- List<Map.Entry<K, V>> builder = new ArrayList<Entry<K, V>>();
- for (Entry<K, Collection<V>> entry : insertionOrder) {
- for (V v : entry.getValue()) {
- builder.add(mapEntry(entry.getKey(), v));
- }
- map.put(entry.getKey(), entry.getValue());
- }
- Iterable<Map.Entry<K, V>> ordered = multimapGenerator.order(builder);
- LinkedHashMap<K, Collection<V>> orderedMap = new LinkedHashMap<K, Collection<V>>();
- for (Map.Entry<K, V> entry : ordered) {
- orderedMap.put(entry.getKey(), map.get(entry.getKey()));
- }
- return orderedMap.entrySet();
- }
-
- @Override
- public K[] createKeyArray(int length) {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .createKeyArray(length);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Collection<V>[] createValueArray(int length) {
- return new Collection[length];
- }
- }
-
- static class EntriesGenerator<K, V, M extends Multimap<K, V>>
- implements TestCollectionGenerator<Entry<K, V>>, DerivedGenerator {
- private final OneSizeTestContainerGenerator<M, Map.Entry<K, V>> multimapGenerator;
-
- public EntriesGenerator(
- OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator) {
- this.multimapGenerator = multimapGenerator;
- }
-
- @Override
- public TestSubjectGenerator<?> getInnerGenerator() {
- return multimapGenerator;
- }
-
- @Override
- public SampleElements<Entry<K, V>> samples() {
- return multimapGenerator.samples();
- }
-
- @Override
- public Collection<Entry<K, V>> create(Object... elements) {
- return multimapGenerator.create(elements).entries();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Entry<K, V>[] createArray(int length) {
- return new Entry[length];
- }
-
- @Override
- public Iterable<Entry<K, V>> order(List<Entry<K, V>> insertionOrder) {
- return multimapGenerator.order(insertionOrder);
- }
- }
-
- static class ValuesGenerator<K, V, M extends Multimap<K, V>>
- implements TestCollectionGenerator<V> {
- private final OneSizeTestContainerGenerator<M, Map.Entry<K, V>> multimapGenerator;
-
- public ValuesGenerator(
- OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator) {
- this.multimapGenerator = multimapGenerator;
- }
-
- @Override
- public SampleElements<V> samples() {
- return
- ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleValues();
- }
-
- @Override
- public Collection<V> create(Object... elements) {
- K k =
- ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleKeys().e0;
- Entry<K, V>[] entries = new Entry[elements.length];
- for (int i = 0; i < elements.length; i++) {
- entries[i] = mapEntry(k, (V) elements[i]);
- }
- return multimapGenerator.create(entries).values();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public V[] createArray(int length) {
- return ((TestMultimapGenerator<K, V, M>)
- multimapGenerator.getInnerGenerator()).createValueArray(length);
- }
-
- @Override
- public Iterable<V> order(List<V> insertionOrder) {
- K k =
- ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleKeys().e0;
- List<Entry<K, V>> entries = new ArrayList<Entry<K, V>>();
- for (V v : insertionOrder) {
- entries.add(mapEntry(k, v));
- }
- Iterable<Entry<K, V>> ordered = multimapGenerator.order(entries);
- List<V> orderedValues = new ArrayList<V>();
- for (Entry<K, V> entry : ordered) {
- orderedValues.add(entry.getValue());
- }
- return orderedValues;
- }
- }
-
- static class KeysGenerator<K, V, M extends Multimap<K, V>> implements
- TestMultisetGenerator<K>, DerivedGenerator {
- private final OneSizeTestContainerGenerator<M, Map.Entry<K, V>> multimapGenerator;
-
- public KeysGenerator(
- OneSizeTestContainerGenerator<M, Entry<K, V>> multimapGenerator) {
- this.multimapGenerator = multimapGenerator;
- }
-
- @Override
- public TestSubjectGenerator<?> getInnerGenerator() {
- return multimapGenerator;
- }
-
- @Override
- public SampleElements<K> samples() {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator()).sampleKeys();
- }
-
- @Override
- public Multiset<K> create(Object... elements) {
- /*
- * This is nasty and complicated, but it's the only way to make sure keys get mapped to enough
- * distinct values.
- */
- Map.Entry[] entries = new Map.Entry[elements.length];
- Map<K, Iterator<V>> valueIterators = new HashMap<K, Iterator<V>>();
- for (int i = 0; i < elements.length; i++) {
- @SuppressWarnings("unchecked")
- K key = (K) elements[i];
-
- Iterator<V> valueItr = valueIterators.get(key);
- if (valueItr == null) {
- valueIterators.put(key, valueItr = sampleValuesIterator());
- }
- entries[i] = mapEntry((K) elements[i], valueItr.next());
- }
- return multimapGenerator.create(entries).keys();
- }
-
- private Iterator<V> sampleValuesIterator() {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator
- .getInnerGenerator()).sampleValues().iterator();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public K[] createArray(int length) {
- return ((TestMultimapGenerator<K, V, M>)
- multimapGenerator.getInnerGenerator()).createKeyArray(length);
- }
-
- @Override
- public Iterable<K> order(List<K> insertionOrder) {
- Iterator<V> valueIter = sampleValuesIterator();
- List<Entry<K, V>> entries = new ArrayList<Entry<K, V>>();
- for (K k : insertionOrder) {
- entries.add(mapEntry(k, valueIter.next()));
- }
- Iterable<Entry<K, V>> ordered = multimapGenerator.order(entries);
- List<K> orderedValues = new ArrayList<K>();
- for (Entry<K, V> entry : ordered) {
- orderedValues.add(entry.getKey());
- }
- return orderedValues;
- }
- }
-
- static class MultimapGetGenerator<K, V, M extends Multimap<K, V>>
- implements TestCollectionGenerator<V> {
- private final OneSizeTestContainerGenerator<M, Map.Entry<K, V>> multimapGenerator;
-
- public MultimapGetGenerator(
- OneSizeTestContainerGenerator<
- M, Map.Entry<K, V>> multimapGenerator) {
- this.multimapGenerator = multimapGenerator;
- }
-
- @Override
- public SampleElements<V> samples() {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .sampleValues();
- }
-
- @Override
- public V[] createArray(int length) {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .createValueArray(length);
- }
-
- @Override
- public Iterable<V> order(List<V> insertionOrder) {
- K k = ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .sampleKeys().e0;
- List<Entry<K, V>> entries = new ArrayList<Entry<K, V>>();
- for (V v : insertionOrder) {
- entries.add(mapEntry(k, v));
- }
- Iterable<Entry<K, V>> orderedEntries = multimapGenerator.order(entries);
- List<V> values = new ArrayList<V>();
- for (Entry<K, V> entry : orderedEntries) {
- values.add(entry.getValue());
- }
- return values;
- }
-
- @Override
- public Collection<V> create(Object... elements) {
- Entry<K, V>[] array = multimapGenerator.createArray(elements.length);
- K k = ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .sampleKeys().e0;
- for (int i = 0; i < elements.length; i++) {
- array[i] = mapEntry(k, (V) elements[i]);
- }
- return multimapGenerator.create(array).get(k);
- }
- }
-
- private static class ReserializedMultimapGenerator<K, V, M extends Multimap<K, V>>
- implements TestMultimapGenerator<K, V, M> {
- private final OneSizeTestContainerGenerator<M, Map.Entry<K, V>> multimapGenerator;
-
- public ReserializedMultimapGenerator(
- OneSizeTestContainerGenerator<
- M, Map.Entry<K, V>> multimapGenerator) {
- this.multimapGenerator = multimapGenerator;
- }
-
- @Override
- public SampleElements<Map.Entry<K, V>> samples() {
- return multimapGenerator.samples();
- }
-
- @Override
- public Map.Entry<K, V>[] createArray(int length) {
- return multimapGenerator.createArray(length);
- }
-
- @Override
- public Iterable<Map.Entry<K, V>> order(
- List<Map.Entry<K, V>> insertionOrder) {
- return multimapGenerator.order(insertionOrder);
- }
-
- @Override
- public M create(Object... elements) {
- return SerializableTester.reserialize(((TestMultimapGenerator<K, V, M>) multimapGenerator
- .getInnerGenerator()).create(elements));
- }
-
- @Override
- public K[] createKeyArray(int length) {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .createKeyArray(length);
- }
-
- @Override
- public V[] createValueArray(int length) {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .createValueArray(length);
- }
-
- @Override
- public SampleElements<K> sampleKeys() {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .sampleKeys();
- }
-
- @Override
- public SampleElements<V> sampleValues() {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .sampleValues();
- }
-
- @Override
- public Collection<V> createCollection(Iterable<? extends V> values) {
- return ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
- .createCollection(values);
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultisetIteratorTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultisetIteratorTester.java
index 8f1f70e..63082d5 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultisetIteratorTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/MultisetIteratorTester.java
@@ -18,8 +18,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.KNOWN
import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;
import com.google.common.annotations.GwtCompatible;
-import com.google.common.annotations.GwtIncompatible;
-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;
@@ -35,7 +33,7 @@ import java.util.List;
*
* @author Louis Wasserman
*/
-@GwtCompatible(emulated = true)
+@GwtCompatible
public class MultisetIteratorTester<E> extends AbstractMultisetTester<E> {
@SuppressWarnings("unchecked")
@CollectionFeature.Require({SUPPORTS_REMOVE, KNOWN_ORDER})
@@ -95,30 +93,11 @@ public class MultisetIteratorTester<E> extends AbstractMultisetTester<E> {
* Returns {@link Method} instances for the tests that assume multisets support duplicates so that
* the test of {@code Multisets.forSet()} can suppress them.
*/
- @GwtIncompatible("reflection")
public static List<Method> getIteratorDuplicateInitializingMethods() {
return Arrays.asList(
- Helpers.getMethod(MultisetIteratorTester.class, "testIteratorKnownOrder"),
- Helpers.getMethod(MultisetIteratorTester.class, "testIteratorUnknownOrder"),
- Helpers.getMethod(MultisetIteratorTester.class, "testRemovingIteratorKnownOrder"),
- Helpers.getMethod(MultisetIteratorTester.class, "testRemovingIteratorUnknownOrder"));
- }
-
- /**
- * Returns the {@link Method} instance for the test that assumes the multiset iterator supports
- * {@code remove()} so that the test for {@code Multisets.filter} can suppress it.
- */
- @GwtIncompatible("reflection")
- public static Method getIteratorKnownOrderRemoveSupportedMethod() {
- return Helpers.getMethod(MultisetIteratorTester.class, "testRemovingIteratorKnownOrder");
- }
-
- /**
- * Returns the {@link Method} instance for the test that assumes the multiset iterator supports
- * {@code remove()} so that the test for {@code Multisets.filter} can suppress it.
- */
- @GwtIncompatible("reflection")
- public static Method getIteratorUnknownOrderRemoveSupportedMethod() {
- return Helpers.getMethod(MultisetIteratorTester.class, "testRemovingIteratorUnknownOrder");
+ Platform.getMethod(MultisetIteratorTester.class, "testIteratorKnownOrder"),
+ Platform.getMethod(MultisetIteratorTester.class, "testIteratorUnknownOrder"),
+ Platform.getMethod(MultisetIteratorTester.class, "testRemovingIteratorKnownOrder"),
+ Platform.getMethod(MultisetIteratorTester.class, "testRemovingIteratorUnknownOrder"));
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultisetNavigationTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultisetNavigationTester.java
index 9c844e8..e817738 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultisetNavigationTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/MultisetNavigationTester.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Guava Authors
+ * Copyright (C) 2011 Google Inc.
*
* 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
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultisetReadsTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultisetReadsTester.java
index 9f1dd9c..c353404 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultisetReadsTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/MultisetReadsTester.java
@@ -21,11 +21,9 @@ 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.annotations.GwtIncompatible;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multisets;
-import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.WrongType;
import com.google.common.collect.testing.features.CollectionSize;
@@ -40,7 +38,7 @@ import java.util.List;
*
* @author Jared Levy
*/
-@GwtCompatible(emulated = true)
+@GwtCompatible
public class MultisetReadsTester<E> extends AbstractMultisetTester<E> {
public void testCount_0() {
assertEquals("multiset.count(missing) didn't return 0",
@@ -149,9 +147,8 @@ public class MultisetReadsTester<E> extends AbstractMultisetTester<E> {
* support duplicates so that the test of {@code Multisets.forSet()} can
* suppress them.
*/
- @GwtIncompatible("reflection")
public static List<Method> getReadsDuplicateInitializingMethods() {
return Arrays.asList(
- Helpers.getMethod(MultisetReadsTester.class, "testCount_3"));
+ Platform.getMethod(MultisetReadsTester.class, "testCount_3"));
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultisetSerializationTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultisetSerializationTester.java
deleted file mode 100644
index 2a0a633..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultisetSerializationTester.java
+++ /dev/null
@@ -1,47 +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_INCLUDING_VIEWS;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multiset;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.testing.SerializableTester;
-
-import java.util.Set;
-
-/**
- * A generic JUnit test which tests multiset-specific serialization. Can't be invoked directly;
- * please see {@link com.google.common.collect.testing.MultisetTestSuiteBuilder}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible // but no-op
-public class MultisetSerializationTester<E> extends AbstractMultisetTester<E> {
- @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS)
- public void testEntrySetSerialization() {
- Set<Multiset.Entry<E>> expected = getMultiset().entrySet();
- assertEquals(expected, SerializableTester.reserialize(expected));
- }
-
- @CollectionFeature.Require(SERIALIZABLE_INCLUDING_VIEWS)
- public void testElementSetSerialization() {
- Set<E> expected = getMultiset().elementSet();
- assertEquals(expected, SerializableTester.reserialize(expected));
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultisetTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/google/MultisetTestSuiteBuilder.java
index 1175af9..4bdbaf5 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultisetTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/MultisetTestSuiteBuilder.java
@@ -16,35 +16,12 @@
package com.google.common.collect.testing.google;
-import static com.google.common.base.Preconditions.checkArgument;
-
-import com.google.common.collect.Multiset;
-import com.google.common.collect.Multiset.Entry;
-import com.google.common.collect.Multisets;
+import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractCollectionTestSuiteBuilder;
import com.google.common.collect.testing.AbstractTester;
-import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.OneSizeTestContainerGenerator;
-import com.google.common.collect.testing.SampleElements;
-import com.google.common.collect.testing.SetTestSuiteBuilder;
-import com.google.common.collect.testing.TestSetGenerator;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.collect.testing.features.Feature;
-import com.google.common.collect.testing.testers.CollectionSerializationEqualTester;
-import com.google.common.testing.SerializableTester;
-
-import junit.framework.TestSuite;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
/**
* Creates, based on your criteria, a JUnit test suite that exhaustively tests
@@ -53,6 +30,7 @@ import java.util.Set;
* @author Jared Levy
* @author Louis Wasserman
*/
+@GwtCompatible
public class MultisetTestSuiteBuilder<E> extends
AbstractCollectionTestSuiteBuilder<MultisetTestSuiteBuilder<E>, E> {
public static <E> MultisetTestSuiteBuilder<E> using(
@@ -60,219 +38,15 @@ public class MultisetTestSuiteBuilder<E> extends
return new MultisetTestSuiteBuilder<E>().usingGenerator(generator);
}
- public enum NoRecurse implements Feature<Void> {
- NO_ENTRY_SET;
-
- @Override
- public Set<Feature<? super Void>> getImpliedFeatures() {
- return Collections.emptySet();
- }
- }
-
@Override protected List<Class<? extends AbstractTester>> getTesters() {
List<Class<? extends AbstractTester>> testers
= Helpers.copyToList(super.getTesters());
- testers.add(CollectionSerializationEqualTester.class);
testers.add(MultisetReadsTester.class);
testers.add(MultisetSetCountConditionallyTester.class);
testers.add(MultisetSetCountUnconditionallyTester.class);
testers.add(MultisetWritesTester.class);
testers.add(MultisetIteratorTester.class);
- testers.add(MultisetSerializationTester.class);
return testers;
}
-
- private static Set<Feature<?>> computeEntrySetFeatures(
- Set<Feature<?>> features) {
- Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
- derivedFeatures.addAll(features);
- derivedFeatures.remove(CollectionFeature.GENERAL_PURPOSE);
- derivedFeatures.remove(CollectionFeature.SUPPORTS_ADD);
- derivedFeatures.remove(CollectionFeature.ALLOWS_NULL_VALUES);
- derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
- if (!derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- }
- return derivedFeatures;
- }
-
- static Set<Feature<?>> computeElementSetFeatures(
- Set<Feature<?>> features) {
- Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
- derivedFeatures.addAll(features);
- derivedFeatures.remove(CollectionFeature.GENERAL_PURPOSE);
- derivedFeatures.remove(CollectionFeature.SUPPORTS_ADD);
- if (!derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- }
- return derivedFeatures;
- }
-
- private static Set<Feature<?>> computeReserializedMultisetFeatures(
- Set<Feature<?>> features) {
- Set<Feature<?>> derivedFeatures = new HashSet<Feature<?>>();
- derivedFeatures.addAll(features);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
- derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);
- return derivedFeatures;
- }
-
- @Override
- protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<
- ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>> parentBuilder) {
- List<TestSuite> derivedSuites = new ArrayList<TestSuite>(
- super.createDerivedSuites(parentBuilder));
-
- derivedSuites.add(createElementSetTestSuite(parentBuilder));
-
- if (!parentBuilder.getFeatures().contains(NoRecurse.NO_ENTRY_SET)) {
- derivedSuites.add(
- SetTestSuiteBuilder.using(new EntrySetGenerator<E>(parentBuilder.getSubjectGenerator()))
- .named(getName() + ".entrySet")
- .withFeatures(computeEntrySetFeatures(parentBuilder.getFeatures()))
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
- }
-
- if (parentBuilder.getFeatures().contains(CollectionFeature.SERIALIZABLE)) {
- derivedSuites.add(MultisetTestSuiteBuilder
- .using(new ReserializedMultisetGenerator<E>(parentBuilder.getSubjectGenerator()))
- .named(getName() + " reserialized")
- .withFeatures(computeReserializedMultisetFeatures(parentBuilder.getFeatures()))
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite());
- }
- return derivedSuites;
- }
-
- TestSuite createElementSetTestSuite(FeatureSpecificTestSuiteBuilder<
- ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>> parentBuilder) {
- return SetTestSuiteBuilder
- .using(new ElementSetGenerator<E>(parentBuilder.getSubjectGenerator()))
- .named(getName() + ".elementSet")
- .withFeatures(computeElementSetFeatures(parentBuilder.getFeatures()))
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- static class ElementSetGenerator<E> implements TestSetGenerator<E> {
- final OneSizeTestContainerGenerator<Collection<E>, E> gen;
-
- ElementSetGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
- this.gen = gen;
- }
-
- @Override
- public SampleElements<E> samples() {
- return gen.samples();
- }
-
- @Override
- public Set<E> create(Object... elements) {
- Object[] duplicated = new Object[elements.length * 2];
- for (int i = 0; i < elements.length; i++) {
- duplicated[i] = elements[i];
- duplicated[i + elements.length] = elements[i];
- }
- return ((Multiset<E>) gen.create(duplicated)).elementSet();
- }
-
- @Override
- public E[] createArray(int length) {
- return gen.createArray(length);
- }
-
- @Override
- public Iterable<E> order(List<E> insertionOrder) {
- return gen.order(new ArrayList<E>(new LinkedHashSet<E>(insertionOrder)));
- }
- }
-
- static class EntrySetGenerator<E> implements TestSetGenerator<Multiset.Entry<E>> {
- final OneSizeTestContainerGenerator<Collection<E>, E> gen;
-
- private EntrySetGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
- this.gen = gen;
- }
-
- @Override
- public SampleElements<Multiset.Entry<E>> samples() {
- SampleElements<E> samples = gen.samples();
- return new SampleElements<Multiset.Entry<E>>(
- Multisets.immutableEntry(samples.e0, 3),
- Multisets.immutableEntry(samples.e1, 4),
- Multisets.immutableEntry(samples.e2, 1),
- Multisets.immutableEntry(samples.e3, 5),
- Multisets.immutableEntry(samples.e4, 2));
- }
-
- @Override
- public Set<Multiset.Entry<E>> create(Object... entries) {
- List<Object> contents = new ArrayList<Object>();
- Set<E> elements = new HashSet<E>();
- for (Object o : entries) {
- @SuppressWarnings("unchecked")
- Multiset.Entry<E> entry = (Entry<E>) o;
- checkArgument(elements.add(entry.getElement()),
- "Duplicate keys not allowed in EntrySetGenerator");
- for (int i = 0; i < entry.getCount(); i++) {
- contents.add(entry.getElement());
- }
- }
- return ((Multiset<E>) gen.create(contents.toArray())).entrySet();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Multiset.Entry<E>[] createArray(int length) {
- return new Multiset.Entry[length];
- }
-
- @Override
- public Iterable<Entry<E>> order(List<Entry<E>> insertionOrder) {
- // We mimic the order from gen.
- Map<E, Entry<E>> map = new LinkedHashMap<E, Entry<E>>();
- for (Entry<E> entry : insertionOrder) {
- map.put(entry.getElement(), entry);
- }
-
- Set<E> seen = new HashSet<E>();
- List<Entry<E>> order = new ArrayList<Entry<E>>();
- for (E e : gen.order(new ArrayList<E>(map.keySet()))) {
- if (seen.add(e)) {
- order.add(map.get(e));
- }
- }
- return order;
- }
- }
-
- static class ReserializedMultisetGenerator<E> implements TestMultisetGenerator<E>{
- final OneSizeTestContainerGenerator<Collection<E>, E> gen;
-
- private ReserializedMultisetGenerator(OneSizeTestContainerGenerator<Collection<E>, E> gen) {
- this.gen = gen;
- }
-
- @Override
- public SampleElements<E> samples() {
- return gen.samples();
- }
-
- @Override
- public Multiset<E> create(Object... elements) {
- return (Multiset<E>) SerializableTester.reserialize(gen.create(elements));
- }
-
- @Override
- public E[] createArray(int length) {
- return gen.createArray(length);
- }
-
- @Override
- public Iterable<E> order(List<E> insertionOrder) {
- return gen.order(insertionOrder);
- }
- }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/MultisetWritesTester.java b/guava-testlib/src/com/google/common/collect/testing/google/MultisetWritesTester.java
index cdf7710..9b91cb8 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/MultisetWritesTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/MultisetWritesTester.java
@@ -17,15 +17,16 @@
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_CLEAR;
import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;
+import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE_ALL;
+import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_RETAIN_ALL;
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.annotations.GwtIncompatible;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multisets;
-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;
@@ -40,31 +41,25 @@ import java.util.Iterator;
*
* @author Jared Levy
*/
-@GwtCompatible(emulated = true)
+@GwtCompatible
public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
/**
* Returns the {@link Method} instance for
* {@link #testEntrySet_iterator()} so that tests of
* classes with unmodifiable iterators can suppress it.
*/
- @GwtIncompatible("reflection")
public static Method getEntrySetIteratorMethod() {
- return Helpers.getMethod(
+ return Platform.getMethod(
MultisetWritesTester.class, "testEntrySet_iterator");
}
@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));
+ int oldCount = getMultiset().count(samples.e0);
+ assertEquals("multiset.add(E, int) should return the old count",
+ oldCount, getMultiset().add(samples.e0, 2));
+ assertEquals("multiset.count() incorrect after add(E, int)",
+ oldCount + 2, getMultiset().count(samples.e0));
}
@CollectionFeature.Require(absent = SUPPORTS_ADD)
@@ -75,21 +70,6 @@ public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
} 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() {
@@ -136,7 +116,7 @@ public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
0, getMultiset().remove(WrongType.VALUE, 1));
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_CLEAR)
public void testEntrySet_clear() {
getMultiset().entrySet().clear();
assertTrue("multiset not empty after entrySet().clear()",
@@ -200,7 +180,7 @@ public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
}
@CollectionSize.Require(absent = ZERO)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
public void testEntrySet_removeAll_present() {
assertTrue(
"multiset.entrySet.removeAll(presentEntry) returned false",
@@ -212,7 +192,7 @@ public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
}
@CollectionSize.Require(absent = ZERO)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
public void testEntrySet_removeAll_missing() {
assertFalse(
"multiset.entrySet.remove(missingEntry) returned true",
@@ -223,7 +203,7 @@ public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
getMultiset().contains(samples.e0));
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
public void testEntrySet_removeAll_null() {
try {
getMultiset().entrySet().removeAll(null);
@@ -232,7 +212,7 @@ public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
}
@CollectionSize.Require(ONE)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
public void testEntrySet_retainAll_present() {
assertFalse(
"multiset.entrySet.retainAll(presentEntry) returned false",
@@ -244,7 +224,7 @@ public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
}
@CollectionSize.Require(ONE)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
public void testEntrySet_retainAll_missing() {
assertTrue(
"multiset.entrySet.retainAll(missingEntry) returned true",
@@ -255,7 +235,7 @@ public class MultisetWritesTester<E> extends AbstractMultisetTester<E> {
getMultiset().contains(samples.e0));
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
public void testEntrySet_retainAll_null() {
try {
getMultiset().entrySet().retainAll(null);
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/Platform.java b/guava-testlib/src/com/google/common/collect/testing/google/Platform.java
new file mode 100644
index 0000000..45b4166
--- /dev/null
+++ b/guava-testlib/src/com/google/common/collect/testing/google/Platform.java
@@ -0,0 +1,40 @@
+/*
+ * 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 com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+
+import java.lang.reflect.Method;
+
+/**
+ * Methods factored out so that they can be emulated in GWT.
+ *
+ * @author Hayward Chan
+ */
+@GwtCompatible
+class Platform {
+
+ @GwtIncompatible("Class.getMethod, java.lang.reflect.Method")
+ static Method getMethod(Class<?> clazz, String name) {
+ try {
+ return clazz.getMethod(name);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SetGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/SetGenerators.java
index 4e8273a..dee0d41 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/SetGenerators.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/SetGenerators.java
@@ -16,28 +16,19 @@
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.annotations.GwtIncompatible;
-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;
@@ -54,12 +45,12 @@ 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)
+@GwtCompatible
public class SetGenerators {
public static class ImmutableSetCopyOfGenerator extends TestStringSetGenerator {
@@ -129,18 +120,6 @@ public class SetGenerators {
}
}
- @GwtIncompatible("NavigableSet")
- public static class ImmutableSortedSetDescendingGenerator
- extends TestStringSortedSetGenerator {
- @Override protected SortedSet<String> create(String[] elements) {
- return ImmutableSortedSet
- .<String>reverseOrder()
- .add(elements)
- .build()
- .descendingSet();
- }
- }
-
public static class ImmutableSortedSetExplicitComparator
extends TestStringSetGenerator {
@@ -231,20 +210,6 @@ public class SetGenerators {
}
}
- @GwtIncompatible("NavigableSet")
- public static class ImmutableSortedSetDescendingAsListGenerator
- extends TestStringListGenerator {
- @Override protected List<String> create(String[] elements) {
- Comparator<String> comparator = createExplicitComparator(elements).reverse();
- return ImmutableSortedSet
- .orderedBy(comparator)
- .add(elements)
- .build()
- .descendingSet()
- .asList();
- }
- }
-
public static class ImmutableSortedSetAsListSubListGenerator
extends TestStringListGenerator {
@Override protected List<String> create(String[] elements) {
@@ -258,7 +223,7 @@ public class SetGenerators {
}
}
- public static class ImmutableSortedSetSubsetAsListSubListGenerator
+ public static class ImmutableSortedsetSubsetAsListSubListGenerator
extends TestStringListGenerator {
@Override protected List<String> create(String[] elements) {
Comparator<String> comparator = createExplicitComparator(elements);
@@ -280,7 +245,7 @@ public class SetGenerators {
implements TestSetGenerator<UnhashableObject> {
}
- private static Ordering<String> createExplicitComparator(
+ private static Comparator<String> createExplicitComparator(
String[] elements) {
// Collapse equal elements, which Ordering.explicit() doesn't support, while
// maintaining the ordering by first occurrence.
@@ -292,97 +257,4 @@ public class SetGenerators {
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);
- }
- }
-
- @GwtIncompatible("NavigableSet")
- public static class ContiguousSetDescendingGenerator extends AbstractContiguousSetGenerator {
- @Override protected SortedSet<Integer> create(Integer[] elements) {
- return checkedCreate(nullCheckedTreeSet(elements)).descendingSet();
- }
-
- /** Sorts the elements in reverse natural order. */
- @Override public List<Integer> order(List<Integer> insertionOrder) {
- Collections.sort(insertionOrder, Ordering.natural().reverse());
- return insertionOrder;
- }
- }
-
- 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/src/com/google/common/collect/testing/google/SetMultimapPutAllTester.java b/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutAllTester.java
deleted file mode 100644
index bcc3d50..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutAllTester.java
+++ /dev/null
@@ -1,55 +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.Helpers.copyToSet;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.SetMultimap;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Tests for {@link SetMultimap#replaceValues}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class SetMultimapPutAllTester<K, V>
- extends AbstractMultimapTester<K, V, SetMultimap<K, V>> {
-
- @MapFeature.Require(SUPPORTS_PUT)
- public void testReplaceValuesHandlesDuplicates() {
- V v0 = sampleValues().e3;
- V v1 = sampleValues().e2;
- @SuppressWarnings("unchecked")
- List<V> valuesToPut = Arrays.asList(v0, v1, v0);
-
- for (K k : sampleKeys()) {
- resetContainer();
-
- Set<V> expectedValues = copyToSet(multimap().get(k));
-
- multimap().putAll(k, valuesToPut);
- expectedValues.addAll(valuesToPut);
-
- assertGet(k, expectedValues);
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutTester.java b/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutTester.java
deleted file mode 100644
index ade18b3..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapPutTester.java
+++ /dev/null
@@ -1,59 +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.Helpers.copyToList;
-import static com.google.common.collect.testing.Helpers.copyToSet;
-import static com.google.common.collect.testing.features.CollectionSize.ZERO;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.SetMultimap;
-import com.google.common.collect.testing.features.CollectionSize;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * Tests for {@link SetMultimap#replaceValues}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class SetMultimapPutTester<K, V>
- extends AbstractMultimapTester<K, V, SetMultimap<K, V>> {
- // Tests for non-duplicate values are in MultimapPutTester
-
- @MapFeature.Require(SUPPORTS_PUT)
- @CollectionSize.Require(absent = ZERO)
- public void testPutDuplicateValue() {
- List<Entry<K, V>> entries = copyToList(multimap().entries());
-
- for (Entry<K, V> entry : entries) {
- resetContainer();
- K k = entry.getKey();
- V v = entry.getValue();
-
- Set<V> values = multimap().get(k);
- Set<V> expectedValues = copyToSet(values);
-
- assertFalse(multimap().put(k, v));
- assertEquals(expectedValues, values);
- assertGet(k, expectedValues);
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapReplaceValuesTester.java b/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapReplaceValuesTester.java
deleted file mode 100644
index fa95309..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapReplaceValuesTester.java
+++ /dev/null
@@ -1,49 +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.MapFeature.SUPPORTS_PUT;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.SetMultimap;
-import com.google.common.collect.testing.features.MapFeature;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Tests for {@link SetMultimap#replaceValues}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class SetMultimapReplaceValuesTester<K, V>
- extends AbstractMultimapTester<K, V, SetMultimap<K, V>> {
-
- @MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
- public void testReplaceValuesHandlesDuplicates() {
- V v0 = sampleValues().e3;
- V v1 = sampleValues().e2;
- @SuppressWarnings("unchecked")
- List<V> values = Arrays.asList(v0, v1, v0);
-
- for (K k : sampleKeys()) {
- resetContainer();
- multimap().replaceValues(k, values);
- assertGet(k, v0, v1);
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapTestSuiteBuilder.java
deleted file mode 100644
index 9a81532..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapTestSuiteBuilder.java
+++ /dev/null
@@ -1,111 +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 com.google.common.collect.SetMultimap;
-import com.google.common.collect.testing.AbstractTester;
-import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.OneSizeTestContainerGenerator;
-import com.google.common.collect.testing.SetTestSuiteBuilder;
-import com.google.common.collect.testing.TestSetGenerator;
-
-import junit.framework.TestSuite;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * Creates, based on your criteria, a JUnit test suite that exhaustively tests
- * a {@code SetMultimap} implementation.
- *
- * @author Louis Wasserman
- */
-public class SetMultimapTestSuiteBuilder<K, V>
- extends MultimapTestSuiteBuilder<K, V, SetMultimap<K, V>> {
-
- public static <K, V> SetMultimapTestSuiteBuilder<K, V> using(
- TestSetMultimapGenerator<K, V> generator) {
- SetMultimapTestSuiteBuilder<K, V> result = new SetMultimapTestSuiteBuilder<K, V>();
- result.usingGenerator(generator);
- return result;
- }
-
- @Override protected List<Class<? extends AbstractTester>> getTesters() {
- List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
- testers.add(SetMultimapPutTester.class);
- testers.add(SetMultimapPutAllTester.class);
- testers.add(SetMultimapReplaceValuesTester.class);
- return testers;
- }
-
- @Override
- TestSuite computeMultimapGetTestSuite(
- FeatureSpecificTestSuiteBuilder<?, ? extends
- OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>> parentBuilder) {
- return SetTestSuiteBuilder.using(
- new MultimapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeMultimapGetFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".get[key]")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- @Override
- TestSuite computeEntriesTestSuite(
- FeatureSpecificTestSuiteBuilder<?, ? extends
- OneSizeTestContainerGenerator<SetMultimap<K, V>, Map.Entry<K, V>>> parentBuilder) {
- return SetTestSuiteBuilder.using(
- new EntriesGenerator<K, V>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeEntriesFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".entries")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- private static class EntriesGenerator<K, V>
- extends MultimapTestSuiteBuilder.EntriesGenerator<K, V, SetMultimap<K, V>>
- implements TestSetGenerator<Entry<K, V>> {
-
- public EntriesGenerator(
- OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>> multimapGenerator) {
- super(multimapGenerator);
- }
-
- @Override
- public Set<Entry<K, V>> create(Object... elements) {
- return (Set<Entry<K, V>>) super.create(elements);
- }
- }
-
- private static class MultimapGetGenerator<K, V>
- extends MultimapTestSuiteBuilder.MultimapGetGenerator<K, V, SetMultimap<K, V>>
- implements TestSetGenerator<V> {
- public MultimapGetGenerator(
- OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>> multimapGenerator) {
- super(multimapGenerator);
- }
-
- @Override
- public Set<V> create(Object... elements) {
- return (Set<V>) super.create(elements);
- }
-
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java b/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java
index e37ae5f..6ce5a77 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/SortedMapGenerators.java
@@ -17,19 +17,21 @@
package com.google.common.collect.testing.google;
import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.testing.Helpers.mapEntry;
import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.ImmutableSortedMap;
-import com.google.common.collect.Ordering;
+import com.google.common.collect.ImmutableSortedMap.Builder;
import com.google.common.collect.testing.SampleElements;
-import com.google.common.collect.testing.TestListGenerator;
-import com.google.common.collect.testing.TestStringListGenerator;
-import com.google.common.collect.testing.TestStringSortedMapGenerator;
+import com.google.common.collect.testing.TestCollectionGenerator;
+import com.google.common.collect.testing.TestMapEntrySetGenerator;
+import com.google.common.collect.testing.TestStringSetGenerator;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
-import java.util.SortedMap;
+import java.util.Set;
/**
* Generators of sorted maps and derived collections.
@@ -38,85 +40,160 @@ import java.util.SortedMap;
* @author Jesse Wilson
* @author Jared Levy
* @author Hayward Chan
- * @author Chris Povirk
- * @author Louis Wasserman
*/
@GwtCompatible
public class SortedMapGenerators {
- public static class ImmutableSortedMapGenerator extends TestStringSortedMapGenerator {
- @Override public SortedMap<String, String> create(Entry<String, String>[] entries) {
- ImmutableSortedMap.Builder<String, String> builder = ImmutableSortedMap.naturalOrder();
- for (Entry<String, String> entry : entries) {
- checkNotNull(entry);
- builder.put(entry.getKey(), entry.getValue());
+
+ public static final Comparator<Entry<String, String>> ENTRY_COMPARATOR
+ = new Comparator<Entry<String, String>>() {
+ @Override
+ public int compare(
+ Entry<String, String> o1, Entry<String, String> o2) {
+ return o1.getKey().compareTo(o2.getKey());
+ }
+ };
+
+ public static class ImmutableSortedMapKeySetGenerator
+ extends TestStringSetGenerator {
+
+ @Override protected Set<String> create(String[] elements) {
+ Builder<String, Integer> builder = ImmutableSortedMap.naturalOrder();
+ for (String key : elements) {
+ builder.put(key, 4);
}
- return builder.build();
+ return builder.build().keySet();
+ }
+ @Override public List<String> order(List<String> insertionOrder) {
+ Collections.sort(insertionOrder);
+ return insertionOrder;
}
}
- public static class ImmutableSortedMapEntryListGenerator
- implements TestListGenerator<Entry<String, Integer>> {
+ public static class ImmutableSortedMapValuesGenerator
+ implements TestCollectionGenerator<String> {
@Override
- public SampleElements<Entry<String, Integer>> samples() {
- return new SampleElements<Entry<String, Integer>>(
- mapEntry("foo", 5),
- mapEntry("bar", 3),
- mapEntry("baz", 17),
- mapEntry("quux", 1),
- mapEntry("toaster", -2));
+ public SampleElements<String> samples() {
+ return new SampleElements.Strings();
}
- @SuppressWarnings("unchecked")
@Override
- public Entry<String, Integer>[] createArray(int length) {
- return new Entry[length];
+ public Collection<String> create(Object... elements) {
+ Builder<Integer, String> builder = ImmutableSortedMap.naturalOrder();
+ for (int i = 0; i < elements.length; i++) {
+ builder.put(i, toStringOrNull(elements[i]));
+ }
+ return builder.build().values();
}
@Override
- public Iterable<Entry<String, Integer>> order(List<Entry<String, Integer>> insertionOrder) {
- return new Ordering<Entry<String, Integer>>() {
- @Override
- public int compare(Entry<String, Integer> left, Entry<String, Integer> right) {
- return left.getKey().compareTo(right.getKey());
- }
- }.sortedCopy(insertionOrder);
+ public String[] createArray(int length) {
+ return new String[length];
}
@Override
- public List<Entry<String, Integer>> create(Object... elements) {
- ImmutableSortedMap.Builder<String, Integer> builder = ImmutableSortedMap.naturalOrder();
- for (Object o : elements) {
- @SuppressWarnings("unchecked")
- Entry<String, Integer> entry = (Entry<String, Integer>) o;
- builder.put(entry);
+ public List<String> order(List<String> insertionOrder) {
+ return insertionOrder;
+ }
+ }
+
+ public static class ImmutableSortedMapSubMapEntryGenerator
+ extends TestMapEntrySetGenerator<String, String> {
+
+ public ImmutableSortedMapSubMapEntryGenerator() {
+ super(new SampleElements.Strings(), new SampleElements.Strings());
+ }
+
+ @Override public Set<Entry<String, String>> createFromEntries(
+ Entry<String, String>[] entries) {
+ Builder<String, String> builder = ImmutableSortedMap.naturalOrder();
+ builder.put(SampleElements.Strings.BEFORE_FIRST, "begin");
+ builder.put(SampleElements.Strings.AFTER_LAST, "end");
+ for (Entry<String, String> entry : entries) {
+ checkNotNull(entry);
+ builder.put(entry.getKey(), entry.getValue());
+ }
+ return builder.build().subMap(SampleElements.Strings.MIN_ELEMENT,
+ SampleElements.Strings.AFTER_LAST).entrySet();
+ }
+ @Override public List<Entry<String, String>> order(
+ List<Entry<String, String>> insertionOrder) {
+ Collections.sort(insertionOrder, ENTRY_COMPARATOR);
+ return insertionOrder;
+ }
+ }
+
+ public static class ImmutableSortedMapHeadMapKeySetGenerator
+ extends TestStringSetGenerator {
+ @Override protected Set<String> create(String[] elements) {
+ Builder<String, Integer> builder = ImmutableSortedMap.naturalOrder();
+ builder.put(SampleElements.Strings.AFTER_LAST, -1);
+ for (String key : elements) {
+ builder.put(key, 4);
}
- return builder.build().entrySet().asList();
+ return builder.build().headMap(
+ SampleElements.Strings.AFTER_LAST).keySet();
+ }
+ @Override public List<String> order(List<String> insertionOrder) {
+ Collections.sort(insertionOrder);
+ return insertionOrder;
}
}
- public static class ImmutableSortedMapKeyListGenerator extends TestStringListGenerator {
- @Override protected List<String> create(String[] elements) {
- ImmutableSortedMap.Builder<String, Integer> builder = ImmutableSortedMap.naturalOrder();
+ public static class ImmutableSortedMapTailMapValuesGenerator
+ implements TestCollectionGenerator<String> {
+
+ @Override
+ public SampleElements<String> samples() {
+ return new SampleElements.Strings();
+ }
+
+ @Override
+ public Collection<String> create(Object... elements) {
+ Builder<Integer, String> builder = ImmutableSortedMap.naturalOrder();
+ builder.put(-1, "begin");
for (int i = 0; i < elements.length; i++) {
- builder.put(elements[i], i);
+ builder.put(i, toStringOrNull(elements[i]));
}
- return builder.build().keySet().asList();
+ return builder.build().tailMap(0).values();
+ }
+
+ @Override
+ public String[] createArray(int length) {
+ return new String[length];
}
@Override
public List<String> order(List<String> insertionOrder) {
- return Ordering.natural().sortedCopy(insertionOrder);
+ return insertionOrder;
}
}
- public static class ImmutableSortedMapValueListGenerator extends TestStringListGenerator {
- @Override protected List<String> create(String[] elements) {
- ImmutableSortedMap.Builder<Integer, String> builder = ImmutableSortedMap.naturalOrder();
- for (int i = 0; i < elements.length; i++) {
- builder.put(i, elements[i]);
+ public static class ImmutableSortedMapEntrySetGenerator
+ extends TestMapEntrySetGenerator<String, String> {
+
+ public ImmutableSortedMapEntrySetGenerator() {
+ super(new SampleElements.Strings(), new SampleElements.Strings());
+ }
+
+ @Override public Set<Entry<String, String>> createFromEntries(
+ Entry<String, String>[] entries) {
+ Builder<String, String> builder = ImmutableSortedMap.naturalOrder();
+ for (Entry<String, String> entry : entries) {
+ checkNotNull(entry);
+ builder.put(entry.getKey(), entry.getValue());
}
- return builder.build().values().asList();
+ return builder.build().entrySet();
+ }
+
+ @Override public List<Entry<String, String>> order(
+ List<Entry<String, String>> insertionOrder) {
+ Collections.sort(insertionOrder, ENTRY_COMPARATOR);
+ return insertionOrder;
}
}
+
+ private static String toStringOrNull(Object o) {
+ return (o == null) ? null : o.toString();
+ }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SortedMultisetTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/google/SortedMultisetTestSuiteBuilder.java
index af79cc2..547ab97 100644
--- a/guava-testlib/src/com/google/common/collect/testing/google/SortedMultisetTestSuiteBuilder.java
+++ b/guava-testlib/src/com/google/common/collect/testing/google/SortedMultisetTestSuiteBuilder.java
@@ -1,12 +1,12 @@
/*
- * Copyright (C) 2011 The Guava Authors
- *
+ * Copyright (C) 2011 Google Inc.
+ *
* 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
@@ -16,40 +16,36 @@
package com.google.common.collect.testing.google;
+import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.BoundType;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Multiset;
import com.google.common.collect.SortedMultiset;
import com.google.common.collect.testing.AbstractTester;
-import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.OneSizeTestContainerGenerator;
import com.google.common.collect.testing.SampleElements;
-import com.google.common.collect.testing.SortedSetTestSuiteBuilder;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.Feature;
-import com.google.common.testing.SerializableTester;
import junit.framework.TestSuite;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Creates, based on your criteria, a JUnit test suite that exhaustively tests a
* {@code SortedMultiset} implementation.
- *
+ *
* <p><b>Warning</b>: expects that {@code E} is a String.
- *
+ *
* @author Louis Wasserman
*/
+@GwtCompatible
public class SortedMultisetTestSuiteBuilder<E> extends
MultisetTestSuiteBuilder<E> {
public static <E> SortedMultisetTestSuiteBuilder<E> using(
@@ -62,7 +58,6 @@ public class SortedMultisetTestSuiteBuilder<E> extends
@Override
public TestSuite createTestSuite() {
- withFeatures(CollectionFeature.KNOWN_ORDER);
TestSuite suite = super.createTestSuite();
for (TestSuite subSuite : createDerivedSuites(this)) {
suite.addTest(subSuite);
@@ -78,17 +73,6 @@ public class SortedMultisetTestSuiteBuilder<E> extends
return testers;
}
- @Override
- TestSuite createElementSetTestSuite(FeatureSpecificTestSuiteBuilder<
- ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>> parentBuilder) {
- return SortedSetTestSuiteBuilder
- .using(new ElementSetGenerator<E>(parentBuilder.getSubjectGenerator()))
- .named(getName() + ".elementSet")
- .withFeatures(computeElementSetFeatures(parentBuilder.getFeatures()))
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
/**
* To avoid infinite recursion, test suites with these marker features won't
* have derived suites created for them.
@@ -117,10 +101,6 @@ public class SortedMultisetTestSuiteBuilder<E> extends
derivedSuites.add(createDescendingSuite(parentBuilder));
}
- if (parentBuilder.getFeatures().contains(CollectionFeature.SERIALIZABLE)) {
- derivedSuites.add(createReserializedSuite(parentBuilder));
- }
-
if (!parentBuilder.getFeatures().contains(NoRecurse.SUBMULTISET)) {
derivedSuites.add(createSubMultisetSuite(parentBuilder, Bound.NO_BOUND,
Bound.EXCLUSIVE));
@@ -149,15 +129,11 @@ public class SortedMultisetTestSuiteBuilder<E> extends
final TestMultisetGenerator<E> delegate =
(TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();
- Set<Feature<?>> features = new HashSet<Feature<?>>();
+ List<Feature<?>> features = new ArrayList<Feature<?>>();
features.add(NoRecurse.SUBMULTISET);
features.add(CollectionFeature.RESTRICTS_ELEMENTS);
features.addAll(parentBuilder.getFeatures());
- if (!features.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
- features.remove(CollectionFeature.SERIALIZABLE);
- }
-
SortedMultiset<E> emptyMultiset = (SortedMultiset<E>) delegate.create();
final Comparator<? super E> comparator = emptyMultiset.comparator();
SampleElements<E> samples = delegate.samples();
@@ -228,7 +204,7 @@ public class SortedMultisetTestSuiteBuilder<E> extends
/**
* Returns an array of four bogus elements that will always be too high or too
* low for the display. This includes two values for each extreme.
- *
+ *
* <p>
* This method (dangerously) assume that the strings {@code "!! a"} and
* {@code "~~ z"} will work for this purpose, which may cause problems for
@@ -248,12 +224,9 @@ public class SortedMultisetTestSuiteBuilder<E> extends
final TestMultisetGenerator<E> delegate =
(TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();
- Set<Feature<?>> features = new HashSet<Feature<?>>();
+ List<Feature<?>> features = new ArrayList<Feature<?>>();
features.add(NoRecurse.DESCENDING);
features.addAll(parentBuilder.getFeatures());
- if (!features.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
- features.remove(CollectionFeature.SERIALIZABLE);
- }
return SortedMultisetTestSuiteBuilder
.using(new ForwardingTestMultisetGenerator<E>(delegate) {
@@ -274,29 +247,6 @@ public class SortedMultisetTestSuiteBuilder<E> extends
.createTestSuite();
}
- private TestSuite createReserializedSuite(
- SortedMultisetTestSuiteBuilder<E> parentBuilder) {
- final TestMultisetGenerator<E> delegate =
- (TestMultisetGenerator<E>) parentBuilder.getSubjectGenerator();
-
- Set<Feature<?>> features = new HashSet<Feature<?>>();
- features.addAll(parentBuilder.getFeatures());
- features.remove(CollectionFeature.SERIALIZABLE);
- features.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS);
-
- return SortedMultisetTestSuiteBuilder
- .using(new ForwardingTestMultisetGenerator<E>(delegate) {
- @Override
- public SortedMultiset<E> create(Object... entries) {
- return SerializableTester.reserialize(((SortedMultiset<E>) super.create(entries)));
- }
- })
- .named(parentBuilder.getName() + " reserialized")
- .withFeatures(features)
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
private static class ForwardingTestMultisetGenerator<E>
implements TestMultisetGenerator<E> {
private final TestMultisetGenerator<E> delegate;
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapGetTester.java b/guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapGetTester.java
deleted file mode 100644
index ee703d8..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapGetTester.java
+++ /dev/null
@@ -1,35 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.SortedSetMultimap;
-
-/**
- * Tester for {@link SortedSetMultimap#get(Object)}.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class SortedSetMultimapGetTester<K, V>
- extends AbstractMultimapTester<K, V, SortedSetMultimap<K, V>> {
- public void testValueComparator() {
- assertEquals(
- multimap().valueComparator(),
- multimap().get(sampleKeys().e0).comparator());
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapTestSuiteBuilder.java b/guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapTestSuiteBuilder.java
deleted file mode 100644
index 268069e..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/SortedSetMultimapTestSuiteBuilder.java
+++ /dev/null
@@ -1,84 +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 com.google.common.collect.SetMultimap;
-import com.google.common.collect.testing.AbstractTester;
-import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.OneSizeTestContainerGenerator;
-import com.google.common.collect.testing.SortedSetTestSuiteBuilder;
-import com.google.common.collect.testing.TestSetGenerator;
-
-import junit.framework.TestSuite;
-
-import java.util.Map.Entry;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Creates, based on your criteria, a JUnit test suite that exhaustively tests
- * a {@code SortedSetMultimap} implementation.
- *
- * @author Louis Wasserman
- */
-public class SortedSetMultimapTestSuiteBuilder<K, V>
- extends MultimapTestSuiteBuilder<K, V, SetMultimap<K, V>> {
-
- public static <K, V> SortedSetMultimapTestSuiteBuilder<K, V> using(
- TestSetMultimapGenerator<K, V> generator) {
- SortedSetMultimapTestSuiteBuilder<K, V> result = new SortedSetMultimapTestSuiteBuilder<K, V>();
- result.usingGenerator(generator);
- return result;
- }
-
- @Override protected List<Class<? extends AbstractTester>> getTesters() {
- List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
- testers.add(SetMultimapPutTester.class);
- testers.add(SetMultimapPutAllTester.class);
- testers.add(SetMultimapReplaceValuesTester.class);
- testers.add(SortedSetMultimapGetTester.class);
- return testers;
- }
-
- @Override
- TestSuite computeMultimapGetTestSuite(
- FeatureSpecificTestSuiteBuilder<?, ? extends
- OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>> parentBuilder) {
- return SortedSetTestSuiteBuilder.using(
- new MultimapGetGenerator<K, V>(parentBuilder.getSubjectGenerator()))
- .withFeatures(computeMultimapGetFeatures(parentBuilder.getFeatures()))
- .named(parentBuilder.getName() + ".get[key]")
- .suppressing(parentBuilder.getSuppressedTests())
- .createTestSuite();
- }
-
- private static class MultimapGetGenerator<K, V>
- extends MultimapTestSuiteBuilder.MultimapGetGenerator<K, V, SetMultimap<K, V>>
- implements TestSetGenerator<V> {
- public MultimapGetGenerator(
- OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>> multimapGenerator) {
- super(multimapGenerator);
- }
-
- @Override
- public Set<V> create(Object... elements) {
- return (Set<V>) super.create(elements);
- }
-
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/TestBiMapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/google/TestBiMapGenerator.java
deleted file mode 100644
index a8999e4..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/TestBiMapGenerator.java
+++ /dev/null
@@ -1,36 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.testing.TestContainerGenerator;
-
-import java.util.Map;
-
-/**
- * Creates bimaps, containing sample entries, to be tested.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public interface TestBiMapGenerator<K, V>
- extends TestContainerGenerator<BiMap<K, V>, Map.Entry<K, V>> {
- K[] createKeyArray(int length);
-
- V[] createValueArray(int length);
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/TestListMultimapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/google/TestListMultimapGenerator.java
deleted file mode 100644
index ffc6ab2..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/TestListMultimapGenerator.java
+++ /dev/null
@@ -1,31 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ListMultimap;
-
-/**
- * A generator for {@code ListMultimap} implementations based on test data.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public interface TestListMultimapGenerator<K, V>
- extends TestMultimapGenerator<K, V, ListMultimap<K, V>> {
-
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/TestMultimapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/google/TestMultimapGenerator.java
deleted file mode 100644
index fe97023..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/TestMultimapGenerator.java
+++ /dev/null
@@ -1,45 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.testing.SampleElements;
-import com.google.common.collect.testing.TestContainerGenerator;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Creates multimaps, containing sample elements, to be tested.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public interface TestMultimapGenerator<K, V, M extends Multimap<K, V>>
- extends TestContainerGenerator<M, Map.Entry<K, V>> {
-
- K[] createKeyArray(int length);
-
- V[] createValueArray(int length);
-
- SampleElements<K> sampleKeys();
-
- SampleElements<V> sampleValues();
-
- Collection<V> createCollection(Iterable<? extends V> values);
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/TestSetMultimapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/google/TestSetMultimapGenerator.java
deleted file mode 100644
index 8b31084..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/TestSetMultimapGenerator.java
+++ /dev/null
@@ -1,31 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.SetMultimap;
-
-/**
- * A generator for {@code SetMultimap} implementations based on test data.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public interface TestSetMultimapGenerator<K, V>
- extends TestMultimapGenerator<K, V, SetMultimap<K, V>> {
-
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/TestStringBiMapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/google/TestStringBiMapGenerator.java
deleted file mode 100644
index 30f1452..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/TestStringBiMapGenerator.java
+++ /dev/null
@@ -1,92 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.SampleElements;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * Implementation helper for {@link TestBiMapGenerator} for use with bimaps of
- * strings.
- *
- * <p>This class is GWT compatible.
- *
- * @author Chris Povirk
- * @author Jared Levy
- * @author George van den Driessche
- * @author Louis Wasserman
- */
-@GwtCompatible
-public abstract class TestStringBiMapGenerator
- implements TestBiMapGenerator<String, String> {
-
- @Override
- public SampleElements<Map.Entry<String, String>> samples() {
- return new SampleElements<Map.Entry<String, String>>(
- Helpers.mapEntry("one", "January"),
- Helpers.mapEntry("two", "February"),
- Helpers.mapEntry("three", "March"),
- Helpers.mapEntry("four", "April"),
- Helpers.mapEntry("five", "May")
- );
- }
-
- @Override
- public final BiMap<String, String> create(Object... entries) {
- @SuppressWarnings("unchecked")
- Entry<String, String>[] array = new Entry[entries.length];
- int i = 0;
- for (Object o : entries) {
- @SuppressWarnings("unchecked")
- Entry<String, String> e = (Entry<String, String>) o;
- array[i++] = e;
- }
- return create(array);
- }
-
- protected abstract BiMap<String, String> create(
- Entry<String, String>[] entries);
-
- @Override
- @SuppressWarnings("unchecked")
- public final Entry<String, String>[] createArray(int length) {
- return new Entry[length];
- }
-
- @Override
- public final String[] createKeyArray(int length) {
- return new String[length];
- }
-
- @Override
- public final String[] createValueArray(int length) {
- return new String[length];
- }
-
- /** Returns the original element list, unchanged. */
- @Override
- public Iterable<Entry<String, String>> order(
- List<Entry<String, String>> insertionOrder) {
- return insertionOrder;
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/TestStringListMultimapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/google/TestStringListMultimapGenerator.java
deleted file mode 100644
index 4f99879..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/TestStringListMultimapGenerator.java
+++ /dev/null
@@ -1,101 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.SampleElements;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * A skeleton generator for a {@code ListMultimap} implementation.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public abstract class TestStringListMultimapGenerator
- implements TestListMultimapGenerator<String, String> {
-
- @Override
- public SampleElements<Map.Entry<String, String>> samples() {
- return new SampleElements<Map.Entry<String, String>>(
- Helpers.mapEntry("one", "January"),
- Helpers.mapEntry("two", "February"),
- Helpers.mapEntry("three", "March"),
- Helpers.mapEntry("four", "April"),
- Helpers.mapEntry("five", "May"));
- }
-
- @Override
- public SampleElements<String> sampleKeys() {
- return new SampleElements<String>("one", "two", "three", "four", "five");
- }
-
- @Override
- public SampleElements<String> sampleValues() {
- return new SampleElements<String>("January", "February", "March", "April", "May");
- }
-
- @Override
- public Collection<String> createCollection(Iterable<? extends String> values) {
- return Helpers.copyToList(values);
- }
-
- @Override
- public final ListMultimap<String, String> create(Object... entries) {
- @SuppressWarnings("unchecked")
- Entry<String, String>[] array = new Entry[entries.length];
- int i = 0;
- for (Object o : entries) {
- @SuppressWarnings("unchecked")
- Entry<String, String> e = (Entry<String, String>) o;
- array[i++] = e;
- }
- return create(array);
- }
-
- protected abstract ListMultimap<String, String> create(
- Entry<String, String>[] entries);
-
- @Override
- @SuppressWarnings("unchecked")
- public final Entry<String, String>[] createArray(int length) {
- return new Entry[length];
- }
-
- @Override
- public final String[] createKeyArray(int length) {
- return new String[length];
- }
-
- @Override
- public final String[] createValueArray(int length) {
- return new String[length];
- }
-
- /** Returns the original element list, unchanged. */
- @Override
- public Iterable<Entry<String, String>> order(
- List<Entry<String, String>> insertionOrder) {
- return insertionOrder;
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/google/TestStringSetMultimapGenerator.java b/guava-testlib/src/com/google/common/collect/testing/google/TestStringSetMultimapGenerator.java
deleted file mode 100644
index f49d4f0..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/google/TestStringSetMultimapGenerator.java
+++ /dev/null
@@ -1,100 +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 com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.SetMultimap;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.SampleElements;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * A skeleton generator for a {@code SetMultimap} implementation.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public abstract class TestStringSetMultimapGenerator
- implements TestSetMultimapGenerator<String, String> {
-
- @Override
- public SampleElements<Map.Entry<String, String>> samples() {
- return new SampleElements<Map.Entry<String, String>>(
- Helpers.mapEntry("one", "January"),
- Helpers.mapEntry("two", "February"),
- Helpers.mapEntry("three", "March"),
- Helpers.mapEntry("four", "April"),
- Helpers.mapEntry("five", "May"));
- }
-
- @Override
- public SampleElements<String> sampleKeys() {
- return new SampleElements<String>("one", "two", "three", "four", "five");
- }
-
- @Override
- public SampleElements<String> sampleValues() {
- return new SampleElements<String>("January", "February", "March", "April", "May");
- }
-
- @Override
- public Collection<String> createCollection(Iterable<? extends String> values) {
- return Helpers.copyToSet(values);
- }
-
- @Override
- public final SetMultimap<String, String> create(Object... entries) {
- @SuppressWarnings("unchecked")
- Entry<String, String>[] array = new Entry[entries.length];
- int i = 0;
- for (Object o : entries) {
- @SuppressWarnings("unchecked")
- Entry<String, String> e = (Entry<String, String>) o;
- array[i++] = e;
- }
- return create(array);
- }
-
- protected abstract SetMultimap<String, String> create(
- Entry<String, String>[] entries);
-
- @Override
- @SuppressWarnings("unchecked")
- public final Entry<String, String>[] createArray(int length) {
- return new Entry[length];
- }
-
- @Override
- public final String[] createKeyArray(int length) {
- return new String[length];
- }
-
- @Override
- public final String[] createValueArray(int length) {
- return new String[length];
- }
-
- /** Returns the original element list, unchanged. */
- @Override
- public Iterable<Entry<String, String>> order(
- List<Entry<String, String>> insertionOrder) {
- return insertionOrder;
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListIndexOfTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListIndexOfTester.java
index 21fff11..af960a5 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListIndexOfTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListIndexOfTester.java
@@ -19,7 +19,6 @@ 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.WrongType;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -32,7 +31,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Chris Povirk
*/
-@GwtCompatible
public abstract class AbstractListIndexOfTester<E>
extends AbstractListTester<E> {
/** Override to call {@code indexOf()} or {@code lastIndexOf()}. */
@@ -47,7 +45,7 @@ public abstract class AbstractListIndexOfTester<E>
@CollectionSize.Require(absent = ZERO)
public void testFind_yes() {
assertEquals(getMethodName() + "(firstElement) should return 0",
- 0, find(getOrderedElements().get(0)));
+ 0, find(samples.e0));
}
public void testFind_no() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListTester.java
index 5bebdb3..268022d 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListTester.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
import com.google.common.collect.testing.Helpers;
@@ -30,7 +29,6 @@ import java.util.List;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class AbstractListTester<E> extends AbstractCollectionTester<E> {
/*
* Previously we had a field named list that was initialized to the value of
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/AbstractQueueTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/AbstractQueueTester.java
index dd6a260..5f7477c 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/AbstractQueueTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/AbstractQueueTester.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
import java.util.Queue;
@@ -28,7 +27,6 @@ import java.util.Queue;
*
* @author Jared Levy
*/
-@GwtCompatible
public class AbstractQueueTester<E> extends AbstractCollectionTester<E> {
protected final Queue<E> getQueue() {
return (Queue<E>) collection;
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/AbstractSetTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/AbstractSetTester.java
index 544373e..76a5326 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/AbstractSetTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/AbstractSetTester.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
import java.util.Set;
@@ -26,7 +25,6 @@ import java.util.Set;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class AbstractSetTester<E> extends AbstractCollectionTester<E> {
/*
* Previously we had a field named set that was initialized to the value of
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddAllTester.java
index 38d5261..b5e3085 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddAllTester.java
@@ -17,23 +17,17 @@
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.CollectionFeature.SUPPORTS_ADD_ALL;
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.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
-import com.google.common.collect.testing.Helpers;
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.lang.reflect.Method;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
import java.util.List;
/**
@@ -47,16 +41,15 @@ import java.util.List;
* @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)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
public void testAddAll_supportedNothing() {
assertFalse("addAll(nothing) should return false",
collection.addAll(emptyCollection()));
expectUnchanged();
}
- @CollectionFeature.Require(absent = SUPPORTS_ADD)
+ @CollectionFeature.Require(absent = SUPPORTS_ADD_ALL)
public void testAddAll_unsupportedNothing() {
try {
assertFalse("addAll(nothing) should return false or throw",
@@ -66,14 +59,14 @@ public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
expectUnchanged();
}
- @CollectionFeature.Require(SUPPORTS_ADD)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
public void testAddAll_supportedNonePresent() {
assertTrue("addAll(nonePresent) should return true",
collection.addAll(createDisjointCollection()));
expectAdded(samples.e3, samples.e4);
}
- @CollectionFeature.Require(absent = SUPPORTS_ADD)
+ @CollectionFeature.Require(absent = SUPPORTS_ADD_ALL)
public void testAddAll_unsupportedNonePresent() {
try {
collection.addAll(createDisjointCollection());
@@ -84,7 +77,7 @@ public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
expectMissing(samples.e3, samples.e4);
}
- @CollectionFeature.Require(SUPPORTS_ADD)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_supportedSomePresent() {
assertTrue("addAll(somePresent) should return true",
@@ -93,7 +86,7 @@ public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
assertTrue("should contain " + samples.e0, collection.contains(samples.e0));
}
- @CollectionFeature.Require(absent = SUPPORTS_ADD)
+ @CollectionFeature.Require(absent = SUPPORTS_ADD_ALL)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_unsupportedSomePresent() {
try {
@@ -104,21 +97,7 @@ public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
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)
+ @CollectionFeature.Require(absent = SUPPORTS_ADD_ALL)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_unsupportedAllPresent() {
try {
@@ -129,7 +108,7 @@ public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
expectUnchanged();
}
- @CollectionFeature.Require(value = {SUPPORTS_ADD,
+ @CollectionFeature.Require(value = {SUPPORTS_ADD_ALL,
ALLOWS_NULL_VALUES}, absent = RESTRICTS_ELEMENTS)
public void testAddAll_nullSupported() {
List<E> containsNull = singletonList(null);
@@ -142,7 +121,7 @@ public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
expectAdded((E) null);
}
- @CollectionFeature.Require(value = SUPPORTS_ADD,
+ @CollectionFeature.Require(value = SUPPORTS_ADD_ALL,
absent = ALLOWS_NULL_VALUES)
public void testAddAll_nullUnsupported() {
List<E> containsNull = singletonList(null);
@@ -156,7 +135,7 @@ public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
"Should not contain null after unsupported addAll(containsNull)");
}
- @CollectionFeature.Require(SUPPORTS_ADD)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
public void testAddAll_nullCollectionReference() {
try {
collection.addAll(null);
@@ -172,8 +151,7 @@ public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147">Sun
* bug 5045147</a> is fixed.
*/
- @GwtIncompatible("reflection")
public static Method getAddAllNullUnsupportedMethod() {
- return Helpers.getMethod(CollectionAddAllTester.class, "testAddAll_nullUnsupported");
+ return Platform.getMethod(CollectionAddAllTester.class, "testAddAll_nullUnsupported");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddTester.java
index afe276b..1de5b14 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionAddTester.java
@@ -17,21 +17,15 @@
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.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
-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.lang.reflect.Method;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
/**
* A generic JUnit test which tests {@code add} operations on a collection.
@@ -44,7 +38,6 @@ import java.util.Iterator;
* @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() {
@@ -96,20 +89,6 @@ public class CollectionAddTester<E> extends AbstractCollectionTester<E> {
"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
- }
- }
-
/**
* Returns the {@link Method} instance for {@link #testAdd_nullSupported()} so
* that tests of {@link
@@ -122,20 +101,20 @@ public class CollectionAddTester<E> extends AbstractCollectionTester<E> {
* seems more likely that code would depend on that behavior than on the
* other. Thus, we say the bug is in add(), which fails to support null.
*/
- @GwtIncompatible("reflection")
public static Method getAddNullSupportedMethod() {
- return Helpers.getMethod(CollectionAddTester.class, "testAdd_nullSupported");
+ return Platform.getMethod(CollectionAddTester.class, "testAdd_nullSupported");
}
/**
- * Returns the {@link Method} instance for {@link #testAdd_nullSupported()}
- * so that tests of {@link java.util.TreeSet} can suppress it with {@code
- * FeatureSpecificTestSuiteBuilder.suppressing()} until <a
- * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147">Sun bug
- * 5045147</a> is fixed.
+ * Returns the {@link Method} instance for {@link #testAdd_nullSupported()} so
+ * that tests of {@link
+ * java.util.Collections#checkedCollection(java.util.Collection, Class)} can
+ * suppress it with {@code FeatureSpecificTestSuiteBuilder.suppressing()}
+ * until <a
+ * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147">Sun
+ * bug 5045147</a> is fixed.
*/
- @GwtIncompatible("reflection")
public static Method getAddNullUnsupportedMethod() {
- return Helpers.getMethod(CollectionAddTester.class, "testAdd_nullUnsupported");
+ return Platform.getMethod(CollectionAddTester.class, "testAdd_nullUnsupported");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionClearTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionClearTester.java
index a417e55..69f1d02 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionClearTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionClearTester.java
@@ -16,19 +16,13 @@
package com.google.common.collect.testing.testers;
-import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION;
-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.CollectionFeature.SUPPORTS_CLEAR;
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 clear()} operations on a collection.
* Can't be invoked directly; please see
@@ -38,16 +32,15 @@ import java.util.Iterator;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class CollectionClearTester<E> extends AbstractCollectionTester<E> {
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_CLEAR)
public void testClear() {
collection.clear();
assertTrue("After clear(), a collection should be empty.",
collection.isEmpty());
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_CLEAR)
@CollectionSize.Require(absent = ZERO)
public void testClear_unsupported() {
try {
@@ -59,7 +52,7 @@ public class CollectionClearTester<E> extends AbstractCollectionTester<E> {
expectUnchanged();
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_CLEAR)
@CollectionSize.Require(ZERO)
public void testClear_unsupportedByEmptyCollection() {
try {
@@ -68,22 +61,4 @@ public class CollectionClearTester<E> extends AbstractCollectionTester<E> {
}
expectUnchanged();
}
-
- @CollectionFeature.Require({SUPPORTS_REMOVE,
- FAILS_FAST_ON_CONCURRENT_MODIFICATION})
- @CollectionSize.Require(SEVERAL)
- public void testClearConcurrentWithIteration() {
- try {
- Iterator<E> iterator = collection.iterator();
- collection.clear();
- iterator.next();
- /*
- * We prefer for iterators to fail immediately on hasNext, but ArrayList
- * and LinkedList will notably return true on hasNext here!
- */
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsAllTester.java
index 4fd424b..40be02b 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsAllTester.java
@@ -20,7 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.ALLOW
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.MinimalCollection;
import com.google.common.collect.testing.WrongType;
@@ -40,7 +39,6 @@ import java.util.Collection;
* @author Chris Povirk
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class CollectionContainsAllTester<E>
extends AbstractCollectionTester<E> {
public void testContainsAll_empty() {
@@ -87,7 +85,6 @@ public class CollectionContainsAllTester<E>
}
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
- @CollectionSize.Require(absent = ZERO)
public void testContainsAll_nullPresent() {
initCollectionWithNullElement();
assertTrue(collection.containsAll(MinimalCollection.of((E) null)));
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsTester.java
index e8f754a..49337c3 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsTester.java
@@ -20,7 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.ALLOW
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.WrongType;
import com.google.common.collect.testing.features.CollectionFeature;
@@ -36,7 +35,6 @@ import com.google.common.collect.testing.features.CollectionSize;
* @author Kevin Bourrillion
* @author Chris Povirk
*/
-@GwtCompatible
public class CollectionContainsTester<E> extends AbstractCollectionTester<E> {
@CollectionSize.Require(absent = ZERO)
public void testContains_yes() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionCreationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionCreationTester.java
index 3e7499c..401a0f2 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionCreationTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionCreationTester.java
@@ -19,10 +19,7 @@ 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.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
-import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -37,7 +34,6 @@ import java.lang.reflect.Method;
*
* @author Chris Povirk
*/
-@GwtCompatible(emulated = true)
public class CollectionCreationTester<E> extends AbstractCollectionTester<E> {
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
@@ -66,8 +62,7 @@ public class CollectionCreationTester<E> extends AbstractCollectionTester<E> {
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147">Sun
* bug 5045147</a> is fixed.
*/
- @GwtIncompatible("reflection")
public static Method getCreateWithNullUnsupportedMethod() {
- return Helpers.getMethod(CollectionCreationTester.class, "testCreateWithNull_unsupported");
+ return Platform.getMethod(CollectionCreationTester.class, "testCreateWithNull_unsupported");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionEqualsTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionEqualsTester.java
index c59db0a..fe642fc 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionEqualsTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionEqualsTester.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
/**
@@ -26,7 +25,6 @@ import com.google.common.collect.testing.AbstractCollectionTester;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class CollectionEqualsTester<E> extends AbstractCollectionTester<E> {
public void testEquals_self() {
assertTrue("An Object should be equal to itself.",
@@ -45,4 +43,4 @@ public class CollectionEqualsTester<E> extends AbstractCollectionTester<E> {
+ "object that is not a Collection.",
collection.equals("huh?"));
}
-}
+} \ No newline at end of file
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIsEmptyTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIsEmptyTester.java
index 94e2c13..8d11f42 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIsEmptyTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIsEmptyTester.java
@@ -18,7 +18,6 @@ package com.google.common.collect.testing.testers;
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.CollectionSize;
@@ -31,7 +30,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public class CollectionIsEmptyTester<E> extends AbstractCollectionTester<E> {
@CollectionSize.Require(ZERO)
public void testIsEmpty_yes() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIteratorTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIteratorTester.java
index 6a8d567..3e54cfc 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIteratorTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionIteratorTester.java
@@ -21,8 +21,6 @@ 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.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.IteratorFeature;
@@ -48,7 +46,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
*
* @author Chris Povirk
*/
-@GwtCompatible(emulated = true)
public class CollectionIteratorTester<E> extends AbstractCollectionTester<E> {
public void testIterator() {
List<E> iteratorElements = new ArrayList<E>();
@@ -123,9 +120,8 @@ public class CollectionIteratorTester<E> extends AbstractCollectionTester<E> {
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6570575">Sun bug
* 6570575</a> is fixed.
*/
- @GwtIncompatible("reflection")
public static Method getIteratorKnownOrderRemoveSupportedMethod() {
- return Helpers.getMethod(
+ return Platform.getMethod(
CollectionIteratorTester.class, "testIterator_knownOrderRemoveSupported");
}
@@ -134,9 +130,8 @@ public class CollectionIteratorTester<E> extends AbstractCollectionTester<E> {
* {@link #testIterator_unknownOrderRemoveSupported()} so that tests of
* classes with unmodifiable iterators can suppress it.
*/
- @GwtIncompatible("reflection")
public static Method getIteratorUnknownOrderRemoveSupportedMethod() {
- return Helpers.getMethod(
+ return Platform.getMethod(
CollectionIteratorTester.class, "testIterator_unknownOrderRemoveSupported");
}
@@ -160,9 +155,8 @@ public class CollectionIteratorTester<E> extends AbstractCollectionTester<E> {
* supports {@code remove()} on only the first element, and the iterator
* tester can't handle that.
*/
- @GwtIncompatible("reflection")
public static Method getIteratorKnownOrderRemoveUnsupportedMethod() {
- return Helpers.getMethod(
+ return Platform.getMethod(
CollectionIteratorTester.class, "testIterator_knownOrderRemoveUnsupported");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveAllTester.java
index f607916..1005307 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveAllTester.java
@@ -18,12 +18,9 @@ package com.google.common.collect.testing.testers;
import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_QUERIES;
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.SUPPORTS_REMOVE;
-import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
+import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE_ALL;
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.MinimalCollection;
import com.google.common.collect.testing.WrongType;
@@ -31,8 +28,6 @@ import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
import java.util.Collections;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
/**
* A generic JUnit test which tests {@code removeAll} operations on a
@@ -45,23 +40,22 @@ import java.util.Iterator;
* @author Chris Povirk
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
public void testRemoveAll_emptyCollection() {
assertFalse("removeAll(emptyCollection) should return false",
collection.removeAll(MinimalCollection.of()));
expectUnchanged();
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
public void testRemoveAll_nonePresent() {
assertFalse("removeAll(disjointCollection) should return false",
collection.removeAll(MinimalCollection.of(samples.e3)));
expectUnchanged();
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_allPresent() {
assertTrue("removeAll(intersectingCollection) should return true",
@@ -69,7 +63,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
expectMissing(samples.e0);
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_somePresent() {
assertTrue("removeAll(intersectingCollection) should return true",
@@ -77,24 +71,10 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
expectMissing(samples.e0);
}
- @CollectionFeature.Require({SUPPORTS_REMOVE,
- FAILS_FAST_ON_CONCURRENT_MODIFICATION})
- @CollectionSize.Require(SEVERAL)
- public void testRemoveAllSomePresentConcurrentWithIteration() {
- try {
- Iterator<E> iterator = collection.iterator();
- assertTrue(collection.removeAll(MinimalCollection.of(samples.e0, samples.e3)));
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
/**
* Trigger the other.size() >= this.size() case in AbstractSet.removeAll().
*/
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_somePresentLargeCollectionToRemove() {
assertTrue("removeAll(largeIntersectingCollection) should return true",
@@ -104,7 +84,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
expectMissing(samples.e0);
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_REMOVE_ALL)
public void testRemoveAll_unsupportedEmptyCollection() {
try {
assertFalse("removeAll(emptyCollection) should return false or throw "
@@ -115,7 +95,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
expectUnchanged();
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_REMOVE_ALL)
public void testRemoveAll_unsupportedNonePresent() {
try {
assertFalse("removeAll(disjointCollection) should return false or throw "
@@ -126,7 +106,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
expectUnchanged();
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_REMOVE_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_unsupportedPresent() {
try {
@@ -146,7 +126,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
* suppress only the former.
*/
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
@CollectionSize.Require(ZERO)
public void testRemoveAll_nullCollectionReferenceEmptySubject() {
try {
@@ -156,7 +136,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
}
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_nullCollectionReferenceNonEmptySubject() {
try {
@@ -166,7 +146,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
}
}
- @CollectionFeature.Require(value = SUPPORTS_REMOVE,
+ @CollectionFeature.Require(value = SUPPORTS_REMOVE_ALL,
absent = ALLOWS_NULL_QUERIES)
public void testRemoveAll_containsNullNo() {
MinimalCollection<?> containsNull = MinimalCollection.of((Object) null);
@@ -178,7 +158,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
expectUnchanged();
}
- @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_QUERIES})
+ @CollectionFeature.Require({SUPPORTS_REMOVE_ALL, ALLOWS_NULL_QUERIES})
public void testRemoveAll_containsNullNoButAllowed() {
MinimalCollection<?> containsNull = MinimalCollection.of((Object) null);
assertFalse("removeAll(containsNull) should return false",
@@ -186,7 +166,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
expectUnchanged();
}
- @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
+ @CollectionFeature.Require({SUPPORTS_REMOVE_ALL, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_containsNullYes() {
initCollectionWithNullElement();
@@ -195,7 +175,7 @@ public class CollectionRemoveAllTester<E> extends AbstractCollectionTester<E> {
// TODO: make this work with MinimalCollection
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
public void testRemoveAll_containsWrongType() {
try {
assertFalse("removeAll(containsWrongType) should return false or throw",
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveTester.java
index 3818fd9..2d051bc 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveTester.java
@@ -18,18 +18,14 @@ package com.google.common.collect.testing.testers;
import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_QUERIES;
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.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.testing.AbstractCollectionTester;
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.ConcurrentModificationException;
import java.util.Iterator;
/**
@@ -42,7 +38,6 @@ import java.util.Iterator;
* @author George van den Driessche
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class CollectionRemoveTester<E> extends AbstractCollectionTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
@@ -55,20 +50,6 @@ public class CollectionRemoveTester<E> extends AbstractCollectionTester<E> {
expectMissing(samples.e0);
}
- @CollectionFeature.Require({SUPPORTS_REMOVE,
- FAILS_FAST_ON_CONCURRENT_MODIFICATION})
- @CollectionSize.Require(SEVERAL)
- public void testRemovePresentConcurrentWithIteration() {
- try {
- Iterator<E> iterator = collection.iterator();
- assertTrue(collection.remove(samples.e0));
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemove_notPresent() {
assertFalse("remove(notPresent) should return false",
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRetainAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRetainAllTester.java
index 693c0b1..fbfd0d8 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRetainAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionRetainAllTester.java
@@ -17,11 +17,10 @@
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_REMOVE;
+import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_RETAIN_ALL;
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.testing.AbstractCollectionTester;
import com.google.common.collect.testing.MinimalCollection;
import com.google.common.collect.testing.features.CollectionFeature;
@@ -42,7 +41,6 @@ import java.util.List;
* @author Chris Povirk
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
/**
@@ -105,21 +103,21 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// retainAll(empty)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(ZERO)
public void testRetainAll_emptyPreviouslyEmpty() {
expectReturnsFalse(empty);
expectUnchanged();
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(ZERO)
public void testRetainAll_emptyPreviouslyEmptyUnsupported() {
expectReturnsFalseOrThrows(empty);
expectUnchanged();
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRetainAll_emptyPreviouslyNonEmpty() {
expectReturnsTrue(empty);
@@ -127,7 +125,7 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
expectMissing(samples.e0, samples.e1, samples.e2);
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRetainAll_emptyPreviouslyNonEmptyUnsupported() {
expectThrows(empty);
@@ -136,21 +134,21 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// retainAll(disjoint)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(ZERO)
public void testRetainAll_disjointPreviouslyEmpty() {
expectReturnsFalse(disjoint);
expectUnchanged();
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(ZERO)
public void testRetainAll_disjointPreviouslyEmptyUnsupported() {
expectReturnsFalseOrThrows(disjoint);
expectUnchanged();
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRetainAll_disjointPreviouslyNonEmpty() {
expectReturnsTrue(disjoint);
@@ -158,7 +156,7 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
expectMissing(samples.e0, samples.e1, samples.e2);
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRetainAll_disjointPreviouslyNonEmptyUnsupported() {
expectThrows(disjoint);
@@ -167,13 +165,13 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// retainAll(superset)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
public void testRetainAll_superset() {
expectReturnsFalse(superset);
expectUnchanged();
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_RETAIN_ALL)
public void testRetainAll_supersetUnsupported() {
expectReturnsFalseOrThrows(superset);
expectUnchanged();
@@ -181,14 +179,14 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// retainAll(subset)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRetainAll_subset() {
expectReturnsTrue(nonEmptyProperSubset);
expectContents(nonEmptyProperSubset.toRetain);
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRetainAll_subsetUnsupported() {
expectThrows(nonEmptyProperSubset);
@@ -197,13 +195,13 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// retainAll(sameElements)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
public void testRetainAll_sameElements() {
expectReturnsFalse(sameElements);
expectUnchanged();
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_RETAIN_ALL)
public void testRetainAll_sameElementsUnsupported() {
expectReturnsFalseOrThrows(sameElements);
expectUnchanged();
@@ -211,14 +209,14 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// retainAll(partialOverlap)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRetainAll_partialOverlap() {
expectReturnsTrue(partialOverlap);
expectContents(samples.e2);
}
- @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
+ @CollectionFeature.Require(absent = SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRetainAll_partialOverlapUnsupported() {
expectThrows(partialOverlap);
@@ -227,14 +225,14 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// retainAll(containsDuplicates)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(ONE)
public void testRetainAll_containsDuplicatesSizeOne() {
expectReturnsFalse(containsDuplicates);
expectContents(samples.e0);
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRetainAll_containsDuplicatesSizeSeveral() {
expectReturnsTrue(containsDuplicates);
@@ -243,21 +241,21 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// retainAll(nullSingleton)
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(ZERO)
public void testRetainAll_nullSingletonPreviouslyEmpty() {
expectReturnsFalse(nullSingleton);
expectUnchanged();
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRetainAll_nullSingletonPreviouslyNonEmpty() {
expectReturnsTrue(nullSingleton);
expectContents();
}
- @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
+ @CollectionFeature.Require({SUPPORTS_RETAIN_ALL, ALLOWS_NULL_VALUES})
@CollectionSize.Require(ONE)
public void testRetainAll_nullSingletonPreviouslySingletonWithNull() {
initCollectionWithNullElement();
@@ -265,7 +263,7 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
expectContents(createArrayWithNullElement());
}
- @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
+ @CollectionFeature.Require({SUPPORTS_RETAIN_ALL, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRetainAll_nullSingletonPreviouslySeveralWithNull() {
initCollectionWithNullElement();
@@ -275,7 +273,7 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
// nullSingleton.retainAll()
- @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
+ @CollectionFeature.Require({SUPPORTS_RETAIN_ALL, ALLOWS_NULL_VALUES})
@CollectionSize.Require(absent = ZERO)
public void testRetainAll_containsNonNullWithNull() {
initCollectionWithNullElement();
@@ -292,7 +290,7 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
* suppress only the former.
*/
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(ZERO)
public void testRetainAll_nullCollectionReferenceEmptySubject() {
try {
@@ -302,7 +300,7 @@ public class CollectionRetainAllTester<E> extends AbstractCollectionTester<E> {
}
}
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = ZERO)
public void testRetainAll_nullCollectionReferenceNonEmptySubject() {
try {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSerializationEqualTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSerializationEqualTester.java
deleted file mode 100644
index 1fbfe26..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSerializationEqualTester.java
+++ /dev/null
@@ -1,40 +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.testers;
-
-import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE;
-
-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.testing.SerializableTester;
-
-/**
- * Basic reserialization test for collection types that must preserve {@code equals()} behavior
- * when reserialized. (Sets and Lists, but not bare Collections.)
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class CollectionSerializationEqualTester<E> extends AbstractCollectionTester<E> {
- @CollectionFeature.Require(SERIALIZABLE)
- public void testReserialize() {
- assertEquals(
- actualContents(),
- SerializableTester.reserialize(actualContents()));
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSerializationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSerializationTester.java
deleted file mode 100644
index bc4470e..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSerializationTester.java
+++ /dev/null
@@ -1,41 +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.testers;
-
-import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE;
-
-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.features.CollectionFeature;
-import com.google.common.testing.SerializableTester;
-
-/**
- * Basic reserialization test for collections.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class CollectionSerializationTester<E> extends AbstractCollectionTester<E> {
- @CollectionFeature.Require(SERIALIZABLE)
- public void testReserialize() {
- // For a bare Collection, the most we can guarantee is that the elements are preserved.
- Helpers.assertEqualIgnoringOrder(
- actualContents(),
- SerializableTester.reserialize(actualContents()));
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSizeTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSizeTester.java
index 0c9693d..f7fa87b 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSizeTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionSizeTester.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
/**
@@ -28,7 +27,6 @@ import com.google.common.collect.testing.AbstractCollectionTester;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public class CollectionSizeTester<E> extends AbstractCollectionTester<E> {
public void testSize() {
assertEquals("size():", getNumElements(), collection.size());
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionToArrayTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionToArrayTester.java
index d7de38b..3d65969 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionToArrayTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionToArrayTester.java
@@ -19,8 +19,6 @@ 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.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractCollectionTester;
import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.WrongType;
@@ -42,7 +40,6 @@ import java.util.List;
* @author Kevin Bourrillion
* @author Chris Povirk
*/
-@GwtCompatible(emulated = true)
public class CollectionToArrayTester<E> extends AbstractCollectionTester<E> {
public void testToArray_noArgs() {
Object[] array = collection.toArray();
@@ -195,8 +192,7 @@ public class CollectionToArrayTester<E> extends AbstractCollectionTester<E> {
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6260652">Sun bug
* 6260652</a> is fixed.
*/
- @GwtIncompatible("reflection")
public static Method getToArrayIsPlainObjectArrayMethod() {
- return Helpers.getMethod(CollectionToArrayTester.class, "testToArray_isPlainObjectArray");
+ return Platform.getMethod(CollectionToArrayTester.class, "testToArray_isPlainObjectArray");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionToStringTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionToStringTester.java
index 4d93fa9..120a112 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/CollectionToStringTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/CollectionToStringTester.java
@@ -22,7 +22,6 @@ 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.testing.AbstractCollectionTester;
import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.features.CollectionFeature;
@@ -37,7 +36,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public class CollectionToStringTester<E> extends AbstractCollectionTester<E> {
public void testToString_minimal() {
assertNotNull("toString() should not return null",
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllAtIndexTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllAtIndexTester.java
index 1844106..be64b0d 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllAtIndexTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllAtIndexTester.java
@@ -19,10 +19,10 @@ 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.ONE;
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
+import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_ALL_WITH_INDEX;
import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_ADD_WITH_INDEX;
import static java.util.Collections.singletonList;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.MinimalCollection;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -40,9 +40,8 @@ import java.util.List;
* @author Chris Povirk
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_supportedAllPresent() {
assertTrue("addAll(n, allPresent) should return true",
@@ -50,7 +49,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectAdded(0, samples.e0);
}
- @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(absent = SUPPORTS_ADD_ALL_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_unsupportedAllPresent() {
try {
@@ -61,7 +60,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectUnchanged();
}
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_supportedSomePresent() {
assertTrue("addAll(n, allPresent) should return true",
@@ -69,7 +68,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectAdded(0, samples.e0, samples.e3);
}
- @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(absent = SUPPORTS_ADD_ALL_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_unsupportedSomePresent() {
try {
@@ -81,14 +80,14 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectMissing(samples.e3);
}
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
public void testAddAllAtIndex_supportedNothing() {
assertFalse("addAll(n, nothing) should return false",
getList().addAll(0, emptyCollection()));
expectUnchanged();
}
- @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(absent = SUPPORTS_ADD_ALL_WITH_INDEX)
public void testAddAllAtIndex_unsupportedNothing() {
try {
assertFalse("addAll(n, nothing) should return false or throw",
@@ -98,7 +97,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectUnchanged();
}
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
public void testAddAllAtIndex_withDuplicates() {
MinimalCollection<E> elementsToAdd
= MinimalCollection.of(samples.e0, samples.e1, samples.e0, samples.e1);
@@ -107,7 +106,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectAdded(0, samples.e0, samples.e1, samples.e0, samples.e1);
}
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testAddAllAtIndex_nullSupported() {
List<E> containsNull = singletonList(null);
@@ -120,7 +119,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectAdded(0, (E) null);
}
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
@CollectionFeature.Require(absent = ALLOWS_NULL_VALUES)
public void testAddAllAtIndex_nullUnsupported() {
List<E> containsNull = singletonList(null);
@@ -134,7 +133,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
"Should not contain null after unsupported addAll(n, containsNull)");
}
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testAddAllAtIndex_middle() {
assertTrue("addAll(middle, disjoint) should return true",
@@ -142,7 +141,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectAdded(getNumElements() / 2, createDisjointCollection());
}
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_end() {
assertTrue("addAll(end, disjoint) should return true",
@@ -150,7 +149,7 @@ public class ListAddAllAtIndexTester<E> extends AbstractListTester<E> {
expectAdded(getNumElements(), createDisjointCollection());
}
- @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
+ @ListFeature.Require(SUPPORTS_ADD_ALL_WITH_INDEX)
public void testAddAllAtIndex_nullCollectionReference() {
try {
getList().addAll(0, null);
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllTester.java
index f76d5db..3e9cb49 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAllTester.java
@@ -16,10 +16,9 @@
package com.google.common.collect.testing.testers;
-import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD;
+import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD_ALL;
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.MinimalCollection;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -34,9 +33,8 @@ import com.google.common.collect.testing.features.CollectionSize;
* @author Chris Povirk
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class ListAddAllTester<E> extends AbstractListTester<E> {
- @CollectionFeature.Require(SUPPORTS_ADD)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_supportedAllPresent() {
assertTrue("addAll(allPresent) should return true",
@@ -44,7 +42,7 @@ public class ListAddAllTester<E> extends AbstractListTester<E> {
expectAdded(samples.e0);
}
- @CollectionFeature.Require(absent = SUPPORTS_ADD)
+ @CollectionFeature.Require(absent = SUPPORTS_ADD_ALL)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_unsupportedAllPresent() {
try {
@@ -55,7 +53,7 @@ public class ListAddAllTester<E> extends AbstractListTester<E> {
expectUnchanged();
}
- @CollectionFeature.Require(SUPPORTS_ADD)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
public void testAddAll_withDuplicates() {
MinimalCollection<E> elementsToAdd
= MinimalCollection.of(samples.e0, samples.e1, samples.e0, samples.e1);
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAtIndexTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAtIndexTester.java
index ab92dd9..9721393 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAtIndexTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListAddAtIndexTester.java
@@ -17,21 +17,15 @@
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.annotations.GwtIncompatible;
-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 java.lang.reflect.Method;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
/**
* A generic JUnit test which tests {@code add(int, Object)} operations on a
@@ -43,7 +37,6 @@ import java.util.Iterator;
* @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)
@@ -73,19 +66,6 @@ public class ListAddAtIndexTester<E> extends AbstractListTester<E> {
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 {
@@ -158,9 +138,8 @@ public class ListAddAtIndexTester<E> extends AbstractListTester<E> {
* {@link #testAddAtIndex_nullSupported()} so that tests can suppress it. See
* {@link CollectionAddTester#getAddNullSupportedMethod()} for details.
*/
- @GwtIncompatible("reflection")
public static Method getAddNullSupportedMethod() {
- return Helpers.getMethod(
+ return Platform.getMethod(
ListAddAtIndexTester.class, "testAddAtIndex_nullSupported");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListAddTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListAddTester.java
index d974761..0fc8dd0 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListAddTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListAddTester.java
@@ -20,8 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.ALLOW
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.annotations.GwtIncompatible;
import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -39,7 +37,6 @@ import java.util.List;
* @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)
@@ -79,8 +76,7 @@ public class ListAddTester<E> extends AbstractListTester<E> {
* {@link #testAdd_supportedNullPresent()} so that tests can suppress it. See
* {@link CollectionAddTester#getAddNullSupportedMethod()} for details.
*/
- @GwtIncompatible("reflection")
public static Method getAddSupportedNullPresentMethod() {
- return Helpers.getMethod(ListAddTester.class, "testAdd_supportedNullPresent");
+ return Platform.getMethod(ListAddTester.class, "testAdd_supportedNullPresent");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListCreationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListCreationTester.java
index 257ffab..601eea4 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListCreationTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListCreationTester.java
@@ -20,7 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.REJEC
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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -33,7 +32,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Chris Povirk
*/
-@GwtCompatible
public class ListCreationTester<E> extends AbstractListTester<E> {
@CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
@CollectionSize.Require(absent = {ZERO, ONE})
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListEqualsTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListEqualsTester.java
index c1adc6a..9e7e13e 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListEqualsTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListEqualsTester.java
@@ -18,7 +18,6 @@ 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.MinimalSet;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -34,12 +33,11 @@ import java.util.List;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class ListEqualsTester<E> extends AbstractListTester<E> {
public void testEquals_otherListWithSameElements() {
assertTrue(
"A List should equal any other List containing the same elements.",
- getList().equals(new ArrayList<E>(getOrderedElements())));
+ getList().equals(new ArrayList<E>(getSampleElements())));
}
@CollectionSize.Require(absent = CollectionSize.ZERO)
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListGetTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListGetTester.java
index eed4112..340e0cb 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListGetTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListGetTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
-
/**
* A generic JUnit test which tests {@code get()} operations on a list. Can't be
* invoked directly; please see
@@ -27,11 +25,10 @@ import com.google.common.annotations.GwtCompatible;
*
* @author Chris Povirk
*/
-@GwtCompatible
public class ListGetTester<E> extends AbstractListTester<E> {
public void testGet_valid() {
// This calls get() on each index and checks the result:
- expectContents(createOrderedArray());
+ expectContents(createSamplesArray());
}
public void testGet_negative() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListHashCodeTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListHashCodeTester.java
index 30ed6c2..f7f3291 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListHashCodeTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListHashCodeTester.java
@@ -16,10 +16,6 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.annotations.GwtIncompatible;
-import com.google.common.collect.testing.Helpers;
-
import java.lang.reflect.Method;
/**
@@ -29,11 +25,10 @@ import java.lang.reflect.Method;
*
* @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()) {
+ for (E element : getSampleElements()) {
expectedHashCode = 31 * expectedHashCode +
((element == null) ? 0 : element.hashCode());
}
@@ -47,8 +42,7 @@ public class ListHashCodeTester<E> extends AbstractListTester<E> {
* list tests on unhashable objects can suppress it with
* {@code FeatureSpecificTestSuiteBuilder.suppressing()}.
*/
- @GwtIncompatible("reflection")
public static Method getHashCodeMethod() {
- return Helpers.getMethod(ListHashCodeTester.class, "testHashCode");
+ return Platform.getMethod(ListHashCodeTester.class, "testHashCode");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListIndexOfTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListIndexOfTester.java
index 5da84e8..4c96c19 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListIndexOfTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListIndexOfTester.java
@@ -20,7 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.REJEC
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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -33,7 +32,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Chris Povirk
*/
-@GwtCompatible
public class ListIndexOfTester<E> extends AbstractListIndexOfTester<E> {
@Override protected int find(Object o) {
return getList().indexOf(o);
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListLastIndexOfTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListLastIndexOfTester.java
index 041a22d..a3f9812 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListLastIndexOfTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListLastIndexOfTester.java
@@ -20,7 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.REJEC
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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -33,7 +32,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Chris Povirk
*/
-@GwtCompatible
public class ListLastIndexOfTester<E> extends AbstractListIndexOfTester<E> {
@Override protected int find(Object o) {
return getList().lastIndexOf(o);
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListListIteratorTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListListIteratorTester.java
index 438634b..c8c8d6f 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListListIteratorTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListListIteratorTester.java
@@ -24,8 +24,6 @@ import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_SE
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.annotations.GwtIncompatible;
import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.IteratorFeature;
import com.google.common.collect.testing.ListIteratorTester;
@@ -48,7 +46,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
* @author Chris Povirk
* @author Kevin Bourrillion
*/
-@GwtCompatible(emulated = true)
public class ListListIteratorTester<E> extends AbstractListTester<E> {
// TODO: switch to DerivedIteratorTestSuiteBuilder
@@ -71,7 +68,7 @@ public class ListListIteratorTester<E> extends AbstractListTester<E> {
private void runListIteratorTest(Set<IteratorFeature> features) {
new ListIteratorTester<E>(
listListIteratorTesterNumIterations(), singleton(samples.e4), features,
- Helpers.copyToList(getOrderedElements()), 0) {
+ Helpers.copyToList(getSampleElements()), 0) {
{
// TODO: don't set this universally
stopTestingWhenAddThrowsException();
@@ -117,9 +114,8 @@ public class ListListIteratorTester<E> extends AbstractListTester<E> {
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6570575">Sun bug
* 6570575</a> is fixed.
*/
- @GwtIncompatible("reflection")
public static Method getListIteratorFullyModifiableMethod() {
- return Helpers.getMethod(
+ return Platform.getMethod(
ListListIteratorTester.class, "testListIterator_fullyModifiable");
}
@@ -128,9 +124,8 @@ public class ListListIteratorTester<E> extends AbstractListTester<E> {
* {@link #testListIterator_unmodifiable()} so that it can be suppressed in
* GWT tests.
*/
- @GwtIncompatible("reflection")
public static Method getListIteratorUnmodifiableMethod() {
- return Helpers.getMethod(
+ return Platform.getMethod(
ListListIteratorTester.class, "testListIterator_unmodifiable");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAllTester.java
index 8eb83ec..faeec46 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAllTester.java
@@ -16,11 +16,10 @@
package com.google.common.collect.testing.testers;
-import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;
+import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE_ALL;
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.testing.MinimalCollection;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -35,9 +34,8 @@ import com.google.common.collect.testing.features.CollectionSize;
* @author George van den Driessche
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class ListRemoveAllTester<E> extends AbstractListTester<E> {
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_REMOVE_ALL)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRemoveAll_duplicate() {
ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAtIndexTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAtIndexTester.java
index 47c1e95..cb37c67 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAtIndexTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAtIndexTester.java
@@ -16,19 +16,14 @@
package com.google.common.collect.testing.testers;
-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_REMOVE_WITH_INDEX;
-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 java.util.ConcurrentModificationException;
-import java.util.Iterator;
import java.util.List;
/**
@@ -40,7 +35,6 @@ import java.util.List;
*
* @author Chris Povirk
*/
-@GwtCompatible
public class ListRemoveAtIndexTester<E> extends AbstractListTester<E> {
@ListFeature.Require(absent = SUPPORTS_REMOVE_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
@@ -85,20 +79,6 @@ public class ListRemoveAtIndexTester<E> extends AbstractListTester<E> {
runRemoveTest(getNumElements() / 2);
}
- @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
- @ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
- @CollectionSize.Require(absent = ZERO)
- public void testRemoveAtIndexConcurrentWithIteration() {
- try {
- Iterator<E> iterator = collection.iterator();
- getList().remove(getNumElements() / 2);
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAtIndex_last() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveTester.java
index e338ca0..0094928 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveTester.java
@@ -20,7 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.SUPPO
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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -33,7 +32,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class ListRemoveTester<E> extends AbstractListTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = {ZERO, ONE})
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListRetainAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListRetainAllTester.java
index 872e096..2ede664 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListRetainAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListRetainAllTester.java
@@ -16,12 +16,11 @@
package com.google.common.collect.testing.testers;
-import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;
+import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_RETAIN_ALL;
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.testing.MinimalCollection;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -35,9 +34,8 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Chris Povirk
*/
-@GwtCompatible
public class ListRetainAllTester<E> extends AbstractListTester<E> {
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRetainAll_duplicatesKept() {
E[] array = createSamplesArray();
@@ -49,7 +47,7 @@ public class ListRetainAllTester<E> extends AbstractListTester<E> {
}
@SuppressWarnings("unchecked")
- @CollectionFeature.Require(SUPPORTS_REMOVE)
+ @CollectionFeature.Require(SUPPORTS_RETAIN_ALL)
@CollectionSize.Require(SEVERAL)
public void testRetainAll_duplicatesRemoved() {
E[] array = createSamplesArray();
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListSetTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListSetTester.java
index df3b8ad..2b3b7b0 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListSetTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListSetTester.java
@@ -20,9 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.ALLOW
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.annotations.GwtIncompatible;
-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;
@@ -38,7 +35,6 @@ import java.lang.reflect.Method;
*
* @author George van den Driessche
*/
-@GwtCompatible(emulated = true)
public class ListSetTester<E> extends AbstractListTester<E> {
@ListFeature.Require(SUPPORTS_SET)
@CollectionSize.Require(absent = ZERO)
@@ -149,8 +145,7 @@ public class ListSetTester<E> extends AbstractListTester<E> {
* seems more likely that code would depend on that behavior than on the
* other. Thus, we say the bug is in set(), which fails to support null.
*/
- @GwtIncompatible("reflection")
public static Method getSetNullSupportedMethod() {
- return Helpers.getMethod(ListSetTester.class, "testSet_null");
+ return Platform.getMethod(ListSetTester.class, "testSet_null");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListSubListTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListSubListTester.java
index e01dce5..7ba68ba 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListSubListTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListSubListTester.java
@@ -16,8 +16,6 @@
package com.google.common.collect.testing.testers;
-import static com.google.common.collect.testing.Helpers.getMethod;
-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;
@@ -25,13 +23,9 @@ import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_RE
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.annotations.GwtIncompatible;
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.lang.reflect.Method;
import java.util.Arrays;
@@ -49,7 +43,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
* @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 {
@@ -178,7 +171,7 @@ public class ListSubListTester<E> extends AbstractListTester<E> {
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);
+ Collections.singletonList(samples.e1), subList);
}
@CollectionSize.Require(absent = {ZERO})
@@ -305,22 +298,6 @@ public class ListSubListTester<E> extends AbstractListTester<E> {
-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));
- }
-
/**
* Returns the {@link Method} instance for
* {@link #testSubList_originalListSetAffectsSubList()} so that tests
@@ -329,9 +306,9 @@ public class ListSubListTester<E> extends AbstractListTester<E> {
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6570631">Sun bug
* 6570631</a> is fixed.
*/
- @GwtIncompatible("reflection")
public static Method getSubListOriginalListSetAffectsSubListMethod() {
- return getMethod(ListSubListTester.class, "testSubList_originalListSetAffectsSubList");
+ return Platform
+ .getMethod(ListSubListTester.class, "testSubList_originalListSetAffectsSubList");
}
/**
@@ -342,9 +319,10 @@ public class ListSubListTester<E> extends AbstractListTester<E> {
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6570631">Sun bug
* 6570631</a> is fixed.
*/
- @GwtIncompatible("reflection")
- public static Method getSubListOriginalListSetAffectsSubListLargeListMethod() {
- return getMethod(ListSubListTester.class, "testSubList_originalListSetAffectsSubListLargeList");
+ public static Method
+ getSubListOriginalListSetAffectsSubListLargeListMethod() {
+ return Platform
+ .getMethod(ListSubListTester.class, "testSubList_originalListSetAffectsSubListLargeList");
}
/**
@@ -355,9 +333,9 @@ public class ListSubListTester<E> extends AbstractListTester<E> {
* href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6570575">Sun bug
* 6570575</a> is fixed.
*/
- @GwtIncompatible("reflection")
public static Method getSubListSubListRemoveAffectsOriginalLargeListMethod() {
- return getMethod(ListSubListTester.class, "testSubList_subListRemoveAffectsOriginalLargeList");
+ return Platform.getMethod(
+ ListSubListTester.class, "testSubList_subListRemoveAffectsOriginalLargeList");
}
/*
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/ListToArrayTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/ListToArrayTester.java
index ca11aba..f990ffb 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/ListToArrayTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/ListToArrayTester.java
@@ -18,7 +18,6 @@ package com.google.common.collect.testing.testers;
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.features.CollectionSize;
import java.util.Arrays;
@@ -32,27 +31,26 @@ import java.util.Arrays;
*
* @author Chris Povirk
*/
-@GwtCompatible
public class ListToArrayTester<E> extends AbstractListTester<E> {
// CollectionToArrayTester tests everything except ordering.
public void testToArray_noArg() {
Object[] actual = getList().toArray();
assertArrayEquals("toArray() order should match list",
- createOrderedArray(), actual);
+ createSamplesArray(), actual);
}
@CollectionSize.Require(absent = ZERO)
public void testToArray_tooSmall() {
Object[] actual = getList().toArray(new Object[0]);
assertArrayEquals("toArray(tooSmall) order should match list",
- createOrderedArray(), actual);
+ createSamplesArray(), actual);
}
public void testToArray_largeEnough() {
Object[] actual = getList().toArray(new Object[getNumElements()]);
assertArrayEquals("toArray(largeEnough) order should match list",
- createOrderedArray(), actual);
+ createSamplesArray(), actual);
}
private static void assertArrayEquals(String message, Object[] expected,
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapClearTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapClearTester.java
index 2f341ff..302df11 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapClearTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapClearTester.java
@@ -16,20 +16,13 @@
package com.google.common.collect.testing.testers;
-import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
-import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION;
-import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
+import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_CLEAR;
-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.Entry;
-
/**
* A generic JUnit test which tests {@code clear()} operations on a map.
* Can't be invoked directly; please see
@@ -40,58 +33,15 @@ import java.util.Map.Entry;
* @author George van den Driessche
* @author Chris Povirk
*/
-@GwtCompatible
public class MapClearTester<K, V> extends AbstractMapTester<K, V> {
- @MapFeature.Require(SUPPORTS_REMOVE)
+ @MapFeature.Require(SUPPORTS_CLEAR)
public void testClear() {
getMap().clear();
assertTrue("After clear(), a map should be empty.",
getMap().isEmpty());
}
- @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- SUPPORTS_REMOVE})
- @CollectionSize.Require(SEVERAL)
- public void testClearConcurrentWithEntrySetIteration() {
- try {
- Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator();
- getMap().clear();
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
- @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- SUPPORTS_REMOVE})
- @CollectionSize.Require(SEVERAL)
- public void testClearConcurrentWithKeySetIteration() {
- try {
- Iterator<K> iterator = getMap().keySet().iterator();
- getMap().clear();
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
- @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- SUPPORTS_REMOVE})
- @CollectionSize.Require(SEVERAL)
- public void testClearConcurrentWithValuesIteration() {
- try {
- Iterator<V> iterator = getMap().values().iterator();
- getMap().clear();
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
- @MapFeature.Require(absent = SUPPORTS_REMOVE)
+ @MapFeature.Require(absent = SUPPORTS_CLEAR)
@CollectionSize.Require(absent = ZERO)
public void testClear_unsupported() {
try {
@@ -103,7 +53,7 @@ public class MapClearTester<K, V> extends AbstractMapTester<K, V> {
expectUnchanged();
}
- @MapFeature.Require(absent = SUPPORTS_REMOVE)
+ @MapFeature.Require(absent = SUPPORTS_CLEAR)
@CollectionSize.Require(ZERO)
public void testClear_unsupportedByEmptyCollection() {
try {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsKeyTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsKeyTester.java
index 7a69636..cbfeaf4 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsKeyTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsKeyTester.java
@@ -20,7 +20,6 @@ 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_QUERIES;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractMapTester;
import com.google.common.collect.testing.WrongType;
import com.google.common.collect.testing.features.CollectionSize;
@@ -35,7 +34,6 @@ import com.google.common.collect.testing.features.MapFeature;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class MapContainsKeyTester<K, V> extends AbstractMapTester<K, V> {
@CollectionSize.Require(absent = ZERO)
public void testContains_yes() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsValueTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsValueTester.java
index e587f67..7c44040 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsValueTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapContainsValueTester.java
@@ -19,7 +19,6 @@ 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.*;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractMapTester;
import com.google.common.collect.testing.WrongType;
import com.google.common.collect.testing.features.CollectionSize;
@@ -35,7 +34,6 @@ import com.google.common.collect.testing.features.MapFeature;
* @author George van den Driessche
* @author Chris Povirk
*/
-@GwtCompatible
public class MapContainsValueTester<K, V> extends AbstractMapTester<K, V> {
@CollectionSize.Require(absent = ZERO)
public void testContains_yes() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapCreationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapCreationTester.java
index 499a53b..00f8bfc 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapCreationTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapCreationTester.java
@@ -22,14 +22,10 @@ import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_
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.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractMapTester;
-import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
-import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
@@ -44,7 +40,6 @@ import java.util.Map.Entry;
* @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)
@@ -126,13 +121,13 @@ public class MapCreationTester<K, V> extends AbstractMapTester<K, V> {
private Entry<K, V>[] getEntriesMultipleNullKeys() {
Entry<K, V>[] entries = createArrayWithNullKey();
- entries[0] = entry(null, entries[0].getValue());
+ entries[0] = entries[getNullLocation()];
return entries;
}
private Entry<K, V>[] getEntriesMultipleNonNullKeys() {
Entry<K, V>[] entries = createSamplesArray();
- entries[0] = entry(samples.e1.getKey(), samples.e0.getValue());
+ entries[0] = samples.e1;
return entries;
}
@@ -143,16 +138,4 @@ public class MapCreationTester<K, V> extends AbstractMapTester<K, V> {
Arrays.asList(entries).subList(1, getNumElements());
expectContents(expectedWithDuplicateRemoved);
}
-
- /**
- * Returns the {@link Method} instance for {@link
- * #testCreateWithNullKeyUnsupported()} so that tests can suppress it
- * with {@code FeatureSpecificTestSuiteBuilder.suppressing()} until <a
- * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147">Sun
- * bug 5045147</a> is fixed.
- */
- @GwtIncompatible("reflection")
- public static Method getCreateWithNullKeyUnsupportedMethod() {
- return Helpers.getMethod(MapCreationTester.class, "testCreateWithNullKeyUnsupported");
- }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapEqualsTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapEqualsTester.java
index b73c523..66b71e7 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapEqualsTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapEqualsTester.java
@@ -19,7 +19,6 @@ package com.google.common.collect.testing.testers;
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractMapTester;
import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.features.CollectionSize;
@@ -38,7 +37,6 @@ import java.util.Map.Entry;
* @author George van den Driessche
* @author Chris Povirk
*/
-@GwtCompatible
public class MapEqualsTester<K, V> extends AbstractMapTester<K, V> {
public void testEquals_otherMapWithSameEntries() {
assertTrue(
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapGetTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapGetTester.java
index a1c934d..9860931 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapGetTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapGetTester.java
@@ -20,7 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.ALLOW
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractMapTester;
import com.google.common.collect.testing.WrongType;
import com.google.common.collect.testing.features.CollectionFeature;
@@ -37,7 +36,6 @@ import com.google.common.collect.testing.features.MapFeature;
* @author Kevin Bourrillion
* @author Chris Povirk
*/
-@GwtCompatible
public class MapGetTester<K, V> extends AbstractMapTester<K, V> {
@CollectionSize.Require(absent = ZERO)
public void testGet_yes() {
@@ -61,7 +59,7 @@ public class MapGetTester<K, V> extends AbstractMapTester<K, V> {
} catch (NullPointerException tolerated) {
}
}
-
+
@MapFeature.Require(ALLOWS_NULL_KEYS)
@CollectionSize.Require(absent = ZERO)
public void testGet_nonNullWhenNullContained() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapHashCodeTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapHashCodeTester.java
index c2483bc..ccfde43 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapHashCodeTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapHashCodeTester.java
@@ -19,7 +19,6 @@ package com.google.common.collect.testing.testers;
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_VALUES;
-import com.google.common.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;
@@ -35,7 +34,6 @@ import java.util.Map;
* @author George van den Driessche
* @author Chris Povirk
*/
-@GwtCompatible
public class MapHashCodeTester<K, V> extends AbstractMapTester<K, V> {
public void testHashCode() {
int expectedHashCode = 0;
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapIsEmptyTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapIsEmptyTester.java
index 8eb31da..8d27eb7 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapIsEmptyTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapIsEmptyTester.java
@@ -18,7 +18,6 @@ package com.google.common.collect.testing.testers;
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractMapTester;
import com.google.common.collect.testing.features.CollectionSize;
@@ -31,7 +30,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible
public class MapIsEmptyTester<K, V> extends AbstractMapTester<K, V> {
@CollectionSize.Require(ZERO)
public void testIsEmpty_yes() {
@@ -42,4 +40,4 @@ public class MapIsEmptyTester<K, V> extends AbstractMapTester<K, V> {
public void testIsEmpty_no() {
assertFalse("isEmpty() should return false", getMap().isEmpty());
}
-}
+} \ No newline at end of file
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/NavigableMapNavigationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapNavigationTester.java
index 26f9918..8c2bf60 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/NavigableMapNavigationTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapNavigationTester.java
@@ -31,15 +31,16 @@ import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.NavigableMap;
+import java.util.NoSuchElementException;
/**
* A generic JUnit test which tests operations on a NavigableMap. Can't be
- * invoked directly; please see {@code NavigableMapTestSuiteBuilder}.
+ * invoked directly; please see {@code MapTestSuiteBuilder}.
*
* @author Jesse Wilson
* @author Louis Wasserman
*/
-public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V> {
+public class MapNavigationTester<K, V> extends AbstractMapTester<K, V> {
private NavigableMap<K, V> navigableMap;
private List<Entry<K, V>> entries;
@@ -78,6 +79,11 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
@CollectionSize.Require(ZERO)
public void testEmptyMapFirst() {
assertNull(navigableMap.firstEntry());
+ try {
+ navigableMap.firstKey();
+ fail();
+ } catch (NoSuchElementException e) {
+ }
}
@MapFeature.Require(SUPPORTS_REMOVE)
@@ -101,7 +107,12 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
@CollectionSize.Require(ZERO)
public void testEmptyMapLast() {
assertNull(navigableMap.lastEntry());
- }
+ try {
+ assertNull(navigableMap.lastKey());
+ fail();
+ } catch (NoSuchElementException e) {
+ }
+ }
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(ZERO)
@@ -112,6 +123,7 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
@CollectionSize.Require(ONE)
public void testSingletonMapFirst() {
assertEquals(a, navigableMap.firstEntry());
+ assertEquals(a.getKey(), navigableMap.firstKey());
}
@MapFeature.Require(SUPPORTS_REMOVE)
@@ -136,6 +148,7 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
@CollectionSize.Require(ONE)
public void testSingletonMapLast() {
assertEquals(a, navigableMap.lastEntry());
+ assertEquals(a.getKey(), navigableMap.lastKey());
}
@MapFeature.Require(SUPPORTS_REMOVE)
@@ -148,6 +161,7 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
@CollectionSize.Require(SEVERAL)
public void testFirst() {
assertEquals(a, navigableMap.firstEntry());
+ assertEquals(a.getKey(), navigableMap.firstKey());
}
@MapFeature.Require(SUPPORTS_REMOVE)
@@ -166,7 +180,7 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
} catch (UnsupportedOperationException e) {
}
}
-
+
@CollectionSize.Require(SEVERAL)
public void testLower() {
resetWithHole();
@@ -177,7 +191,7 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
assertEquals(a, navigableMap.lowerEntry(c.getKey()));
assertEquals(a.getKey(), navigableMap.lowerKey(c.getKey()));
}
-
+
@CollectionSize.Require(SEVERAL)
public void testFloor() {
resetWithHole();
@@ -210,12 +224,13 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
assertEquals(null, navigableMap.higherEntry(c.getKey()));
assertEquals(null, navigableMap.higherKey(c.getKey()));
}
-
+
@CollectionSize.Require(SEVERAL)
public void testLast() {
assertEquals(c, navigableMap.lastEntry());
+ assertEquals(c.getKey(), navigableMap.lastKey());
}
-
+
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(SEVERAL)
public void testPollLast() {
@@ -232,7 +247,7 @@ public class NavigableMapNavigationTester<K, V> extends AbstractMapTester<K, V>
fail();
} catch (UnsupportedOperationException e) {
}
- }
+ }
@CollectionSize.Require(SEVERAL)
public void testDescendingNavigation() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapPutAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapPutAllTester.java
index 41eec75..d36e736 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapPutAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapPutAllTester.java
@@ -19,22 +19,15 @@ 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 com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT_ALL;
import static java.util.Collections.singletonList;
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractMapTester;
-import com.google.common.collect.testing.Helpers;
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.lang.reflect.Method;
import java.util.Collections;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -51,7 +44,6 @@ import java.util.Map.Entry;
* @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;
@@ -62,13 +54,13 @@ public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> {
containsNullValue = singletonList(entry(samples.e3.getKey(), null));
}
- @MapFeature.Require(SUPPORTS_PUT)
+ @MapFeature.Require(SUPPORTS_PUT_ALL)
public void testPutAll_supportedNothing() {
getMap().putAll(emptyMap());
expectUnchanged();
}
- @MapFeature.Require(absent = SUPPORTS_PUT)
+ @MapFeature.Require(absent = SUPPORTS_PUT_ALL)
public void testPutAll_unsupportedNothing() {
try {
getMap().putAll(emptyMap());
@@ -77,13 +69,13 @@ public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> {
expectUnchanged();
}
- @MapFeature.Require(SUPPORTS_PUT)
+ @MapFeature.Require(SUPPORTS_PUT_ALL)
public void testPutAll_supportedNonePresent() {
putAll(createDisjointCollection());
expectAdded(samples.e3, samples.e4);
}
- @MapFeature.Require(absent = SUPPORTS_PUT)
+ @MapFeature.Require(absent = SUPPORTS_PUT_ALL)
public void testPutAll_unsupportedNonePresent() {
try {
putAll(createDisjointCollection());
@@ -94,28 +86,14 @@ public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> {
expectMissing(samples.e3, samples.e4);
}
- @MapFeature.Require(SUPPORTS_PUT)
+ @MapFeature.Require(SUPPORTS_PUT_ALL)
@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)
+ @MapFeature.Require(absent = SUPPORTS_PUT_ALL)
@CollectionSize.Require(absent = ZERO)
public void testPutAll_unsupportedSomePresent() {
try {
@@ -126,7 +104,7 @@ public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> {
expectUnchanged();
}
- @MapFeature.Require(absent = SUPPORTS_PUT)
+ @MapFeature.Require(absent = SUPPORTS_PUT_ALL)
@CollectionSize.Require(absent = ZERO)
public void testPutAll_unsupportedAllPresent() {
try {
@@ -136,16 +114,16 @@ public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> {
expectUnchanged();
}
- @MapFeature.Require({SUPPORTS_PUT,
+ @MapFeature.Require({SUPPORTS_PUT_ALL,
ALLOWS_NULL_KEYS})
public void testPutAll_nullKeySupported() {
putAll(containsNullKey);
expectAdded(containsNullKey.get(0));
}
- @MapFeature.Require(value = SUPPORTS_PUT,
+ @MapFeature.Require(value = SUPPORTS_PUT_ALL,
absent = ALLOWS_NULL_KEYS)
- public void testPutAll_nullKeyUnsupported() {
+ public void testAdd_nullKeyUnsupported() {
try {
putAll(containsNullKey);
fail("putAll(containsNullKey) should throw");
@@ -157,16 +135,16 @@ public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> {
"putAll(containsNullKey)");
}
- @MapFeature.Require({SUPPORTS_PUT,
+ @MapFeature.Require({SUPPORTS_PUT_ALL,
ALLOWS_NULL_VALUES})
public void testPutAll_nullValueSupported() {
putAll(containsNullValue);
expectAdded(containsNullValue.get(0));
}
- @MapFeature.Require(value = SUPPORTS_PUT,
+ @MapFeature.Require(value = SUPPORTS_PUT_ALL,
absent = ALLOWS_NULL_VALUES)
- public void testPutAll_nullValueUnsupported() {
+ public void testAdd_nullValueUnsupported() {
try {
putAll(containsNullValue);
fail("putAll(containsNullValue) should throw");
@@ -178,7 +156,7 @@ public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> {
"putAll(containsNullValue)");
}
- @MapFeature.Require(SUPPORTS_PUT)
+ @MapFeature.Require(SUPPORTS_PUT_ALL)
public void testPutAll_nullCollectionReference() {
try {
getMap().putAll(null);
@@ -198,16 +176,4 @@ public class MapPutAllTester<K, V> extends AbstractMapTester<K, V> {
}
getMap().putAll(map);
}
-
- /**
- * Returns the {@link Method} instance for {@link
- * #testPutAll_nullKeyUnsupported()} so that tests can suppress it with {@code
- * FeatureSpecificTestSuiteBuilder.suppressing()} until <a
- * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147">Sun
- * bug 5045147</a> is fixed.
- */
- @GwtIncompatible("reflection")
- public static Method getPutAllNullKeyUnsupportedMethod() {
- return Helpers.getMethod(MapPutAllTester.class, "testPutAll_nullKeyUnsupported");
- }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapPutTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapPutTester.java
index 7c242d5..69b57ca 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapPutTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapPutTester.java
@@ -19,19 +19,12 @@ 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.annotations.GwtIncompatible;
import com.google.common.collect.testing.AbstractMapTester;
-import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
-import java.lang.reflect.Method;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
@@ -46,7 +39,6 @@ import java.util.Map.Entry;
* @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;
@@ -67,45 +59,6 @@ public class MapPutTester<K, V> extends AbstractMapTester<K, V> {
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 {
@@ -240,17 +193,4 @@ public class MapPutTester<K, V> extends AbstractMapTester<K, V> {
private V put(Map.Entry<K, V> entry) {
return getMap().put(entry.getKey(), entry.getValue());
}
-
- /**
- * Returns the {@link Method} instance for {@link
- * #testPut_nullKeyUnsupported()} so that tests of {@link java.util.TreeMap}
- * can suppress it with {@code FeatureSpecificTestSuiteBuilder.suppressing()}
- * until <a
- * href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147">Sun bug
- * 5045147</a> is fixed.
- */
- @GwtIncompatible("reflection")
- public static Method getPutNullKeyUnsupportedMethod() {
- return Helpers.getMethod(MapPutTester.class, "testPut_nullKeyUnsupported");
- }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapRemoveTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapRemoveTester.java
index 4a7a5b4..6ba33ce 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapRemoveTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapRemoveTester.java
@@ -16,23 +16,16 @@
package com.google.common.collect.testing.testers;
-import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
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_QUERIES;
-import static com.google.common.collect.testing.features.MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractMapTester;
import com.google.common.collect.testing.WrongType;
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.Entry;
-
/**
* A generic JUnit test which tests {@code remove} operations on a map. Can't be
* invoked directly; please see
@@ -44,7 +37,6 @@ import java.util.Map.Entry;
* @author Chris Povirk
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class MapRemoveTester<K, V> extends AbstractMapTester<K, V> {
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
@@ -57,48 +49,6 @@ public class MapRemoveTester<K, V> extends AbstractMapTester<K, V> {
expectMissing(samples.e0);
}
- @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- SUPPORTS_REMOVE})
- @CollectionSize.Require(SEVERAL)
- public void testRemovePresentConcurrentWithEntrySetIteration() {
- try {
- Iterator<Entry<K, V>> iterator = getMap().entrySet().iterator();
- getMap().remove(samples.e0.getKey());
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
- @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- SUPPORTS_REMOVE})
- @CollectionSize.Require(SEVERAL)
- public void testRemovePresentConcurrentWithKeySetIteration() {
- try {
- Iterator<K> iterator = getMap().keySet().iterator();
- getMap().remove(samples.e0.getKey());
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
- @MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION,
- SUPPORTS_REMOVE})
- @CollectionSize.Require(SEVERAL)
- public void testRemovePresentConcurrentWithValuesIteration() {
- try {
- Iterator<V> iterator = getMap().values().iterator();
- getMap().remove(samples.e0.getKey());
- iterator.next();
- fail("Expected ConcurrentModificationException");
- } catch (ConcurrentModificationException expected) {
- // success
- }
- }
-
@MapFeature.Require(SUPPORTS_REMOVE)
public void testRemove_notPresent() {
assertNull("remove(notPresent) should return null",
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapSerializationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapSerializationTester.java
deleted file mode 100644
index 3d5c675..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapSerializationTester.java
+++ /dev/null
@@ -1,37 +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.testers;
-
-import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE;
-
-import com.google.common.annotations.GwtCompatible;
-import com.google.common.collect.testing.AbstractMapTester;
-import com.google.common.collect.testing.features.CollectionFeature;
-import com.google.common.testing.SerializableTester;
-
-/**
- * Basic serialization test for maps.
- *
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class MapSerializationTester<K, V> extends AbstractMapTester<K, V> {
- @CollectionFeature.Require(SERIALIZABLE)
- public void testReserializeMap() {
- SerializableTester.reserializeAndAssert(getMap());
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/MapSizeTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/MapSizeTester.java
index f3df9f0..6b3439a 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/MapSizeTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/MapSizeTester.java
@@ -16,7 +16,6 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.AbstractMapTester;
/**
@@ -28,9 +27,8 @@ import com.google.common.collect.testing.AbstractMapTester;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class MapSizeTester<K, V> extends AbstractMapTester<K, V> {
public void testSize() {
assertEquals("size():", getNumElements(), getMap().size());
}
-}
+} \ No newline at end of file
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/Platform.java b/guava-testlib/src/com/google/common/collect/testing/testers/Platform.java
index cd3eb84..ba4d3f0 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/Platform.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/Platform.java
@@ -16,17 +16,28 @@
package com.google.common.collect.testing.testers;
-import com.google.common.annotations.GwtCompatible;
+import java.lang.reflect.Method;
/**
* This class is emulated in GWT.
*
* @author Hayward Chan
*/
-@GwtCompatible
class Platform {
/**
+ * Delegate to {@link Class#getMethod(String, Class[])}. Not
+ * usable in GWT.
+ */
+ static Method getMethod(Class<?> clazz, String methodName) {
+ try {
+ return clazz.getMethod(methodName);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
* Format the template with args, only supports the placeholder
* {@code %s}.
*/
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/QueueElementTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/QueueElementTester.java
index 26570ed..7c5ce41 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/QueueElementTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/QueueElementTester.java
@@ -21,7 +21,6 @@ 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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -36,7 +35,6 @@ import java.util.NoSuchElementException;
*
* @author Jared Levy
*/
-@GwtCompatible
public class QueueElementTester<E> extends AbstractQueueTester<E> {
@CollectionSize.Require(ZERO)
public void testElement_empty() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/QueueOfferTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/QueueOfferTester.java
index d9a67ea..f4fa792 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/QueueOfferTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/QueueOfferTester.java
@@ -19,7 +19,6 @@ 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 com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.features.CollectionFeature;
/**
@@ -32,7 +31,6 @@ import com.google.common.collect.testing.features.CollectionFeature;
* @author Jared Levy
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class QueueOfferTester<E> extends AbstractQueueTester<E> {
@CollectionFeature.Require(SUPPORTS_ADD)
public void testOffer_supportedNotPresent() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/QueuePeekTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/QueuePeekTester.java
index c9c045e..341e68d 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/QueuePeekTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/QueuePeekTester.java
@@ -21,7 +21,6 @@ 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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -34,7 +33,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author Jared Levy
*/
-@GwtCompatible
public class QueuePeekTester<E> extends AbstractQueueTester<E> {
@CollectionSize.Require(ZERO)
public void testPeek_empty() {
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/QueuePollTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/QueuePollTester.java
index 14c2803..a447bb0 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/QueuePollTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/QueuePollTester.java
@@ -22,7 +22,6 @@ 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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -36,7 +35,6 @@ import com.google.common.collect.testing.features.CollectionSize;
* @author Jared Levy
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class QueuePollTester<E> extends AbstractQueueTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(ZERO)
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/QueueRemoveTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/QueueRemoveTester.java
index 718f63b..07596f4 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/QueueRemoveTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/QueueRemoveTester.java
@@ -22,7 +22,6 @@ 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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -38,7 +37,6 @@ import java.util.NoSuchElementException;
* @author Jared Levy
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class QueueRemoveTester<E> extends AbstractQueueTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(ZERO)
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/SetAddAllTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SetAddAllTester.java
index 638d6ef..0dac713 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/SetAddAllTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/SetAddAllTester.java
@@ -16,10 +16,9 @@
package com.google.common.collect.testing.testers;
-import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD;
+import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD_ALL;
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
-import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.MinimalCollection;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -34,9 +33,8 @@ import com.google.common.collect.testing.features.CollectionSize;
* @author Kevin Bourrillion
*/
@SuppressWarnings("unchecked") // too many "unchecked generic array creations"
-@GwtCompatible
public class SetAddAllTester<E> extends AbstractSetTester<E> {
- @CollectionFeature.Require(SUPPORTS_ADD)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_supportedSomePresent() {
assertTrue("add(somePresent) should return true",
@@ -44,7 +42,7 @@ public class SetAddAllTester<E> extends AbstractSetTester<E> {
expectAdded(samples.e3);
}
- @CollectionFeature.Require(SUPPORTS_ADD)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
public void testAddAll_withDuplicates() {
MinimalCollection<E> elementsToAdd
= MinimalCollection.of(samples.e3, samples.e4, samples.e3, samples.e4);
@@ -53,7 +51,7 @@ public class SetAddAllTester<E> extends AbstractSetTester<E> {
expectAdded(samples.e3, samples.e4);
}
- @CollectionFeature.Require(SUPPORTS_ADD)
+ @CollectionFeature.Require(SUPPORTS_ADD_ALL)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_supportedAllPresent() {
assertFalse("add(allPresent) should return false",
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/SetAddTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SetAddTester.java
index 216411e..d9d8601 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/SetAddTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/SetAddTester.java
@@ -20,9 +20,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.ALLOW
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.annotations.GwtIncompatible;
-import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -37,7 +34,6 @@ import java.lang.reflect.Method;
*
* @author Kevin Bourrillion
*/
-@GwtCompatible(emulated = true)
public class SetAddTester<E> extends AbstractSetTester<E> {
@CollectionFeature.Require(SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
@@ -60,8 +56,7 @@ public class SetAddTester<E> extends AbstractSetTester<E> {
* {@link #testAdd_supportedNullPresent()} so that tests can suppress it. See
* {@link CollectionAddTester#getAddNullSupportedMethod()} for details.
*/
- @GwtIncompatible("reflection")
public static Method getAddSupportedNullPresentMethod() {
- return Helpers.getMethod(SetAddTester.class, "testAdd_supportedNullPresent");
+ return Platform.getMethod(SetAddTester.class, "testAdd_supportedNullPresent");
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/SetCreationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SetCreationTester.java
index f81314d..50d83c7 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/SetCreationTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/SetCreationTester.java
@@ -21,7 +21,6 @@ import static com.google.common.collect.testing.features.CollectionFeature.REJEC
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.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -37,7 +36,6 @@ import java.util.List;
*
* @author Chris Povirk
*/
-@GwtCompatible
public class SetCreationTester<E> extends AbstractSetTester<E> {
@CollectionFeature.Require(value = ALLOWS_NULL_VALUES,
absent = REJECTS_DUPLICATES_AT_CREATION)
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/SetEqualsTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SetEqualsTester.java
index 9989d2d..a783a44 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/SetEqualsTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/SetEqualsTester.java
@@ -18,7 +18,6 @@ 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.Helpers;
import com.google.common.collect.testing.MinimalSet;
import com.google.common.collect.testing.features.CollectionFeature;
@@ -34,7 +33,6 @@ import java.util.Set;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class SetEqualsTester<E> extends AbstractSetTester<E> {
public void testEquals_otherSetWithSameElements() {
assertTrue(
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/SetHashCodeTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SetHashCodeTester.java
index 09c6f5d..e8fc705 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/SetHashCodeTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/SetHashCodeTester.java
@@ -18,9 +18,6 @@ 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.annotations.GwtIncompatible;
-import com.google.common.collect.testing.Helpers;
import com.google.common.collect.testing.features.CollectionFeature;
import com.google.common.collect.testing.features.CollectionSize;
@@ -34,7 +31,6 @@ import java.util.Collection;
*
* @author George van den Driessche
*/
-@GwtCompatible(emulated = true)
public class SetHashCodeTester<E> extends AbstractSetTester<E> {
public void testHashCode() {
int expectedHashCode = 0;
@@ -69,10 +65,9 @@ public class SetHashCodeTester<E> extends AbstractSetTester<E> {
* unhashable objects can suppress it with
* {@code FeatureSpecificTestSuiteBuilder.suppressing()}.
*/
- @GwtIncompatible("reflection")
public static Method[] getHashCodeMethods() {
return new Method[]{
- Helpers.getMethod(SetHashCodeTester.class, "testHashCode"),
- Helpers.getMethod(SetHashCodeTester.class, "testHashCode_containingNull") };
+ Platform.getMethod(SetHashCodeTester.class, "testHashCode"),
+ Platform.getMethod(SetHashCodeTester.class, "testHashCode_containingNull") };
}
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/NavigableSetNavigationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SetNavigationTester.java
index 14c6a47..a35595a 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/NavigableSetNavigationTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/SetNavigationTester.java
@@ -25,22 +25,21 @@ 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.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableSet;
-import java.util.TreeSet;
+import java.util.NoSuchElementException;
/**
* A generic JUnit test which tests operations on a NavigableSet. Can't be
- * invoked directly; please see {@code NavigableSetTestSuiteBuilder}.
+ * invoked directly; please see {@code SetTestSuiteBuilder}.
*
* @author Jesse Wilson
* @author Louis Wasserman
*/
-public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
+public class SetNavigationTester<E> extends AbstractSetTester<E> {
private NavigableSet<E> navigableSet;
private List<E> values;
@@ -64,7 +63,7 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
}
}
}
-
+
/**
* Resets the contents of navigableSet to have elements a, c, for the
* navigation tests.
@@ -74,6 +73,15 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
navigableSet = (NavigableSet<E>) getSet();
}
+ @CollectionSize.Require(ZERO)
+ public void testEmptySetFirst() {
+ try {
+ navigableSet.first();
+ fail();
+ } catch (NoSuchElementException e) {
+ }
+ }
+
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(ZERO)
public void testEmptySetPollFirst() {
@@ -88,12 +96,26 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
assertNull(navigableSet.higher(samples.e0));
}
+ @CollectionSize.Require(ZERO)
+ public void testEmptySetLast() {
+ try {
+ navigableSet.last();
+ fail();
+ } catch (NoSuchElementException e) {
+ }
+ }
+
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(ZERO)
public void testEmptySetPollLast() {
assertNull(navigableSet.pollLast());
}
+ @CollectionSize.Require(ONE)
+ public void testSingletonSetFirst() {
+ assertEquals(a, navigableSet.first());
+ }
+
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(ONE)
public void testSingletonSetPollFirst() {
@@ -109,6 +131,11 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
assertNull(navigableSet.higher(samples.e0));
}
+ @CollectionSize.Require(ONE)
+ public void testSingletonSetLast() {
+ assertEquals(a, navigableSet.last());
+ }
+
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(ONE)
public void testSingletonSetPollLast() {
@@ -116,6 +143,11 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
assertTrue(navigableSet.isEmpty());
}
+ @CollectionSize.Require(SEVERAL)
+ public void testFirst() {
+ assertEquals(a, navigableSet.first());
+ }
+
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(SEVERAL)
public void testPollFirst() {
@@ -134,15 +166,14 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
}
@CollectionSize.Require(SEVERAL)
- public void testLowerHole() {
+ public void testLower() {
resetWithHole();
assertEquals(null, navigableSet.lower(a));
assertEquals(a, navigableSet.lower(b));
assertEquals(a, navigableSet.lower(c));
}
-
@CollectionSize.Require(SEVERAL)
- public void testFloorHole() {
+ public void testFloor() {
resetWithHole();
assertEquals(a, navigableSet.floor(a));
assertEquals(a, navigableSet.floor(b));
@@ -150,7 +181,7 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
}
@CollectionSize.Require(SEVERAL)
- public void testCeilingHole() {
+ public void testCeiling() {
resetWithHole();
assertEquals(a, navigableSet.ceiling(a));
assertEquals(c, navigableSet.ceiling(b));
@@ -158,44 +189,16 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
}
@CollectionSize.Require(SEVERAL)
- public void testHigherHole() {
+ public void testHigher() {
resetWithHole();
assertEquals(c, navigableSet.higher(a));
assertEquals(c, navigableSet.higher(b));
assertEquals(null, navigableSet.higher(c));
}
- /*
- * TODO(cpovirk): make "too small" and "too large" elements available for better navigation
- * testing. At that point, we may be able to eliminate the "hole" tests, which would mean that
- * ContiguousSet's tests would no longer need to suppress them.
- */
- @CollectionSize.Require(SEVERAL)
- public void testLower() {
- assertEquals(null, navigableSet.lower(a));
- assertEquals(a, navigableSet.lower(b));
- assertEquals(b, navigableSet.lower(c));
- }
-
@CollectionSize.Require(SEVERAL)
- public void testFloor() {
- assertEquals(a, navigableSet.floor(a));
- assertEquals(b, navigableSet.floor(b));
- assertEquals(c, navigableSet.floor(c));
- }
-
- @CollectionSize.Require(SEVERAL)
- public void testCeiling() {
- assertEquals(a, navigableSet.ceiling(a));
- assertEquals(b, navigableSet.ceiling(b));
- assertEquals(c, navigableSet.ceiling(c));
- }
-
- @CollectionSize.Require(SEVERAL)
- public void testHigher() {
- assertEquals(b, navigableSet.higher(a));
- assertEquals(c, navigableSet.higher(b));
- assertEquals(null, navigableSet.higher(c));
+ public void testLast() {
+ assertEquals(c, navigableSet.last());
}
@CollectionFeature.Require(SUPPORTS_REMOVE)
@@ -224,34 +227,4 @@ public class NavigableSetNavigationTester<E> extends AbstractSetTester<E> {
Collections.reverse(descending);
assertEquals(values, descending);
}
-
- public void testEmptySubSet() {
- NavigableSet<E> empty = navigableSet.subSet(samples.e0, false, samples.e0, false);
- assertEquals(new TreeSet<E>(), empty);
- }
-
- /*
- * TODO(cpovirk): more testing of subSet/headSet/tailSet/descendingSet? and/or generate derived
- * suites?
- */
-
- /**
- * Returns the {@link Method} instances for the test methods in this class that create a set with
- * a "hole" in it so that set tests of {@code ContiguousSet} can suppress them with {@code
- * FeatureSpecificTestSuiteBuilder.suppressing()}.
- */
- /*
- * TODO(cpovirk): or we could make HOLES_FORBIDDEN a feature. Or we could declare that
- * implementations are permitted to throw IAE if a hole is requested, and we could update
- * test*Hole to permit IAE. (But might this ignore genuine bugs?) But see the TODO above
- * testLower, which could make this all unnecessary
- */
- public static Method[] getHoleMethods() {
- return new Method[] {
- Helpers.getMethod(NavigableSetNavigationTester.class, "testLowerHole"),
- Helpers.getMethod(NavigableSetNavigationTester.class, "testFloorHole"),
- Helpers.getMethod(NavigableSetNavigationTester.class, "testCeilingHole"),
- Helpers.getMethod(NavigableSetNavigationTester.class, "testHigherHole"),
- };
- }
}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/SetRemoveTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SetRemoveTester.java
index ffc5044..1310cff 100644
--- a/guava-testlib/src/com/google/common/collect/testing/testers/SetRemoveTester.java
+++ b/guava-testlib/src/com/google/common/collect/testing/testers/SetRemoveTester.java
@@ -19,7 +19,6 @@ package com.google.common.collect.testing.testers;
import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;
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;
@@ -32,7 +31,6 @@ import com.google.common.collect.testing.features.CollectionSize;
*
* @author George van den Driessche
*/
-@GwtCompatible
public class SetRemoveTester<E> extends AbstractSetTester<E> {
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/SortedMapNavigationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SortedMapNavigationTester.java
deleted file mode 100644
index 9552a41..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/testers/SortedMapNavigationTester.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2010 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing.testers;
-
-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.testing.AbstractMapTester;
-import com.google.common.collect.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.NoSuchElementException;
-import java.util.SortedMap;
-
-/**
- * A generic JUnit test which tests operations on a SortedMap. Can't be
- * invoked directly; please see {@code SortedMapTestSuiteBuilder}.
- *
- * @author Jesse Wilson
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class SortedMapNavigationTester<K, V> extends AbstractMapTester<K, V> {
-
- private SortedMap<K, V> navigableMap;
- private Entry<K, V> a;
- private Entry<K, V> c;
-
- @Override public void setUp() throws Exception {
- super.setUp();
- navigableMap = (SortedMap<K, V>) getMap();
- List<Entry<K, V>> entries = Helpers.copyToList(getSubjectGenerator().getSampleElements(
- getSubjectGenerator().getCollectionSize().getNumElements()));
- Collections.sort(entries, Helpers.<K, V>entryComparator(navigableMap.comparator()));
-
- // some tests assume SEVERAL == 3
- if (entries.size() >= 1) {
- a = entries.get(0);
- if (entries.size() >= 3) {
- c = entries.get(2);
- }
- }
- }
-
- @CollectionSize.Require(ZERO)
- public void testEmptyMapFirst() {
- try {
- navigableMap.firstKey();
- fail();
- } catch (NoSuchElementException e) {
- }
- }
-
- @CollectionSize.Require(ZERO)
- public void testEmptyMapLast() {
- try {
- assertNull(navigableMap.lastKey());
- fail();
- } catch (NoSuchElementException e) {
- }
- }
-
- @CollectionSize.Require(ONE)
- public void testSingletonMapFirst() {
- assertEquals(a.getKey(), navigableMap.firstKey());
- }
-
- @CollectionSize.Require(ONE)
- public void testSingletonMapLast() {
- assertEquals(a.getKey(), navigableMap.lastKey());
- }
-
- @CollectionSize.Require(SEVERAL)
- public void testFirst() {
- assertEquals(a.getKey(), navigableMap.firstKey());
- }
-
- @CollectionSize.Require(SEVERAL)
- public void testLast() {
- assertEquals(c.getKey(), navigableMap.lastKey());
- }
-}
diff --git a/guava-testlib/src/com/google/common/collect/testing/testers/SortedSetNavigationTester.java b/guava-testlib/src/com/google/common/collect/testing/testers/SortedSetNavigationTester.java
deleted file mode 100644
index b3a52d2..0000000
--- a/guava-testlib/src/com/google/common/collect/testing/testers/SortedSetNavigationTester.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2010 The Guava Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.common.collect.testing.testers;
-
-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.testing.Helpers;
-import com.google.common.collect.testing.features.CollectionSize;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.SortedSet;
-
-/**
- * A generic JUnit test which tests operations on a SortedSet. Can't be
- * invoked directly; please see {@code SortedSetTestSuiteBuilder}.
- *
- * @author Jesse Wilson
- * @author Louis Wasserman
- */
-@GwtCompatible
-public class SortedSetNavigationTester<E> extends AbstractSetTester<E> {
-
- private SortedSet<E> sortedSet;
- private List<E> values;
- private E a;
- private E b;
- private E c;
-
- @Override public void setUp() throws Exception {
- super.setUp();
- sortedSet = (SortedSet<E>) getSet();
- values = Helpers.copyToList(getSubjectGenerator().getSampleElements(
- getSubjectGenerator().getCollectionSize().getNumElements()));
- Collections.sort(values, sortedSet.comparator());
-
- // some tests assume SEVERAL == 3
- if (values.size() >= 1) {
- a = values.get(0);
- if (values.size() >= 3) {
- b = values.get(1);
- c = values.get(2);
- }
- }
- }
-
- @CollectionSize.Require(ZERO)
- public void testEmptySetFirst() {
- try {
- sortedSet.first();
- fail();
- } catch (NoSuchElementException e) {
- }
- }
-
- @CollectionSize.Require(ZERO)
- public void testEmptySetLast() {
- try {
- sortedSet.last();
- fail();
- } catch (NoSuchElementException e) {
- }
- }
-
- @CollectionSize.Require(ONE)
- public void testSingletonSetFirst() {
- assertEquals(a, sortedSet.first());
- }
-
- @CollectionSize.Require(ONE)
- public void testSingletonSetLast() {
- assertEquals(a, sortedSet.last());
- }
-
- @CollectionSize.Require(SEVERAL)
- public void testFirst() {
- assertEquals(a, sortedSet.first());
- }
-
- @CollectionSize.Require(SEVERAL)
- public void testLast() {
- assertEquals(c, sortedSet.last());
- }
-}
diff --git a/guava-testlib/src/com/google/common/testing/AbstractPackageSanityTests.java b/guava-testlib/src/com/google/common/testing/AbstractPackageSanityTests.java
deleted file mode 100644
index 3e13fa0..0000000
--- a/guava-testlib/src/com/google/common/testing/AbstractPackageSanityTests.java
+++ /dev/null
@@ -1,380 +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.testing;
-
-import static com.google.common.base.Predicates.and;
-import static com.google.common.base.Predicates.not;
-import static com.google.common.testing.AbstractPackageSanityTests.Chopper.suffix;
-
-import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
-import com.google.common.reflect.ClassPath;
-import com.google.common.testing.NullPointerTester.Visibility;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
-import org.junit.Test;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.TreeMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Automatically runs sanity checks against top level classes in the same package of the test that
- * extends {@code AbstractPackageSanityTests}. Currently sanity checks include {@link
- * NullPointerTester}, {@link EqualsTester} and {@link SerializableTester}. For example: <pre>
- * public class PackageSanityTests extends AbstractPackageSanityTests {}
- * </pre>
- *
- * <p>Note that only top-level classes with either a non-private constructor or a non-private static
- * factory method to construct instances can have their instance methods checked. For example: <pre>
- * public class Address {
- * private final String city;
- * private final String state;
- * private final String zipcode;
- *
- * public Address(String city, String state, String zipcode) {...}
- *
- * {@literal @Override} public boolean equals(Object obj) {...}
- * {@literal @Override} public int hashCode() {...}
- * ...
- * }
- * </pre>
- * No cascading checks are performed against the return values of methods unless the method is a
- * static factory method. Neither are semantics of mutation methods such as {@code
- * someList.add(obj)} checked. For more detailed discussion of supported and unsupported cases, see
- * {@link #testEquals}, {@link #testNulls} and {@link #testSerializable}.
- *
- * <p>For testing against the returned instances from a static factory class, such as <pre>
- * interface Book {...}
- * public class Books {
- * public static Book hardcover(String title) {...}
- * public static Book paperback(String title) {...}
- * }
- * </pre>
- * please use {@link ClassSanityTester#forAllPublicStaticMethods}.
- *
- * <p>This class incurs IO because it scans the classpath and reads classpath resources.
- *
- * @author Ben Yu
- * @since 14.0
- */
-@Beta
-// TODO: Switch to JUnit 4 and use @Parameterized and @BeforeClass
-public abstract class AbstractPackageSanityTests extends TestCase {
-
- /* The names of the expected method that tests null checks. */
- private static final ImmutableList<String> NULL_TEST_METHOD_NAMES = ImmutableList.of(
- "testNulls", "testNull",
- "testNullPointers", "testNullPointer",
- "testNullPointerExceptions", "testNullPointerException");
-
- /* The names of the expected method that tests serializable. */
- private static final ImmutableList<String> SERIALIZABLE_TEST_METHOD_NAMES = ImmutableList.of(
- "testSerializable", "testSerialization",
- "testEqualsAndSerializable", "testEqualsAndSerialization");
-
- /* The names of the expected method that tests equals. */
- private static final ImmutableList<String> EQUALS_TEST_METHOD_NAMES = ImmutableList.of(
- "testEquals", "testEqualsAndHashCode",
- "testEqualsAndSerializable", "testEqualsAndSerialization",
- "testEquality");
-
- private static final Chopper TEST_SUFFIX =
- suffix("Test")
- .or(suffix("Tests"))
- .or(suffix("TestCase"))
- .or(suffix("TestSuite"));
-
- private final Logger logger = Logger.getLogger(getClass().getName());
- private final ClassSanityTester tester = new ClassSanityTester();
- private Visibility visibility = Visibility.PACKAGE;
- private Predicate<Class<?>> classFilter = new Predicate<Class<?>>() {
- @Override public boolean apply(Class<?> cls) {
- return visibility.isVisible(cls.getModifiers());
- }
- };
-
- /**
- * Restricts the sanity tests for public API only. By default, package-private API are also
- * covered.
- */
- protected final void publicApiOnly() {
- visibility = Visibility.PUBLIC;
- }
-
- /**
- * Tests all top-level public {@link Serializable} classes in the package. For a serializable
- * Class {@code C}:
- * <ul>
- * <li>If {@code C} explicitly implements {@link Object#equals}, the deserialized instance will be
- * checked to be equal to the instance before serialization.
- * <li>If {@code C} doesn't explicitly implement {@code equals} but instead inherits it from a
- * superclass, no equality check is done on the deserialized instance because it's not clear
- * whether the author intended for the class to be a value type.
- * <li>If a constructor or factory method takes a parameter whose type is interface, a dynamic
- * proxy will be passed to the method. It's possible that the method body expects an instance
- * method of the passed-in proxy to be of a certain value yet the proxy isn't aware of the
- * assumption, in which case the equality check before and after serialization will fail.
- * <li>If the constructor or factory method takes a parameter that {@link
- * AbstractPackageSanityTests} doesn't know how to construct, the test will fail.
- * <li>If there is no public constructor or public static factory method declared by {@code C},
- * {@code C} is skipped for serialization test, even if it implements {@link Serializable}.
- * <li>Serialization test is not performed on method return values unless the method is a public
- * static factory method whose return type is {@code C} or {@code C}'s subtype.
- * </ul>
- *
- * In all cases, if {@code C} needs custom logic for testing serialization, you can add an
- * explicit {@code testSerializable()} test in the corresponding {@code CTest} class, and {@code
- * C} will be excluded from automated serialization test performed by this method.
- */
- @Test
- public void testSerializable() throws Exception {
- // TODO: when we use @BeforeClass, we can pay the cost of class path scanning only once.
- for (Class<?> classToTest
- : findClassesToTest(loadClassesInPackage(), SERIALIZABLE_TEST_METHOD_NAMES)) {
- if (Serializable.class.isAssignableFrom(classToTest)) {
- try {
- Object instance = tester.instantiate(classToTest);
- if (instance != null) {
- if (isEqualsDefined(classToTest)) {
- SerializableTester.reserializeAndAssert(instance);
- } else {
- SerializableTester.reserialize(instance);
- }
- }
- } catch (Throwable e) {
- throw sanityError(classToTest, SERIALIZABLE_TEST_METHOD_NAMES, "serializable test", e);
- }
- }
- }
- }
-
- /**
- * Performs {@link NullPointerTester} checks for all top-level public classes in the package. For
- * a class {@code C}
- * <ul>
- * <li>All public static methods are checked such that passing null for any parameter that's not
- * annotated with {@link javax.annotation.Nullable} should throw {@link NullPointerException}.
- * <li>If there is any public constructor or public static factory method declared by the class,
- * all public instance methods will be checked too using the instance created by invoking the
- * constructor or static factory method.
- * <li>If the constructor or factory method used to construct instance takes a parameter that
- * {@link AbstractPackageSanityTests} doesn't know how to construct, the test will fail.
- * <li>If there is no public constructor or public static factory method declared by {@code C},
- * instance methods are skipped for nulls test.
- * <li>Nulls test is not performed on method return values unless the method is a public static
- * factory method whose return type is {@code C} or {@code C}'s subtype.
- * </ul>
- *
- * In all cases, if {@code C} needs custom logic for testing nulls, you can add an explicit {@code
- * testNulls()} test in the corresponding {@code CTest} class, and {@code C} will be excluded from
- * the automated null tests performed by this method.
- */
- @Test
- public void testNulls() throws Exception {
- for (Class<?> classToTest
- : findClassesToTest(loadClassesInPackage(), NULL_TEST_METHOD_NAMES)) {
- try {
- tester.doTestNulls(classToTest, visibility);
- } catch (Throwable e) {
- throw sanityError(classToTest, NULL_TEST_METHOD_NAMES, "nulls test", e);
- }
- }
- }
-
- /**
- * Tests {@code equals()} and {@code hashCode()} implementations for every top-level public class
- * in the package, that explicitly implements {@link Object#equals}. For a class {@code C}:
- * <ul>
- * <li>The public constructor or public static factory method with the most parameters is used to
- * construct the sample instances. In case of tie, the candidate constructors or factories are
- * tried one after another until one can be used to construct sample instances.
- * <li>For the constructor or static factory method used to construct instances, it's checked that
- * when equal parameters are passed, the result instance should also be equal; and vice versa.
- * <li>Inequality check is not performed against state mutation methods such as {@link List#add},
- * or functional update methods such as {@link com.google.common.base.Joiner#skipNulls}.
- * <li>If the constructor or factory method used to construct instance takes a parameter that
- * {@link AbstractPackageSanityTests} doesn't know how to construct, the test will fail.
- * <li>If there is no public constructor or public static factory method declared by {@code C},
- * {@code C} is skipped for equality test.
- * <li>Equality test is not performed on method return values unless the method is a public static
- * factory method whose return type is {@code C} or {@code C}'s subtype.
- * </ul>
- *
- * In all cases, if {@code C} needs custom logic for testing {@code equals()}, you can add an
- * explicit {@code testEquals()} test in the corresponding {@code CTest} class, and {@code C} will
- * be excluded from the automated {@code equals} test performed by this method.
- */
- @Test
- public void testEquals() throws Exception {
- for (Class<?> classToTest
- : findClassesToTest(loadClassesInPackage(), EQUALS_TEST_METHOD_NAMES)) {
- if (!classToTest.isEnum() && isEqualsDefined(classToTest)) {
- try {
- tester.doTestEquals(classToTest);
- } catch (Throwable e) {
- throw sanityError(classToTest, EQUALS_TEST_METHOD_NAMES, "equals test", e);
- }
- }
- }
- }
-
- /**
- * Sets the default value for {@code type}, when dummy value for a parameter of the same type
- * needs to be created in order to invoke a method or constructor. The default value isn't used in
- * testing {@link Object#equals} because more than one sample instances are needed for testing
- * inequality.
- */
- protected final <T> void setDefault(Class<T> type, T value) {
- tester.setDefault(type, value);
- }
-
- /** Specifies that classes that satisfy the given predicate aren't tested for sanity. */
- protected final void ignoreClasses(Predicate<? super Class<?>> condition) {
- this.classFilter = and(this.classFilter, not(condition));
- }
-
- private static AssertionFailedError sanityError(
- Class<?> cls, List<String> explicitTestNames, String description, Throwable e) {
- String message = String.format(
- "Error in automated %s of %s\n"
- + "If the class is better tested explicitly, you can add %s() to %sTest",
- description, cls, explicitTestNames.get(0), cls.getName());
- AssertionFailedError error = new AssertionFailedError(message);
- error.initCause(e);
- return error;
- }
-
- /**
- * Finds the classes not ending with a test suffix and not covered by an explicit test
- * whose name is {@code explicitTestName}.
- */
- @VisibleForTesting List<Class<?>> findClassesToTest(
- Iterable<? extends Class<?>> classes, Iterable<String> explicitTestNames) {
- // "a.b.Foo" -> a.b.Foo.class
- TreeMap<String, Class<?>> classMap = Maps.newTreeMap();
- for (Class<?> cls : classes) {
- classMap.put(cls.getName(), cls);
- }
- // Foo.class -> [FooTest.class, FooTests.class, FooTestSuite.class, ...]
- Multimap<Class<?>, Class<?>> testClasses = HashMultimap.create();
- LinkedHashSet<Class<?>> candidateClasses = Sets.newLinkedHashSet();
- for (Class<?> cls : classes) {
- Optional<String> testedClassName = TEST_SUFFIX.chop(cls.getName());
- if (testedClassName.isPresent()) {
- Class<?> testedClass = classMap.get(testedClassName.get());
- if (testedClass != null) {
- testClasses.put(testedClass, cls);
- }
- } else {
- candidateClasses.add(cls);
- }
- }
- List<Class<?>> result = Lists.newArrayList();
- NEXT_CANDIDATE: for (Class<?> candidate : Iterables.filter(candidateClasses, classFilter)) {
- for (Class<?> testClass : testClasses.get(candidate)) {
- if (hasTest(testClass, explicitTestNames)) {
- // covered by explicit test
- continue NEXT_CANDIDATE;
- }
- }
- result.add(candidate);
- }
- return result;
- }
-
- private List<Class<?>> loadClassesInPackage() throws IOException {
- List<Class<?>> classes = Lists.newArrayList();
- String packageName = getClass().getPackage().getName();
- for (ClassPath.ClassInfo classInfo
- : ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(packageName)) {
- Class<?> cls;
- try {
- cls = classInfo.load();
- } catch (NoClassDefFoundError e) {
- // In case there were linking problems, this is probably not a class we care to test anyway.
- logger.log(Level.SEVERE, "Cannot load class " + classInfo + ", skipping...", e);
- continue;
- }
- if (!cls.isInterface()) {
- classes.add(cls);
- }
- }
- return classes;
- }
-
- private static boolean hasTest(Class<?> testClass, Iterable<String> testNames) {
- for (String testName : testNames) {
- try {
- testClass.getMethod(testName);
- return true;
- } catch (NoSuchMethodException e) {
- continue;
- }
- }
- return false;
- }
-
- private static boolean isEqualsDefined(Class<?> cls) {
- try {
- return !cls.getDeclaredMethod("equals", Object.class).isSynthetic();
- } catch (NoSuchMethodException e) {
- return false;
- }
- }
-
- static abstract class Chopper {
-
- final Chopper or(final Chopper you) {
- final Chopper i = this;
- return new Chopper() {
- @Override Optional<String> chop(String str) {
- return i.chop(str).or(you.chop(str));
- }
- };
- }
-
- abstract Optional<String> chop(String str);
-
- static Chopper suffix(final String suffix) {
- return new Chopper() {
- @Override Optional<String> chop(String str) {
- if (str.endsWith(suffix)) {
- return Optional.of(str.substring(0, str.length() - suffix.length()));
- } else {
- return Optional.absent();
- }
- }
- };
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java b/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java
deleted file mode 100644
index 4ebcc9a..0000000
--- a/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java
+++ /dev/null
@@ -1,440 +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.testing;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.CharMatcher;
-import com.google.common.base.Charsets;
-import com.google.common.base.Defaults;
-import com.google.common.base.Equivalence;
-import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.base.Splitter;
-import com.google.common.base.Ticker;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.ClassToInstanceMap;
-import com.google.common.collect.Constraint;
-import com.google.common.collect.Constraints;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableClassToInstanceMap;
-import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.ImmutableMultiset;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.ImmutableSortedMap;
-import com.google.common.collect.ImmutableSortedMultiset;
-import com.google.common.collect.ImmutableSortedSet;
-import com.google.common.collect.ImmutableTable;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.MapConstraint;
-import com.google.common.collect.MapConstraints;
-import com.google.common.collect.MapDifference;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.Multiset;
-import com.google.common.collect.Ordering;
-import com.google.common.collect.PeekingIterator;
-import com.google.common.collect.Range;
-import com.google.common.collect.RowSortedTable;
-import com.google.common.collect.SetMultimap;
-import com.google.common.collect.Sets;
-import com.google.common.collect.SortedMapDifference;
-import com.google.common.collect.SortedMultiset;
-import com.google.common.collect.SortedSetMultimap;
-import com.google.common.collect.Table;
-import com.google.common.collect.Tables;
-import com.google.common.collect.TreeBasedTable;
-import com.google.common.collect.TreeMultimap;
-import com.google.common.primitives.Primitives;
-import com.google.common.primitives.UnsignedInteger;
-import com.google.common.primitives.UnsignedLong;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.Serializable;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Array;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.GenericDeclaration;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.DoubleBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-import java.nio.LongBuffer;
-import java.nio.ShortBuffer;
-import java.nio.charset.Charset;
-import java.util.ArrayDeque;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Currency;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.NavigableMap;
-import java.util.NavigableSet;
-import java.util.Queue;
-import java.util.Random;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.concurrent.BlockingDeque;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ConcurrentNavigableMap;
-import java.util.concurrent.ConcurrentSkipListMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executor;
-import java.util.concurrent.LinkedBlockingDeque;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.MatchResult;
-import java.util.regex.Pattern;
-
-import javax.annotation.Nullable;
-
-/**
- * Supplies an arbitrary "default" instance for a wide range of types, often useful in testing
- * utilities.
- *
- * <p>Covers common types defined in {@code java.lang}, {@code java.lang.reflect}, {@code java.io},
- * {@code java.nio}, {@code java.math}, {@code java.util}, {@code java.util.concurrent},
- * {@code java.util.regex}, {@code com.google.common.base}, {@code com.google.common.collect}
- * and {@code com.google.common.primitives}. In addition, any public class that exposes a public
- * parameter-less constructor will be "new"d and returned.
- *
- * <p>All default instances returned by {@link #get} are generics-safe. Clients won't get type
- * errors for using {@code get(Comparator.class)} as a {@code Comparator<Foo>}, for example.
- * Immutable empty instances are returned for collection types; {@code ""} for string;
- * {@code 0} for number types; reasonable default instance for other stateless types. For mutable
- * types, a fresh instance is created each time {@code get()} is called.
- *
- * @author Kevin Bourrillion
- * @author Ben Yu
- * @since 12.0
- */
-@Beta
-public final class ArbitraryInstances {
-
- private static final ClassToInstanceMap<Object> DEFAULTS = ImmutableClassToInstanceMap.builder()
- // primitives
- .put(Object.class, "")
- .put(Number.class, 0)
- .put(UnsignedInteger.class, UnsignedInteger.ZERO)
- .put(UnsignedLong.class, UnsignedLong.ZERO)
- .put(BigInteger.class, BigInteger.ZERO)
- .put(BigDecimal.class, BigDecimal.ZERO)
- .put(CharSequence.class, "")
- .put(String.class, "")
- .put(Pattern.class, Pattern.compile(""))
- .put(MatchResult.class, Pattern.compile("").matcher("").toMatchResult())
- .put(TimeUnit.class, TimeUnit.SECONDS)
- .put(Charset.class, Charsets.UTF_8)
- .put(Currency.class, Currency.getInstance(Locale.US))
- .put(Locale.class, Locale.US)
- // common.base
- .put(CharMatcher.class, CharMatcher.NONE)
- .put(Joiner.class, Joiner.on(','))
- .put(Splitter.class, Splitter.on(','))
- .put(Optional.class, Optional.absent())
- .put(Predicate.class, Predicates.alwaysTrue())
- .put(Equivalence.class, Equivalence.equals())
- .put(Ticker.class, Ticker.systemTicker())
- // io types
- .put(InputStream.class, new ByteArrayInputStream(new byte[0]))
- .put(ByteArrayInputStream.class, new ByteArrayInputStream(new byte[0]))
- .put(Readable.class, new StringReader(""))
- .put(Reader.class, new StringReader(""))
- .put(StringReader.class, new StringReader(""))
- .put(Buffer.class, ByteBuffer.allocate(0))
- .put(CharBuffer.class, CharBuffer.allocate(0))
- .put(ByteBuffer.class, ByteBuffer.allocate(0))
- .put(ShortBuffer.class, ShortBuffer.allocate(0))
- .put(IntBuffer.class, IntBuffer.allocate(0))
- .put(LongBuffer.class, LongBuffer.allocate(0))
- .put(FloatBuffer.class, FloatBuffer.allocate(0))
- .put(DoubleBuffer.class, DoubleBuffer.allocate(0))
- .put(File.class, new File(""))
- // All collections are immutable empty. So safe for any type parameter.
- .put(Iterator.class, Iterators.emptyIterator())
- .put(PeekingIterator.class, Iterators.peekingIterator(Iterators.emptyIterator()))
- .put(ListIterator.class, ImmutableList.of().listIterator())
- .put(Iterable.class, ImmutableSet.of())
- .put(Collection.class, ImmutableList.of())
- .put(ImmutableCollection.class, ImmutableList.of())
- .put(List.class, ImmutableList.of())
- .put(ImmutableList.class, ImmutableList.of())
- .put(Set.class, ImmutableSet.of())
- .put(ImmutableSet.class, ImmutableSet.of())
- .put(SortedSet.class, ImmutableSortedSet.of())
- .put(ImmutableSortedSet.class, ImmutableSortedSet.of())
- .put(NavigableSet.class, Sets.unmodifiableNavigableSet(Sets.newTreeSet()))
- .put(Map.class, ImmutableMap.of())
- .put(ImmutableMap.class, ImmutableMap.of())
- .put(SortedMap.class, ImmutableSortedMap.of())
- .put(ImmutableSortedMap.class, ImmutableSortedMap.of())
- .put(NavigableMap.class, Maps.unmodifiableNavigableMap(Maps.newTreeMap()))
- .put(Multimap.class, ImmutableMultimap.of())
- .put(ImmutableMultimap.class, ImmutableMultimap.of())
- .put(ListMultimap.class, ImmutableListMultimap.of())
- .put(ImmutableListMultimap.class, ImmutableListMultimap.of())
- .put(SetMultimap.class, ImmutableSetMultimap.of())
- .put(ImmutableSetMultimap.class, ImmutableSetMultimap.of())
- .put(SortedSetMultimap.class, Multimaps.unmodifiableSortedSetMultimap(TreeMultimap.create()))
- .put(Multiset.class, ImmutableMultiset.of())
- .put(ImmutableMultiset.class, ImmutableMultiset.of())
- .put(SortedMultiset.class, ImmutableSortedMultiset.of())
- .put(ImmutableSortedMultiset.class, ImmutableSortedMultiset.of())
- .put(BiMap.class, ImmutableBiMap.of())
- .put(ImmutableBiMap.class, ImmutableBiMap.of())
- .put(Table.class, ImmutableTable.of())
- .put(ImmutableTable.class, ImmutableTable.of())
- .put(RowSortedTable.class, Tables.unmodifiableRowSortedTable(TreeBasedTable.create()))
- .put(ClassToInstanceMap.class, ImmutableClassToInstanceMap.builder().build())
- .put(ImmutableClassToInstanceMap.class, ImmutableClassToInstanceMap.builder().build())
- .put(Comparable.class, ByToString.INSTANCE)
- .put(Comparator.class, AlwaysEqual.INSTANCE)
- .put(Ordering.class, AlwaysEqual.INSTANCE)
- .put(Range.class, Range.all())
- .put(Constraint.class, Constraints.notNull())
- .put(MapConstraint.class, MapConstraints.notNull())
- .put(MapDifference.class, Maps.difference(ImmutableMap.of(), ImmutableMap.of()))
- .put(SortedMapDifference.class,
- Maps.difference(ImmutableSortedMap.of(), ImmutableSortedMap.of()))
- // reflect
- .put(AnnotatedElement.class, Object.class)
- .put(GenericDeclaration.class, Object.class)
- .put(Type.class, Object.class)
- .build();
-
- /**
- * type -> implementation. Inherently mutable interfaces and abstract classes are mapped to their
- * default implementations and are "new"d upon get().
- */
- private static final ConcurrentMap<Class<?>, Class<?>> implementations = Maps.newConcurrentMap();
-
- private static <T> void setImplementation(Class<T> type, Class<? extends T> implementation) {
- checkArgument(type != implementation, "Don't register %s to itself!", type);
- checkArgument(!DEFAULTS.containsKey(type),
- "A default value was already registered for %s", type);
- checkArgument(implementations.put(type, implementation) == null,
- "Implementation for %s was already registered", type);
- }
-
- static {
- setImplementation(Appendable.class, StringBuilder.class);
- setImplementation(BlockingQueue.class, LinkedBlockingDeque.class);
- setImplementation(BlockingDeque.class, LinkedBlockingDeque.class);
- setImplementation(ConcurrentMap.class, ConcurrentHashMap.class);
- setImplementation(ConcurrentNavigableMap.class, ConcurrentSkipListMap.class);
- setImplementation(CountDownLatch.class, Dummies.DummyCountDownLatch.class);
- setImplementation(Deque.class, ArrayDeque.class);
- setImplementation(OutputStream.class, ByteArrayOutputStream.class);
- setImplementation(PrintStream.class, Dummies.InMemoryPrintStream.class);
- setImplementation(PrintWriter.class, Dummies.InMemoryPrintWriter.class);
- setImplementation(Queue.class, ArrayDeque.class);
- setImplementation(Random.class, Dummies.DeterministicRandom.class);
- setImplementation(ScheduledThreadPoolExecutor.class,
- Dummies.DummyScheduledThreadPoolExecutor.class);
- setImplementation(ThreadPoolExecutor.class, Dummies.DummyScheduledThreadPoolExecutor.class);
- setImplementation(Writer.class, StringWriter.class);
- setImplementation(Runnable.class, Dummies.DummyRunnable.class);
- setImplementation(ThreadFactory.class, Dummies.DummyThreadFactory.class);
- setImplementation(Executor.class, Dummies.DummyExecutor.class);
- }
-
- @SuppressWarnings("unchecked") // it's a subtype map
- @Nullable
- private static <T> Class<? extends T> getImplementation(Class<T> type) {
- return (Class<? extends T>) implementations.get(type);
- }
-
- private static final Logger logger = Logger.getLogger(ArbitraryInstances.class.getName());
-
- /**
- * Returns an arbitrary value for {@code type} as the null value, or {@code null} if empty-ness is
- * unknown for the type.
- */
- @Nullable public static <T> T get(Class<T> type) {
- T defaultValue = DEFAULTS.getInstance(type);
- if (defaultValue != null) {
- return defaultValue;
- }
- Class<? extends T> implementation = getImplementation(type);
- if (implementation != null) {
- return get(implementation);
- }
- if (type.isEnum()) {
- T[] enumConstants = type.getEnumConstants();
- return (enumConstants.length == 0)
- ? null
- : enumConstants[0];
- }
- if (type.isArray()) {
- return createEmptyArray(type);
- }
- T jvmDefault = Defaults.defaultValue(Primitives.unwrap(type));
- if (jvmDefault != null) {
- return jvmDefault;
- }
- if (Modifier.isAbstract(type.getModifiers()) || !Modifier.isPublic(type.getModifiers())) {
- return null;
- }
- final Constructor<T> constructor;
- try {
- constructor = type.getConstructor();
- } catch (NoSuchMethodException e) {
- return null;
- }
- constructor.setAccessible(true); // accessibility check is too slow
- try {
- return constructor.newInstance();
- } catch (InstantiationException impossible) {
- throw new AssertionError(impossible);
- } catch (IllegalAccessException impossible) {
- throw new AssertionError(impossible);
- } catch (InvocationTargetException e) {
- logger.log(Level.WARNING, "Exception while invoking default constructor.", e.getCause());
- return null;
- }
- }
-
- @SuppressWarnings("unchecked") // same component type means same array type
- private static <T> T createEmptyArray(Class<T> arrayType) {
- return (T) Array.newInstance(arrayType.getComponentType(), 0);
- }
-
- // Internal implementations of some classes, with public default constructor that get() needs.
- private static final class Dummies {
-
- public static final class InMemoryPrintStream extends PrintStream {
- public InMemoryPrintStream() {
- super(new ByteArrayOutputStream());
- }
- }
-
- public static final class InMemoryPrintWriter extends PrintWriter {
- public InMemoryPrintWriter() {
- super(new StringWriter());
- }
- }
-
- public static final class DeterministicRandom extends Random {
- @SuppressWarnings("unused") // invoked by reflection
- public DeterministicRandom() {
- super(0);
- }
- }
-
- public static final class DummyScheduledThreadPoolExecutor extends ScheduledThreadPoolExecutor {
- public DummyScheduledThreadPoolExecutor() {
- super(1);
- }
- }
-
- public static final class DummyCountDownLatch extends CountDownLatch {
- public DummyCountDownLatch() {
- super(0);
- }
- }
-
- public static final class DummyRunnable implements Runnable, Serializable {
- @Override public void run() {}
- }
-
- public static final class DummyThreadFactory implements ThreadFactory, Serializable {
- @Override public Thread newThread(Runnable r) {
- return new Thread(r);
- }
- }
-
- public static final class DummyExecutor implements Executor, Serializable {
- @Override public void execute(Runnable command) {}
- }
- }
-
- // Compare by toString() to satisfy 2 properties:
- // 1. compareTo(null) should throw NullPointerException
- // 2. the order is deterministic and easy to understand, for debugging purpose.
- private static final class ByToString implements Comparable<Object>, Serializable {
- private static final ByToString INSTANCE = new ByToString();
-
- @Override public int compareTo(Object o) {
- return toString().compareTo(o.toString());
- }
-
- @Override public String toString() {
- return "BY_TO_STRING";
- }
-
- private Object readResolve() {
- return INSTANCE;
- }
- }
-
- // Always equal is a valid total ordering. And it works for any Object.
- private static final class AlwaysEqual extends Ordering<Object> implements Serializable {
- private static final AlwaysEqual INSTANCE = new AlwaysEqual();
-
- @Override public int compare(Object o1, Object o2) {
- return 0;
- }
-
- @Override public String toString() {
- return "ALWAYS_EQUAL";
- }
-
- private Object readResolve() {
- return INSTANCE;
- }
- }
-
- private ArbitraryInstances() {}
-}
diff --git a/guava-testlib/src/com/google/common/testing/ClassSanityTester.java b/guava-testlib/src/com/google/common/testing/ClassSanityTester.java
deleted file mode 100644
index 4b273fb..0000000
--- a/guava-testlib/src/com/google/common/testing/ClassSanityTester.java
+++ /dev/null
@@ -1,765 +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.testing;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Joiner;
-import com.google.common.base.Objects;
-import com.google.common.base.Throwables;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.MutableClassToInstanceMap;
-import com.google.common.collect.Ordering;
-import com.google.common.collect.Sets;
-import com.google.common.primitives.Ints;
-import com.google.common.reflect.Invokable;
-import com.google.common.reflect.Parameter;
-import com.google.common.reflect.Reflection;
-import com.google.common.reflect.TypeToken;
-import com.google.common.testing.NullPointerTester.Visibility;
-import com.google.common.testing.RelationshipTester.Item;
-import com.google.common.testing.RelationshipTester.ItemReporter;
-
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-
-import java.io.Serializable;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.annotation.Nullable;
-
-/**
- * Tester that runs automated sanity tests for any given class. A typical use case is to test static
- * factory classes like: <pre>
- * interface Book {...}
- * public class Books {
- * public static Book hardcover(String title) {...}
- * public static Book paperback(String title) {...}
- * }
- * </pre>
- * And all the created {@code Book} instances can be tested with: <pre>
- * new ClassSanityTester()
- * .forAllPublicStaticMethods(Books.class)
- * .thatReturn(Book.class)
- * .testEquals(); // or testNulls(), testSerializable() etc.
- * </pre>
- *
- * @author Ben Yu
- * @since 14.0
- */
-@Beta
-public final class ClassSanityTester {
-
- private static final Ordering<Invokable<?, ?>> BY_METHOD_NAME =
- new Ordering<Invokable<?, ?>>() {
- @Override public int compare(Invokable<?, ?> left, Invokable<?, ?> right) {
- return left.getName().compareTo(right.getName());
- }
- };
-
- private static final Ordering<Invokable<?, ?>> BY_PARAMETERS =
- new Ordering<Invokable<?, ?>>() {
- @Override public int compare(Invokable<?, ?> left, Invokable<?, ?> right) {
- return Ordering.usingToString().compare(left.getParameters(), right.getParameters());
- }
- };
-
- private static final Ordering<Invokable<?, ?>> BY_NUMBER_OF_PARAMETERS =
- new Ordering<Invokable<?, ?>>() {
- @Override public int compare(Invokable<?, ?> left, Invokable<?, ?> right) {
- return Ints.compare(left.getParameters().size(), right.getParameters().size());
- }
- };
-
- private final MutableClassToInstanceMap<Object> defaultValues =
- MutableClassToInstanceMap.create();
- private final ListMultimap<Class<?>, Object> sampleInstances = ArrayListMultimap.create();
- private final NullPointerTester nullPointerTester = new NullPointerTester();
-
- public ClassSanityTester() {
- // TODO(benyu): bake these into ArbitraryInstances.
- setDefault(byte.class, (byte) 1);
- setDefault(Byte.class, (byte) 1);
- setDefault(short.class, (short) 1);
- setDefault(Short.class, (short) 1);
- setDefault(int.class, 1);
- setDefault(Integer.class, 1);
- setDefault(long.class, 1L);
- setDefault(Long.class, 1L);
- setDefault(float.class, 1F);
- setDefault(Float.class, 1F);
- setDefault(double.class, 1D);
- setDefault(Double.class, 1D);
- setDefault(Class.class, Class.class);
- }
-
- /**
- * Sets the default value for {@code type}. The default value isn't used in testing {@link
- * Object#equals} because more than one sample instances are needed for testing inequality.
- * To set sample instances for equality testing, use {@link #setSampleInstances} instead.
- */
- public <T> ClassSanityTester setDefault(Class<T> type, T value) {
- nullPointerTester.setDefault(type, value);
- defaultValues.putInstance(type, value);
- return this;
- }
-
- /**
- * Sets sample instances for {@code type} for purpose of {@code equals} testing, where different
- * values are needed to test inequality.
- *
- * <p>Used for types that {@link ClassSanityTester} doesn't already know how to sample.
- * It's usually necessary to add two unequal instances for each type, with the exception that if
- * the sample instance is to be passed to a {@link Nullable} parameter, one non-null sample is
- * sufficient. Setting an empty list will clear sample instances for {@code type}.
- */
- public <T> ClassSanityTester setSampleInstances(Class<T> type, Iterable<? extends T> instances) {
- ImmutableList<? extends T> samples = ImmutableList.copyOf(instances);
- sampleInstances.putAll(checkNotNull(type), samples);
- if (!samples.isEmpty()) {
- setDefault(type, samples.get(0));
- }
- return this;
- }
-
- /**
- * Tests that {@code cls} properly checks null on all constructor and method parameters that
- * aren't annotated with {@link Nullable}. In details:
- * <ul>
- * <li>All non-private static methods are checked such that passing null for any parameter that's
- * not annotated with {@link javax.annotation.Nullable} should throw {@link
- * NullPointerException}.
- * <li>If there is any non-private constructor or non-private static factory method declared by
- * {@code cls}, all non-private instance methods will be checked too using the instance
- * created by invoking the constructor or static factory method.
- * <li>If there is any non-private constructor or non-private static factory method declared by
- * {@code cls}:
- * <ul>
- * <li>Test will fail if default value for a parameter cannot be determined.
- * <li>Test will fail if the factory method returns null so testing instance methods is
- * impossible.
- * <li>Test will fail if the constructor or factory method throws exception.
- * </ul>
- * <li>If there is no non-private constructor or non-private static factory method declared by
- * {@code cls}, instance methods are skipped for nulls test.
- * <li>Nulls test is not performed on method return values unless the method is a non-private
- * static factory method whose return type is {@code cls} or {@code cls}'s subtype.
- * </ul>
- */
- public void testNulls(Class<?> cls) {
- try {
- doTestNulls(cls, Visibility.PACKAGE);
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
-
- void doTestNulls(Class<?> cls, Visibility visibility)
- throws ParameterNotInstantiableException, IllegalAccessException,
- InvocationTargetException, FactoryMethodReturnsNullException {
- if (!Modifier.isAbstract(cls.getModifiers())) {
- nullPointerTester.testConstructors(cls, visibility);
- }
- nullPointerTester.testStaticMethods(cls, visibility);
- if (hasInstanceMethodToTestNulls(cls, visibility)) {
- Object instance = instantiate(cls);
- if (instance != null) {
- nullPointerTester.testInstanceMethods(instance, visibility);
- }
- }
- }
-
- private boolean hasInstanceMethodToTestNulls(Class<?> c, Visibility visibility) {
- for (Method method : nullPointerTester.getInstanceMethodsToTest(c, visibility)) {
- for (Parameter param : Invokable.from(method).getParameters()) {
- if (!NullPointerTester.isPrimitiveOrNullable(param)) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Tests the {@link Object#equals} and {@link Object#hashCode} of {@code cls}. In details:
- * <ul>
- * <li>The non-private constructor or non-private static factory method with the most parameters
- * is used to construct the sample instances. In case of tie, the candidate constructors or
- * factories are tried one after another until one can be used to construct sample instances.
- * <li>For the constructor or static factory method used to construct instances, it's checked that
- * when equal parameters are passed, the result instance should also be equal; and vice versa.
- * <li>If a non-private constructor or non-private static factory method exists: <ul>
- * <li>Test will fail if default value for a parameter cannot be determined.
- * <li>Test will fail if the factory method returns null so testing instance methods is
- * impossible.
- * <li>Test will fail if the constructor or factory method throws exception.
- * </ul>
- * <li>If there is no non-private constructor or non-private static factory method declared by
- * {@code cls}, no test is performed.
- * <li>Equality test is not performed on method return values unless the method is a non-private
- * static factory method whose return type is {@code cls} or {@code cls}'s subtype.
- * <li>Inequality check is not performed against state mutation methods such as {@link List#add},
- * or functional update methods such as {@link com.google.common.base.Joiner#skipNulls}.
- * </ul>
- *
- * <p>Note that constructors taking a builder object cannot be tested effectively because
- * semantics of builder can be arbitrarily complex. Still, a factory class can be created in the
- * test to facilitate equality testing. For example: <pre>
- * public class FooTest {
- *
- * private static class FooFactoryForTest {
- * public static Foo create(String a, String b, int c, boolean d) {
- * return Foo.builder()
- * .setA(a)
- * .setB(b)
- * .setC(c)
- * .setD(d)
- * .build();
- * }
- * }
- *
- * public void testEquals() {
- * new ClassSanityTester()
- * .forAllPublicStaticMethods(FooFactoryForTest.class)
- * .thatReturn(Foo.class)
- * .testEquals();
- * }
- * }
- * </pre>
- * It will test that Foo objects created by the {@code create(a, b, c, d)} factory method with
- * equal parameters are equal and vice versa, thus indirectly tests the builder equality.
- */
- public void testEquals(Class<?> cls) {
- try {
- doTestEquals(cls);
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
-
- void doTestEquals(Class<?> cls)
- throws ParameterNotInstantiableException, IllegalAccessException,
- InvocationTargetException, FactoryMethodReturnsNullException {
- if (cls.isEnum()) {
- return;
- }
- List<? extends Invokable<?, ?>> factories = Lists.reverse(getFactories(TypeToken.of(cls)));
- if (factories.isEmpty()) {
- return;
- }
- int numberOfParameters = factories.get(0).getParameters().size();
- List<ParameterNotInstantiableException> paramErrors = Lists.newArrayList();
- List<InvocationTargetException> instantiationExceptions = Lists.newArrayList();
- List<FactoryMethodReturnsNullException> nullErrors = Lists.newArrayList();
- // Try factories with the greatest number of parameters first.
- for (Invokable<?, ?> factory : factories) {
- if (factory.getParameters().size() == numberOfParameters) {
- try {
- testEqualsUsing(factory);
- return;
- } catch (ParameterNotInstantiableException e) {
- paramErrors.add(e);
- } catch (InvocationTargetException e) {
- instantiationExceptions.add(e);
- } catch (FactoryMethodReturnsNullException e) {
- nullErrors.add(e);
- }
- }
- }
- throwFirst(paramErrors);
- throwFirst(instantiationExceptions);
- throwFirst(nullErrors);
- }
-
- /**
- * Instantiates {@code cls} by invoking one of its non-private constructors or non-private static
- * factory methods with the parameters automatically provided using dummy values.
- *
- * @return The instantiated instance, or {@code null} if the class has no non-private constructor
- * or factory method to be constructed.
- */
- @Nullable <T> T instantiate(Class<T> cls)
- throws ParameterNotInstantiableException, IllegalAccessException,
- InvocationTargetException, FactoryMethodReturnsNullException {
- if (cls.isEnum()) {
- T[] constants = cls.getEnumConstants();
- if (constants.length > 0) {
- return constants[0];
- } else {
- return null;
- }
- }
- TypeToken<T> type = TypeToken.of(cls);
- List<ParameterNotInstantiableException> paramErrors = Lists.newArrayList();
- List<InvocationTargetException> instantiationExceptions = Lists.newArrayList();
- List<FactoryMethodReturnsNullException> nullErrors = Lists.newArrayList();
- for (Invokable<?, ? extends T> factory : getFactories(type)) {
- T instance;
- try {
- instance = instantiate(factory);
- } catch (ParameterNotInstantiableException e) {
- paramErrors.add(e);
- continue;
- } catch (InvocationTargetException e) {
- instantiationExceptions.add(e);
- continue;
- }
- if (instance == null) {
- nullErrors.add(new FactoryMethodReturnsNullException(factory));
- } else {
- return instance;
- }
- }
- throwFirst(paramErrors);
- throwFirst(instantiationExceptions);
- throwFirst(nullErrors);
- return null;
- }
-
- /**
- * Returns an object responsible for performing sanity tests against the return values
- * of all public static methods declared by {@code cls}, excluding superclasses.
- */
- public FactoryMethodReturnValueTester forAllPublicStaticMethods(Class<?> cls) {
- ImmutableList.Builder<Invokable<?, ?>> builder = ImmutableList.builder();
- for (Method method : cls.getDeclaredMethods()) {
- Invokable<?, ?> invokable = Invokable.from(method);
- invokable.setAccessible(true);
- if (invokable.isPublic() && invokable.isStatic() && !invokable.isSynthetic()) {
- builder.add(invokable);
- }
- }
- return new FactoryMethodReturnValueTester(cls, builder.build(), "public static methods");
- }
-
- /** Runs sanity tests against return values of static factory methods declared by a class. */
- public final class FactoryMethodReturnValueTester {
- private final Set<String> packagesToTest = Sets.newHashSet();
- private final Class<?> declaringClass;
- private final ImmutableList<Invokable<?, ?>> factories;
- private final String factoryMethodsDescription;
- private Class<?> returnTypeToTest = Object.class;
-
- private FactoryMethodReturnValueTester(
- Class<?> declaringClass,
- ImmutableList<Invokable<?, ?>> factories,
- String factoryMethodsDescription) {
- this.declaringClass = declaringClass;
- this.factories = factories;
- this.factoryMethodsDescription = factoryMethodsDescription;
- packagesToTest.add(Reflection.getPackageName(declaringClass));
- }
-
- /**
- * Specifies that only the methods that are declared to return {@code returnType} or its subtype
- * are tested.
- *
- * @return this tester object
- */
- public FactoryMethodReturnValueTester thatReturn(Class<?> returnType) {
- this.returnTypeToTest = returnType;
- return this;
- }
-
- /**
- * Tests null checks against the instance methods of the return values, if any.
- *
- * <p>Test fails if default value cannot be determined for a constructor or factory method
- * parameter, or if the constructor or factory method throws exception.
- *
- * @return this tester
- */
- public FactoryMethodReturnValueTester testNulls() throws Exception {
- for (Invokable<?, ?> factory : getFactoriesToTest()) {
- Object instance = instantiate(factory);
- if (instance != null
- && packagesToTest.contains(Reflection.getPackageName(instance.getClass()))) {
- try {
- nullPointerTester.testAllPublicInstanceMethods(instance);
- } catch (AssertionError e) {
- AssertionError error = new AssertionFailedError(
- "Null check failed on return value of " + factory);
- error.initCause(e);
- throw error;
- }
- }
- }
- return this;
- }
-
- /**
- * Tests {@link Object#equals} and {@link Object#hashCode} against the return values of the
- * static methods, by asserting that when equal parameters are passed to the same static method,
- * the return value should also be equal; and vice versa.
- *
- * <p>Test fails if default value cannot be determined for a constructor or factory method
- * parameter, or if the constructor or factory method throws exception.
- *
- * @return this tester
- */
- public FactoryMethodReturnValueTester testEquals() throws Exception {
- for (Invokable<?, ?> factory : getFactoriesToTest()) {
- try {
- testEqualsUsing(factory);
- } catch (FactoryMethodReturnsNullException e) {
- // If the factory returns null, we just skip it.
- }
- }
- return this;
- }
-
- /**
- * Runs serialization test on the return values of the static methods.
- *
- * <p>Test fails if default value cannot be determined for a constructor or factory method
- * parameter, or if the constructor or factory method throws exception.
- *
- * @return this tester
- */
- public FactoryMethodReturnValueTester testSerializable() throws Exception {
- for (Invokable<?, ?> factory : getFactoriesToTest()) {
- Object instance = instantiate(factory);
- if (instance != null) {
- try {
- SerializableTester.reserialize(instance);
- } catch (RuntimeException e) {
- AssertionError error = new AssertionFailedError(
- "Serialization failed on return value of " + factory);
- error.initCause(e.getCause());
- throw error;
- }
- }
- }
- return this;
- }
-
- /**
- * Runs equals and serialization test on the return values.
- *
- * <p>Test fails if default value cannot be determined for a constructor or factory method
- * parameter, or if the constructor or factory method throws exception.
- *
- * @return this tester
- */
- public FactoryMethodReturnValueTester testEqualsAndSerializable() throws Exception {
- for (Invokable<?, ?> factory : getFactoriesToTest()) {
- try {
- testEqualsUsing(factory);
- } catch (FactoryMethodReturnsNullException e) {
- // If the factory returns null, we just skip it.
- }
- Object instance = instantiate(factory);
- if (instance != null) {
- try {
- SerializableTester.reserializeAndAssert(instance);
- } catch (RuntimeException e) {
- AssertionError error = new AssertionFailedError(
- "Serialization failed on return value of " + factory);
- error.initCause(e.getCause());
- throw error;
- } catch (AssertionFailedError e) {
- AssertionError error = new AssertionFailedError(
- "Return value of " + factory + " reserialized to an unequal value");
- error.initCause(e);
- throw error;
- }
- }
- }
- return this;
- }
-
- private ImmutableList<Invokable<?, ?>> getFactoriesToTest() {
- ImmutableList.Builder<Invokable<?, ?>> builder = ImmutableList.builder();
- for (Invokable<?, ?> factory : factories) {
- if (returnTypeToTest.isAssignableFrom(factory.getReturnType().getRawType())) {
- builder.add(factory);
- }
- }
- ImmutableList<Invokable<?, ?>> factoriesToTest = builder.build();
- Assert.assertFalse("No " + factoryMethodsDescription + " that return "
- + returnTypeToTest.getName() + " or subtype are found in "
- + declaringClass + ".",
- factoriesToTest.isEmpty());
- return factoriesToTest;
- }
- }
-
- /**
- * Instantiates using {@code factory}. If {@code factory} is annotated with {@link Nullable} and
- * returns null, null will be returned.
- *
- * @throws ParameterNotInstantiableException if the static methods cannot be invoked because
- * the default value of a parameter cannot be determined.
- * @throws IllegalAccessException if the class isn't public or is nested inside a non-public
- * class, preventing its methods from being accessible.
- * @throws InvocationTargetException if a static method threw exception.
- */
- @Nullable private <T> T instantiate(Invokable<?, ? extends T> factory)
- throws ParameterNotInstantiableException, InvocationTargetException,
- IllegalAccessException {
- return invoke(factory, getDummyArguments(factory));
- }
-
- private void testEqualsUsing(final Invokable<?, ?> factory)
- throws ParameterNotInstantiableException, IllegalAccessException,
- InvocationTargetException, FactoryMethodReturnsNullException {
- List<Parameter> params = factory.getParameters();
- List<FreshValueGenerator> argGenerators = Lists.newArrayListWithCapacity(params.size());
- List<Object> args = Lists.newArrayListWithCapacity(params.size());
- for (Parameter param : params) {
- FreshValueGenerator generator = newFreshValueGenerator();
- argGenerators.add(generator);
- args.add(generateDummyArg(param, generator));
- }
- Object instance = createInstance(factory, args);
- List<Object> equalArgs = generateEqualFactoryArguments(factory, params, args);
- // Each group is a List of items, each item has a list of factory args.
- final List<List<List<Object>>> argGroups = Lists.newArrayList();
- argGroups.add(ImmutableList.of(args, equalArgs));
- EqualsTester tester = new EqualsTester().setItemReporter(new ItemReporter() {
- @Override String reportItem(Item item) {
- List<Object> factoryArgs = argGroups.get(item.groupNumber).get(item.itemNumber);
- return factory.getName() + "(" + Joiner.on(", ").useForNull("null").join(factoryArgs) + ")";
- }
- });
- tester.addEqualityGroup(instance, createInstance(factory, equalArgs));
- for (int i = 0; i < params.size(); i++) {
- List<Object> newArgs = Lists.newArrayList(args);
- Object newArg = argGenerators.get(i).generate(params.get(i).getType().getRawType());
- if (Objects.equal(args.get(i), newArg)) {
- // no value variance, no equality group
- continue;
- }
- newArgs.set(i, newArg);
- tester.addEqualityGroup(createInstance(factory, newArgs));
- argGroups.add(ImmutableList.of(newArgs));
- }
- tester.testEquals();
- }
-
- /**
- * Returns dummy factory arguments that are equal to {@code args} but may be different instances,
- * to be used to construct a second instance of the same equality group.
- */
- private List<Object> generateEqualFactoryArguments(
- Invokable<?, ?> factory, List<Parameter> params, List<Object> args)
- throws ParameterNotInstantiableException, FactoryMethodReturnsNullException,
- InvocationTargetException, IllegalAccessException {
- List<Object> equalArgs = Lists.newArrayList(args);
- for (int i = 0; i < args.size(); i++) {
- Parameter param = params.get(i);
- Object arg = args.get(i);
- // Use new fresh value generator because 'args' were populated with new fresh generator each.
- // Two newFreshValueGenerator() instances should normally generate equal value sequence.
- Object shouldBeEqualArg = generateDummyArg(param, newFreshValueGenerator());
- if (arg != shouldBeEqualArg
- && Objects.equal(arg, shouldBeEqualArg)
- && hashCodeInsensitiveToArgReference(factory, args, i, shouldBeEqualArg)
- && hashCodeInsensitiveToArgReference(
- factory, args, i, generateDummyArg(param, newFreshValueGenerator()))) {
- // If the implementation uses identityHashCode(), referential equality is
- // probably intended. So no point in using an equal-but-different factory argument.
- // We check twice to avoid confusion caused by accidental hash collision.
- equalArgs.set(i, shouldBeEqualArg);
- }
- }
- return equalArgs;
- }
-
- private static boolean hashCodeInsensitiveToArgReference(
- Invokable<?, ?> factory, List<Object> args, int i, Object alternateArg)
- throws FactoryMethodReturnsNullException, InvocationTargetException, IllegalAccessException {
- List<Object> tentativeArgs = Lists.newArrayList(args);
- tentativeArgs.set(i, alternateArg);
- return createInstance(factory, tentativeArgs).hashCode()
- == createInstance(factory, args).hashCode();
- }
-
- // sampleInstances is a type-safe class-values mapping, but we don't have a type-safe data
- // data structure to hold the mappings.
- @SuppressWarnings({"unchecked", "rawtypes"})
- private FreshValueGenerator newFreshValueGenerator() {
- FreshValueGenerator generator = new FreshValueGenerator() {
- @Override Object interfaceMethodCalled(Class<?> interfaceType, Method method) {
- return getDummyValue(TypeToken.of(interfaceType).method(method).getReturnType());
- }
- };
- for (Map.Entry<Class<?>, Collection<Object>> entry : sampleInstances.asMap().entrySet()) {
- generator.addSampleInstances((Class) entry.getKey(), entry.getValue());
- }
- return generator;
- }
-
- private static @Nullable Object generateDummyArg(Parameter param, FreshValueGenerator generator)
- throws ParameterNotInstantiableException {
- if (param.isAnnotationPresent(Nullable.class)) {
- return null;
- }
- Object arg = generator.generate(param.getType());
- if (arg == null) {
- throw new ParameterNotInstantiableException(param);
- }
- return arg;
- }
-
- private static <X extends Throwable> void throwFirst(List<X> exceptions) throws X {
- if (!exceptions.isEmpty()) {
- throw exceptions.get(0);
- }
- }
-
- /** Factories with the least number of parameters are listed first. */
- private static <T> ImmutableList<Invokable<?, ? extends T>> getFactories(TypeToken<T> type) {
- List<Invokable<?, ? extends T>> factories = Lists.newArrayList();
- for (Method method : type.getRawType().getDeclaredMethods()) {
- Invokable<?, ?> invokable = type.method(method);
- if (!invokable.isPrivate()
- && !invokable.isSynthetic()
- && invokable.isStatic()
- && type.isAssignableFrom(invokable.getReturnType())) {
- @SuppressWarnings("unchecked") // guarded by isAssignableFrom()
- Invokable<?, ? extends T> factory = (Invokable<?, ? extends T>) invokable;
- factories.add(factory);
- }
- }
- if (!Modifier.isAbstract(type.getRawType().getModifiers())) {
- for (Constructor<?> constructor : type.getRawType().getDeclaredConstructors()) {
- Invokable<T, T> invokable = type.constructor(constructor);
- if (!invokable.isPrivate() && !invokable.isSynthetic()) {
- factories.add(invokable);
- }
- }
- }
- for (Invokable<?, ?> factory : factories) {
- factory.setAccessible(true);
- }
- // Sorts methods/constructors with least number of parameters first since it's likely easier to
- // fill dummy parameter values for them. Ties are broken by name then by the string form of the
- // parameter list.
- return BY_NUMBER_OF_PARAMETERS.compound(BY_METHOD_NAME).compound(BY_PARAMETERS)
- .immutableSortedCopy(factories);
- }
-
- private List<Object> getDummyArguments(Invokable<?, ?> invokable)
- throws ParameterNotInstantiableException {
- List<Object> args = Lists.newArrayList();
- for (Parameter param : invokable.getParameters()) {
- if (param.isAnnotationPresent(Nullable.class)) {
- args.add(null);
- continue;
- }
- Object defaultValue = getDummyValue(param.getType());
- if (defaultValue == null) {
- throw new ParameterNotInstantiableException(param);
- }
- args.add(defaultValue);
- }
- return args;
- }
-
- private <T> T getDummyValue(TypeToken<T> type) {
- Class<? super T> rawType = type.getRawType();
- @SuppressWarnings("unchecked") // Assume all default values are generics safe.
- T defaultValue = (T) defaultValues.getInstance(rawType);
- if (defaultValue != null) {
- return defaultValue;
- }
- @SuppressWarnings("unchecked") // ArbitraryInstances always returns generics-safe dummies.
- T value = (T) ArbitraryInstances.get(rawType);
- if (value != null) {
- return value;
- }
- if (rawType.isInterface()) {
- return new SerializableDummyProxy(this).newProxy(type);
- }
- return null;
- }
-
- private static <T> T createInstance(Invokable<?, ? extends T> factory, List<?> args)
- throws FactoryMethodReturnsNullException, InvocationTargetException, IllegalAccessException {
- T instance = invoke(factory, args);
- if (instance == null) {
- throw new FactoryMethodReturnsNullException(factory);
- }
- return instance;
- }
-
- @Nullable private static <T> T invoke(Invokable<?, ? extends T> factory, List<?> args)
- throws InvocationTargetException, IllegalAccessException {
- T returnValue = factory.invoke(null, args.toArray());
- if (returnValue == null) {
- Assert.assertTrue(factory + " returns null but it's not annotated with @Nullable",
- factory.isAnnotationPresent(Nullable.class));
- }
- return returnValue;
- }
-
- /**
- * Thrown if the test tries to invoke a constructor or static factory method but failed because
- * the dummy value of a constructor or method parameter is unknown.
- */
- @VisibleForTesting static class ParameterNotInstantiableException extends Exception {
- public ParameterNotInstantiableException(Parameter parameter) {
- super("Cannot determine value for parameter " + parameter
- + " of " + parameter.getDeclaringInvokable());
- }
- }
-
- /**
- * Thrown if the test tries to invoke a static factory method to test instance methods but the
- * factory returned null.
- */
- @VisibleForTesting static class FactoryMethodReturnsNullException extends Exception {
- public FactoryMethodReturnsNullException(Invokable<?, ?> factory) {
- super(factory + " returns null and cannot be used to test instance methods.");
- }
- }
-
- private static final class SerializableDummyProxy extends DummyProxy
- implements Serializable {
-
- private transient final ClassSanityTester tester;
-
- SerializableDummyProxy(ClassSanityTester tester) {
- this.tester = tester;
- }
-
- @Override <R> R dummyReturnValue(TypeToken<R> returnType) {
- return tester.getDummyValue(returnType);
- }
-
- @Override public boolean equals(Object obj) {
- return obj instanceof SerializableDummyProxy;
- }
-
- @Override public int hashCode() {
- return 0;
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/testing/DummyProxy.java b/guava-testlib/src/com/google/common/testing/DummyProxy.java
deleted file mode 100644
index 71017af..0000000
--- a/guava-testlib/src/com/google/common/testing/DummyProxy.java
+++ /dev/null
@@ -1,110 +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.testing;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Sets;
-import com.google.common.reflect.AbstractInvocationHandler;
-import com.google.common.reflect.Invokable;
-import com.google.common.reflect.Parameter;
-import com.google.common.reflect.TypeToken;
-
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Set;
-
-import javax.annotation.Nullable;
-
-/**
- * Generates a dummy interface proxy that simply returns a dummy value for each method.
- *
- * @author Ben Yu
- */
-abstract class DummyProxy {
-
- /**
- * Returns a new proxy for {@code interfaceType}. Proxies of the same interface are equal to each
- * other if the {@link DummyProxy} instance that created the proxies are equal.
- */
- final <T> T newProxy(TypeToken<T> interfaceType) {
- Set<Class<?>> interfaceClasses = Sets.newLinkedHashSet();
- interfaceClasses.addAll(interfaceType.getTypes().interfaces().rawTypes());
- // Make the proxy serializable to work with SerializableTester
- interfaceClasses.add(Serializable.class);
- Object dummy = Proxy.newProxyInstance(
- interfaceClasses.iterator().next().getClassLoader(),
- interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
- new DummyHandler(interfaceType));
- @SuppressWarnings("unchecked") // interfaceType is T
- T result = (T) dummy;
- return result;
- }
-
- /** Returns the dummy return value for {@code returnType}. */
- abstract <R> R dummyReturnValue(TypeToken<R> returnType);
-
- private class DummyHandler extends AbstractInvocationHandler implements Serializable {
- private final TypeToken<?> interfaceType;
-
- DummyHandler(TypeToken<?> interfaceType) {
- this.interfaceType = interfaceType;
- }
-
- @Override protected Object handleInvocation(
- Object proxy, Method method, Object[] args) {
- Invokable<?, ?> invokable = interfaceType.method(method);
- ImmutableList<Parameter> params = invokable.getParameters();
- for (int i = 0; i < args.length; i++) {
- Parameter param = params.get(i);
- if (!param.isAnnotationPresent(Nullable.class)) {
- checkNotNull(args[i]);
- }
- }
- return dummyReturnValue(interfaceType.resolveType(method.getGenericReturnType()));
- }
-
- @Override public int hashCode() {
- return identity().hashCode();
- }
-
- @Override public boolean equals(Object obj) {
- if (obj instanceof DummyHandler) {
- DummyHandler that = (DummyHandler) obj;
- return identity().equals(that.identity());
- } else {
- return false;
- }
- }
-
- private DummyProxy identity() {
- return DummyProxy.this;
- }
-
- @Override public String toString() {
- return "Dummy proxy for " + interfaceType;
- }
-
- // Since type variables aren't serializable, reduce the type down to raw type before
- // serialization.
- private Object writeReplace() {
- return new DummyHandler(TypeToken.of(interfaceType.getRawType()));
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/testing/EqualsTester.java b/guava-testlib/src/com/google/common/testing/EqualsTester.java
index 50b58c3..4ee69bf 100644
--- a/guava-testlib/src/com/google/common/testing/EqualsTester.java
+++ b/guava-testlib/src/com/google/common/testing/EqualsTester.java
@@ -47,13 +47,12 @@ import java.util.List;
* <ul>
* <li>comparing each object against itself returns true
* <li>comparing each object against null returns false
- * <li>comparing each object against an instance of an incompatible class
- * returns false
+ * <li>comparing each object an instance of an incompatible class returns false
* <li>comparing each pair of objects within the same equality group returns
* true
* <li>comparing each pair of objects from different equality groups returns
* false
- * <li>the hash codes of any two equal objects are equal
+ * <li>the hash code of any two equal objects are equal
* </ul>
*
* <p>When a test fails, the error message labels the objects involved in
@@ -76,7 +75,6 @@ public final class EqualsTester {
private static final int REPETITIONS = 3;
private final List<List<Object>> equalityGroups = Lists.newArrayList();
- private RelationshipTester.ItemReporter itemReporter = new RelationshipTester.ItemReporter();
/**
* Constructs an empty EqualsTester instance
@@ -112,7 +110,7 @@ public final class EqualsTester {
// RelationshipAssertions in general) accept null inputs?
assertTrue("$ITEM must be unequal to $UNRELATED", !Objects.equal(item, unrelated));
}
- }, itemReporter);
+ });
for (List<Object> group : equalityGroups) {
delegate.addRelatedGroup(group);
}
@@ -123,11 +121,6 @@ public final class EqualsTester {
return this;
}
- EqualsTester setItemReporter(RelationshipTester.ItemReporter reporter) {
- this.itemReporter = checkNotNull(reporter);
- return this;
- }
-
private void testItems() {
for (Object item : Iterables.concat(equalityGroups)) {
assertTrue(item + " must be unequal to null", !item.equals(null));
diff --git a/guava-testlib/src/com/google/common/testing/EquivalenceTester.java b/guava-testlib/src/com/google/common/testing/EquivalenceTester.java
index d74155e..40e5a27 100644
--- a/guava-testlib/src/com/google/common/testing/EquivalenceTester.java
+++ b/guava-testlib/src/com/google/common/testing/EquivalenceTester.java
@@ -47,7 +47,7 @@ import java.util.List;
* </pre>
*
* <p>
- * Note that testing {@link Object#equals(Object)} is more simply done using
+ * Note that testing {@link Objects#equals(Object)} is more simply done using
* the {@link EqualsTester}. It includes an extra test against an instance of an
* arbitrary class without having to explicitly add another equivalence group.
*
diff --git a/guava-testlib/src/com/google/common/testing/FakeTicker.java b/guava-testlib/src/com/google/common/testing/FakeTicker.java
index b4237df..9f32120 100644
--- a/guava-testlib/src/com/google/common/testing/FakeTicker.java
+++ b/guava-testlib/src/com/google/common/testing/FakeTicker.java
@@ -16,8 +16,6 @@
package com.google.common.testing;
-import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Ticker;
@@ -28,9 +26,6 @@ import java.util.concurrent.atomic.AtomicLong;
/**
* A Ticker whose value can be advanced programmatically in test.
* <p>
- * The ticker can be configured so that the time is incremented whenever {@link #read} is called:
- * see {@link #setAutoIncrementStep}.
- * <p>
* This class is thread-safe.
*
* @author Jige Yu
@@ -41,7 +36,6 @@ import java.util.concurrent.atomic.AtomicLong;
public class FakeTicker extends Ticker {
private final AtomicLong nanos = new AtomicLong();
- private volatile long autoIncrementStepNanos;
/** Advances the ticker value by {@code time} in {@code timeUnit}. */
public FakeTicker advance(long time, TimeUnit timeUnit) {
@@ -54,19 +48,7 @@ public class FakeTicker extends Ticker {
return this;
}
- /**
- * Sets the increment applied to the ticker whenever it is queried.
- *
- * <p>The default behavior is to auto increment by zero. i.e: The ticker is left unchanged when
- * queried.
- */
- public FakeTicker setAutoIncrementStep(long autoIncrementStep, TimeUnit timeUnit) {
- checkArgument(autoIncrementStep >= 0, "May not auto-increment by a negative amount");
- this.autoIncrementStepNanos = timeUnit.toNanos(autoIncrementStep);
- return this;
- }
-
@Override public long read() {
- return nanos.getAndAdd(autoIncrementStepNanos);
+ return nanos.get();
}
}
diff --git a/guava-testlib/src/com/google/common/testing/ForwardingWrapperTester.java b/guava-testlib/src/com/google/common/testing/ForwardingWrapperTester.java
deleted file mode 100644
index 71d2b1a..0000000
--- a/guava-testlib/src/com/google/common/testing/ForwardingWrapperTester.java
+++ /dev/null
@@ -1,214 +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.testing;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.fail;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Function;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
-import com.google.common.reflect.AbstractInvocationHandler;
-import com.google.common.reflect.Reflection;
-
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Tester to ensure forwarding wrapper works by delegating calls to the corresponding method
- * with the same parameters forwarded and return value forwarded back or exception propagated as is.
- *
- * <p>For example: <pre> {@code
- * new ForwardingWrapperTester().testForwarding(Foo.class, new Function<Foo, Foo>() {
- * public Foo apply(Foo foo) {
- * return new ForwardingFoo(foo);
- * }
- * });}</pre>
- *
- * @author Ben Yu
- * @since 14.0
- */
-@Beta
-public final class ForwardingWrapperTester {
-
- private boolean testsEquals = false;
-
- /**
- * Asks for {@link Object#equals} and {@link Object#hashCode} to be tested.
- * That is, forwarding wrappers of equal instances should be equal.
- */
- public ForwardingWrapperTester includingEquals() {
- this.testsEquals = true;
- return this;
- }
-
- /**
- * Tests that the forwarding wrapper returned by {@code wrapperFunction} properly forwards
- * method calls with parameters passed as is, return value returned as is, and exceptions
- * propagated as is.
- */
- public <T> void testForwarding(
- Class<T> interfaceType, Function<? super T, ? extends T> wrapperFunction) {
- checkNotNull(wrapperFunction);
- checkArgument(interfaceType.isInterface(), "%s isn't an interface", interfaceType);
- Method[] methods = getMostConcreteMethods(interfaceType);
- AccessibleObject.setAccessible(methods, true);
- for (Method method : methods) {
- // The interface could be package-private or private.
- // filter out equals/hashCode/toString
- if (method.getName().equals("equals")
- && method.getParameterTypes().length == 1
- && method.getParameterTypes()[0] == Object.class) {
- continue;
- }
- if (method.getName().equals("hashCode")
- && method.getParameterTypes().length == 0) {
- continue;
- }
- if (method.getName().equals("toString")
- && method.getParameterTypes().length == 0) {
- continue;
- }
- testSuccessfulForwarding(interfaceType, method, wrapperFunction);
- testExceptionPropagation(interfaceType, method, wrapperFunction);
- }
- if (testsEquals) {
- testEquals(interfaceType, wrapperFunction);
- }
- testToString(interfaceType, wrapperFunction);
- }
-
- /** Returns the most concrete public methods from {@code type}. */
- private static Method[] getMostConcreteMethods(Class<?> type) {
- Method[] methods = type.getMethods();
- for (int i = 0; i < methods.length; i++) {
- try {
- methods[i] = type.getMethod(methods[i].getName(), methods[i].getParameterTypes());
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
- return methods;
- }
-
- private static <T> void testSuccessfulForwarding(
- Class<T> interfaceType, Method method, Function<? super T, ? extends T> wrapperFunction) {
- new InteractionTester<T>(interfaceType, method).testInteraction(wrapperFunction);
- }
-
- private static <T> void testExceptionPropagation(
- Class<T> interfaceType, Method method, Function<? super T, ? extends T> wrapperFunction) {
- final RuntimeException exception = new RuntimeException();
- T proxy = Reflection.newProxy(interfaceType, new AbstractInvocationHandler() {
- @Override protected Object handleInvocation(Object p, Method m, Object[] args)
- throws Throwable {
- throw exception;
- }
- });
- T wrapper = wrapperFunction.apply(proxy);
- try {
- method.invoke(wrapper, getParameterValues(method));
- fail(method + " failed to throw exception as is.");
- } catch (InvocationTargetException e) {
- if (exception != e.getCause()) {
- throw new RuntimeException(e);
- }
- } catch (IllegalAccessException e) {
- throw new AssertionError(e);
- }
- }
-
- private static <T> void testEquals(
- Class<T> interfaceType, Function<? super T, ? extends T> wrapperFunction) {
- FreshValueGenerator generator = new FreshValueGenerator();
- T instance = generator.newProxy(interfaceType);
- new EqualsTester()
- .addEqualityGroup(wrapperFunction.apply(instance), wrapperFunction.apply(instance))
- .addEqualityGroup(wrapperFunction.apply(generator.newProxy(interfaceType)))
- // TODO: add an overload to EqualsTester to print custom error message?
- .testEquals();
- }
-
- private static <T> void testToString(
- Class<T> interfaceType, Function<? super T, ? extends T> wrapperFunction) {
- T proxy = new FreshValueGenerator().newProxy(interfaceType);
- assertEquals("toString() isn't properly forwarded",
- proxy.toString(), wrapperFunction.apply(proxy).toString());
- }
-
- private static Object[] getParameterValues(Method method) {
- FreshValueGenerator paramValues = new FreshValueGenerator();
- final List<Object> passedArgs = Lists.newArrayList();
- for (Class<?> paramType : method.getParameterTypes()) {
- passedArgs.add(paramValues.generate(paramType));
- }
- return passedArgs.toArray();
- }
-
- /** Tests a single interaction against a method. */
- private static final class InteractionTester<T> extends AbstractInvocationHandler {
-
- private final Class<T> interfaceType;
- private final Method method;
- private final Object[] passedArgs;
- private final Object returnValue;
- private final AtomicInteger called = new AtomicInteger();
-
- InteractionTester(Class<T> interfaceType, Method method) {
- this.interfaceType = interfaceType;
- this.method = method;
- this.passedArgs = getParameterValues(method);
- this.returnValue = new FreshValueGenerator().generate(method.getReturnType());
- }
-
- @Override protected Object handleInvocation(Object p, Method calledMethod, Object[] args)
- throws Throwable {
- assertEquals(method, calledMethod);
- assertEquals(method + " invoked more than once.", 0, called.get());
- for (int i = 0; i < passedArgs.length; i++) {
- assertEquals("Parameter #" + i + " of " + method + " not forwarded",
- passedArgs[i], args[i]);
- }
- called.getAndIncrement();
- return returnValue;
- }
-
- void testInteraction(Function<? super T, ? extends T> wrapperFunction) {
- T proxy = Reflection.newProxy(interfaceType, this);
- T wrapper = wrapperFunction.apply(proxy);
- try {
- assertEquals("Return value of " + method + " not forwarded", returnValue,
- method.invoke(wrapper, passedArgs));
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw Throwables.propagate(e.getCause());
- }
- assertEquals("Failed to forward to " + method, 1, called.get());
- }
-
- @Override public String toString() {
- return "dummy " + interfaceType.getSimpleName();
- }
- }
-}
diff --git a/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java b/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java
deleted file mode 100644
index b53edae..0000000
--- a/guava-testlib/src/com/google/common/testing/FreshValueGenerator.java
+++ /dev/null
@@ -1,789 +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.testing;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.CharMatcher;
-import com.google.common.base.Charsets;
-import com.google.common.base.Equivalence;
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
-import com.google.common.base.Throwables;
-import com.google.common.base.Ticker;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.HashBiMap;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.HashMultiset;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableCollection;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableListMultimap;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.ImmutableMultiset;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSetMultimap;
-import com.google.common.collect.ImmutableSortedMap;
-import com.google.common.collect.ImmutableSortedMultiset;
-import com.google.common.collect.ImmutableSortedSet;
-import com.google.common.collect.ImmutableTable;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.LinkedHashMultimap;
-import com.google.common.collect.LinkedHashMultiset;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multiset;
-import com.google.common.collect.Ordering;
-import com.google.common.collect.RowSortedTable;
-import com.google.common.collect.SetMultimap;
-import com.google.common.collect.Sets;
-import com.google.common.collect.SortedMultiset;
-import com.google.common.collect.Table;
-import com.google.common.collect.TreeBasedTable;
-import com.google.common.collect.TreeMultiset;
-import com.google.common.primitives.UnsignedInteger;
-import com.google.common.primitives.UnsignedLong;
-import com.google.common.reflect.AbstractInvocationHandler;
-import com.google.common.reflect.Invokable;
-import com.google.common.reflect.Parameter;
-import com.google.common.reflect.Reflection;
-import com.google.common.reflect.TypeToken;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.TypeVariable;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.DoubleBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-import java.nio.LongBuffer;
-import java.nio.ShortBuffer;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Currency;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.NavigableMap;
-import java.util.NavigableSet;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.regex.Pattern;
-
-import javax.annotation.Nullable;
-
-/**
- * Generates fresh instances of types that are different from each other (if possible).
- *
- * @author Ben Yu
- */
-class FreshValueGenerator {
-
- private static final ImmutableMap<Class<?>, Method> GENERATORS;
- static {
- ImmutableMap.Builder<Class<?>, Method> builder =
- ImmutableMap.builder();
- for (Method method : FreshValueGenerator.class.getDeclaredMethods()) {
- if (method.isAnnotationPresent(Generates.class)) {
- builder.put(method.getReturnType(), method);
- }
- }
- GENERATORS = builder.build();
- }
-
- private final AtomicInteger differentiator = new AtomicInteger(1);
- private final ListMultimap<Class<?>, Object> sampleInstances = ArrayListMultimap.create();
-
- <T> void addSampleInstances(Class<T> type, Iterable<? extends T> instances) {
- sampleInstances.putAll(checkNotNull(type), checkNotNull(instances));
- }
-
- /**
- * Returns a fresh instance for {@code type} if possible. The returned instance could be:
- * <ul>
- * <li>exactly of the given type, including generic type parameters, such as
- * {@code ImmutableList<String>};
- * <li>of the raw type;
- * <li>null if no fresh value can be generated.
- * </ul>
- */
- @Nullable final <T> T generate(TypeToken<T> type) {
- // Not completely safe since sample instances are registered by raw types.
- // But we assume the generic type parameters are mostly unimportant for these dummy values,
- // because what really matters are equals/hashCode.
- @SuppressWarnings("unchecked")
- T result = (T) generateIfPossible(type);
- return result;
- }
-
- @Nullable final <T> T generate(Class<T> type) {
- return generate(TypeToken.of(type));
- }
-
- @Nullable private Object generateIfPossible(TypeToken<?> type) {
- Class<?> rawType = type.getRawType();
- List<Object> samples = sampleInstances.get(rawType);
- Object sample = nextInstance(samples, null);
- if (sample != null) {
- return sample;
- }
- if (rawType.isEnum()) {
- return nextInstance(rawType.getEnumConstants(), null);
- }
- if (type.isArray()) {
- TypeToken<?> componentType = type.getComponentType();
- Object array = Array.newInstance(componentType.getRawType(), 1);
- Array.set(array, 0, generateIfPossible(componentType));
- return array;
- }
- Method generator = GENERATORS.get(rawType);
- if (generator != null) {
- ImmutableList<Parameter> params = Invokable.from(generator).getParameters();
- List<Object> args = Lists.newArrayListWithCapacity(params.size());
- TypeVariable<?>[] typeVars = rawType.getTypeParameters();
- for (int i = 0; i < params.size(); i++) {
- TypeToken<?> paramType = type.resolveType(typeVars[i]);
- // We require all @Generates methods to either be parameter-less or accept non-null
- // fresh values for their generic parameter types.
- Object argValue = generateIfPossible(paramType);
- if (argValue == null) {
- return defaultGenerate(rawType);
- }
- args.add(argValue);
- }
- try {
- return generator.invoke(this, args.toArray());
- } catch (InvocationTargetException e) {
- Throwables.propagate(e.getCause());
- } catch (Exception e) {
- throw Throwables.propagate(e);
- }
- }
- return defaultGenerate(rawType);
- }
-
- private Object defaultGenerate(Class<?> rawType) {
- if (rawType.isInterface()) {
- // always create a new proxy
- return newProxy(rawType);
- }
- return ArbitraryInstances.get(rawType);
- }
-
- final <T> T newProxy(final Class<T> interfaceType) {
- return Reflection.newProxy(interfaceType, new FreshInvocationHandler(interfaceType));
- }
-
- private final class FreshInvocationHandler extends AbstractInvocationHandler {
- private final int identity = freshInt();
- private final Class<?> interfaceType;
-
- FreshInvocationHandler(Class<?> interfaceType) {
- this.interfaceType = interfaceType;
- }
-
- @Override protected Object handleInvocation(Object proxy, Method method, Object[] args) {
- return interfaceMethodCalled(interfaceType, method);
- }
-
- @Override public int hashCode() {
- return identity;
- }
-
- @Override public boolean equals(@Nullable Object obj) {
- if (obj instanceof FreshInvocationHandler) {
- FreshInvocationHandler that = (FreshInvocationHandler) obj;
- return identity == that.identity;
- }
- return false;
- }
-
- @Override public String toString() {
- return paramString(interfaceType, identity);
- }
- }
-
- /** Subclasses can override to provide different return value for proxied interface methods. */
- Object interfaceMethodCalled(
- @SuppressWarnings("unused") Class<?> interfaceType,
- @SuppressWarnings("unused") Method method) {
- throw new UnsupportedOperationException();
- }
-
- private <T> T nextInstance(T[] instances, T defaultValue) {
- return nextInstance(Arrays.asList(instances), defaultValue);
- }
-
- private <T> T nextInstance(Collection<T> instances, T defaultValue) {
- if (instances.isEmpty()) {
- return defaultValue;
- }
- // freshInt() is 1-based.
- return Iterables.get(instances, (freshInt() - 1) % instances.size());
- }
-
- private static String paramString(Class<?> type, int i) {
- return type.getSimpleName() + '@' + i;
- }
-
- /**
- * Annotates a method to be the instance generator of a certain type. The return type is the
- * generated type. The method parameters are non-null fresh values for each method type variable
- * in the same type variable declaration order of the return type.
- */
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- private @interface Generates {}
-
- @Generates private Class<?> freshClass() {
- return nextInstance(
- ImmutableList.of(
- int.class, long.class, void.class,
- Object.class, Object[].class, Iterable.class),
- Object.class);
- }
-
- @Generates private Object freshObject() {
- return freshString();
- }
-
- @Generates private Number freshNumber() {
- return freshInt();
- }
-
- @Generates private int freshInt() {
- return differentiator.getAndIncrement();
- }
-
- @Generates private Integer freshInteger() {
- return new Integer(freshInt());
- }
-
- @Generates private long freshLong() {
- return freshInt();
- }
-
- @Generates private Long freshLongObject() {
- return new Long(freshLong());
- }
-
- @Generates private float freshFloat() {
- return freshInt();
- }
-
- @Generates private Float freshFloatObject() {
- return new Float(freshFloat());
- }
-
- @Generates private double freshDouble() {
- return freshInt();
- }
-
- @Generates private Double freshDoubleObject() {
- return new Double(freshDouble());
- }
-
- @Generates private short freshShort() {
- return (short) freshInt();
- }
-
- @Generates private Short freshShortObject() {
- return new Short(freshShort());
- }
-
- @Generates private byte freshByte() {
- return (byte) freshInt();
- }
-
- @Generates private Byte freshByteObject() {
- return new Byte(freshByte());
- }
-
- @Generates private char freshChar() {
- return freshString().charAt(0);
- }
-
- @Generates private Character freshCharacter() {
- return new Character(freshChar());
- }
-
- @Generates private boolean freshBoolean() {
- return freshInt() % 2 == 0;
- }
-
- @Generates private Boolean freshBooleanObject() {
- return new Boolean(freshBoolean());
- }
-
- @Generates private UnsignedInteger freshUnsignedInteger() {
- return UnsignedInteger.fromIntBits(freshInt());
- }
-
- @Generates private UnsignedLong freshUnsignedLong() {
- return UnsignedLong.fromLongBits(freshLong());
- }
-
- @Generates private BigInteger freshBigInteger() {
- return BigInteger.valueOf(freshInt());
- }
-
- @Generates private BigDecimal freshBigDecimal() {
- return BigDecimal.valueOf(freshInt());
- }
-
- @Generates private CharSequence freshCharSequence() {
- return freshString();
- }
-
- @Generates private String freshString() {
- return Integer.toString(freshInt());
- }
-
- @Generates private Comparable<?> freshComparable() {
- return freshString();
- }
-
- @Generates private Pattern freshPattern() {
- return Pattern.compile(freshString());
- }
-
- @Generates private Charset freshCharset() {
- return nextInstance(Charset.availableCharsets().values(), Charsets.UTF_8);
- }
-
- @Generates private Locale freshLocale() {
- return nextInstance(Locale.getAvailableLocales(), Locale.US);
- }
-
- @Generates private Currency freshCurrency() {
- for (Set<Locale> uselessLocales = Sets.newHashSet(); ; ) {
- Locale locale = freshLocale();
- if (uselessLocales.contains(locale)) { // exhausted all locales
- return Currency.getInstance(Locale.US);
- }
- try {
- return Currency.getInstance(locale);
- } catch (IllegalArgumentException e) {
- uselessLocales.add(locale);
- }
- }
- }
-
- // common.base
- @Generates private Joiner freshJoiner() {
- return Joiner.on(freshString());
- }
-
- @Generates private Splitter freshSplitter() {
- return Splitter.on(freshString());
- }
-
- @Generates private <T> Equivalence<T> freshEquivalence() {
- return new Equivalence<T>() {
- @Override protected boolean doEquivalent(T a, T b) {
- return false;
- }
- @Override protected int doHash(T t) {
- return 0;
- }
- final String string = paramString(Equivalence.class, freshInt());
- @Override public String toString() {
- return string;
- }
- };
- }
-
- @Generates private CharMatcher freshCharMatcher() {
- return new CharMatcher() {
- @Override public boolean matches(char c) {
- return false;
- }
- final String string = paramString(CharMatcher.class, freshInt());
- @Override public String toString() {
- return string;
- }
- };
- }
-
- @Generates private Ticker freshTicker() {
- return new Ticker() {
- @Override public long read() {
- return 0;
- }
- final String string = paramString(Ticker.class, freshInt());
- @Override public String toString() {
- return string;
- }
- };
- }
-
- // collect
- @Generates private <T> Comparator<T> freshComparator() {
- return freshOrdering();
- }
-
- @Generates private <T> Ordering<T> freshOrdering() {
- return new Ordering<T>() {
- @Override public int compare(T left, T right) {
- return 0;
- }
- final String string = paramString(Ordering.class, freshInt());
- @Override public String toString() {
- return string;
- }
- };
- }
-
- @Generates static private <E> Iterable<E> freshIterable(E freshElement) {
- return freshList(freshElement);
- }
-
- @Generates static private <E> Collection<E> freshCollection(E freshElement) {
- return freshList(freshElement);
- }
-
- @Generates static private <E> List<E> freshList(E freshElement) {
- return freshArrayList(freshElement);
- }
-
- @Generates static private <E> ArrayList<E> freshArrayList(E freshElement) {
- ArrayList<E> list = Lists.newArrayList();
- list.add(freshElement);
- return list;
- }
-
- @Generates static private <E> LinkedList<E> freshLinkedList(E freshElement) {
- LinkedList<E> list = Lists.newLinkedList();
- list.add(freshElement);
- return list;
- }
-
- @Generates static private <E> ImmutableList<E> freshImmutableList(E freshElement) {
- return ImmutableList.of(freshElement);
- }
-
- @Generates static private <E> ImmutableCollection<E> freshImmutableCollection(E freshElement) {
- return freshImmutableList(freshElement);
- }
-
- @Generates static private <E> Set<E> freshSet(E freshElement) {
- return freshHashSet(freshElement);
- }
-
- @Generates static private <E> HashSet<E> freshHashSet(E freshElement) {
- return freshLinkedHashSet(freshElement);
- }
-
- @Generates static private <E> LinkedHashSet<E> freshLinkedHashSet(E freshElement) {
- LinkedHashSet<E> set = Sets.newLinkedHashSet();
- set.add(freshElement);
- return set;
- }
-
- @Generates static private <E> ImmutableSet<E> freshImmutableSet(E freshElement) {
- return ImmutableSet.of(freshElement);
- }
-
- @Generates static private <E extends Comparable<? super E>> SortedSet<E>
- freshSortedSet(E freshElement) {
- return freshNavigableSet(freshElement);
- }
-
- @Generates static private <E extends Comparable<? super E>> NavigableSet<E>
- freshNavigableSet(E freshElement) {
- return freshTreeSet(freshElement);
- }
-
- @Generates static private <E extends Comparable<? super E>> TreeSet<E> freshTreeSet(
- E freshElement) {
- TreeSet<E> set = Sets.newTreeSet();
- set.add(freshElement);
- return set;
- }
-
- @Generates static private <E extends Comparable<? super E>> ImmutableSortedSet<E>
- freshImmutableSortedSet(E freshElement) {
- return ImmutableSortedSet.of(freshElement);
- }
-
- @Generates static private <E> Multiset<E> freshMultiset(E freshElement) {
- return freshHashMultiset(freshElement);
- }
-
- @Generates static private <E> HashMultiset<E> freshHashMultiset(E freshElement) {
- HashMultiset<E> multiset = HashMultiset.create();
- multiset.add(freshElement);
- return multiset;
- }
-
- @Generates static private <E> LinkedHashMultiset<E> freshLinkedHashMultiset(E freshElement) {
- LinkedHashMultiset<E> multiset = LinkedHashMultiset.create();
- multiset.add(freshElement);
- return multiset;
- }
-
- @Generates static private <E> ImmutableMultiset<E> freshImmutableMultiset(E freshElement) {
- return ImmutableMultiset.of(freshElement);
- }
-
- @Generates static private <E extends Comparable<E>> SortedMultiset<E> freshSortedMultiset(
- E freshElement) {
- return freshTreeMultiset(freshElement);
- }
-
- @Generates static private <E extends Comparable<E>> TreeMultiset<E> freshTreeMultiset(
- E freshElement) {
- TreeMultiset<E> multiset = TreeMultiset.create();
- multiset.add(freshElement);
- return multiset;
- }
-
- @Generates static private <E extends Comparable<E>> ImmutableSortedMultiset<E>
- freshImmutableSortedMultiset(E freshElement) {
- return ImmutableSortedMultiset.of(freshElement);
- }
-
- @Generates static private <K, V> Map<K, V> freshMap(K key, V value) {
- return freshHashdMap(key, value);
- }
-
- @Generates static private <K, V> HashMap<K, V> freshHashdMap(K key, V value) {
- return freshLinkedHashMap(key, value);
- }
-
- @Generates static private <K, V> LinkedHashMap<K, V> freshLinkedHashMap(K key, V value) {
- LinkedHashMap<K, V> map = Maps.newLinkedHashMap();
- map.put(key, value);
- return map;
- }
-
- @Generates static private <K, V> ImmutableMap<K, V> freshImmutableMap(K key, V value) {
- return ImmutableMap.of(key, value);
- }
-
- @Generates static private <K, V> ConcurrentMap<K, V> freshConcurrentMap(K key, V value) {
- ConcurrentMap<K, V> map = Maps.newConcurrentMap();
- map.put(key, value);
- return map;
- }
-
- @Generates static private <K extends Comparable<? super K>, V> SortedMap<K, V>
- freshSortedMap(K key, V value) {
- return freshNavigableMap(key, value);
- }
-
- @Generates static private <K extends Comparable<? super K>, V> NavigableMap<K, V>
- freshNavigableMap(K key, V value) {
- return freshTreeMap(key, value);
- }
-
- @Generates static private <K extends Comparable<? super K>, V> TreeMap<K, V> freshTreeMap(
- K key, V value) {
- TreeMap<K, V> map = Maps.newTreeMap();
- map.put(key, value);
- return map;
- }
-
- @Generates static private <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
- freshImmutableSortedMap(K key, V value) {
- return ImmutableSortedMap.of(key, value);
- }
-
- @Generates static private <K, V> Multimap<K, V> freshMultimap(K key, V value) {
- return freshListMultimap(key, value);
- }
-
- @Generates static private <K, V> ImmutableMultimap<K, V> freshImmutableMultimap(K key, V value) {
- return ImmutableMultimap.of(key, value);
- }
-
- @Generates static private <K, V> ListMultimap<K, V> freshListMultimap(K key, V value) {
- return freshArrayListMultimap(key, value);
- }
-
- @Generates static private <K, V> ArrayListMultimap<K, V> freshArrayListMultimap(K key, V value) {
- ArrayListMultimap<K, V> multimap = ArrayListMultimap.create();
- multimap.put(key, value);
- return multimap;
- }
-
- @Generates static private <K, V> ImmutableListMultimap<K, V> freshImmutableListMultimap(
- K key, V value) {
- return ImmutableListMultimap.of(key, value);
- }
-
- @Generates static private <K, V> SetMultimap<K, V> freshSetMultimap(K key, V value) {
- return freshLinkedHashMultimap(key, value);
- }
-
- @Generates static private <K, V> HashMultimap<K, V> freshHashMultimap(K key, V value) {
- HashMultimap<K, V> multimap = HashMultimap.create();
- multimap.put(key, value);
- return multimap;
- }
-
- @Generates static private <K, V> LinkedHashMultimap<K, V> freshLinkedHashMultimap(
- K key, V value) {
- LinkedHashMultimap<K, V> multimap = LinkedHashMultimap.create();
- multimap.put(key, value);
- return multimap;
- }
-
- @Generates static private <K, V> ImmutableSetMultimap<K, V> freshImmutableSetMultimap(
- K key, V value) {
- return ImmutableSetMultimap.of(key, value);
- }
-
- @Generates static private <K, V> BiMap<K, V> freshBimap(K key, V value) {
- return freshHashBiMap(key, value);
- }
-
- @Generates static private <K, V> HashBiMap<K, V> freshHashBiMap(K key, V value) {
- HashBiMap<K, V> bimap = HashBiMap.create();
- bimap.put(key, value);
- return bimap;
- }
-
- @Generates static private <K, V> ImmutableBiMap<K, V> freshImmutableBimap(
- K key, V value) {
- return ImmutableBiMap.of(key, value);
- }
-
- @Generates static private <R, C, V> Table<R, C, V> freshTable(R row, C column, V value) {
- return freshHashBasedTable(row, column, value);
- }
-
- @Generates static private <R, C, V> HashBasedTable<R, C, V> freshHashBasedTable(
- R row, C column, V value) {
- HashBasedTable<R, C, V> table = HashBasedTable.create();
- table.put(row, column, value);
- return table;
- }
-
- @SuppressWarnings("rawtypes") // TreeBasedTable.create() is defined as such
- @Generates static private <R extends Comparable, C extends Comparable, V> RowSortedTable<R, C, V>
- freshRowSortedTable(R row, C column, V value) {
- return freshTreeBasedTable(row, column, value);
- }
-
- @SuppressWarnings("rawtypes") // TreeBasedTable.create() is defined as such
- @Generates static private <R extends Comparable, C extends Comparable, V> TreeBasedTable<R, C, V>
- freshTreeBasedTable(R row, C column, V value) {
- TreeBasedTable<R, C, V> table = TreeBasedTable.create();
- table.put(row, column, value);
- return table;
- }
-
- @Generates static private <R, C, V> ImmutableTable<R, C, V> freshImmutableTable(
- R row, C column, V value) {
- return ImmutableTable.of(row, column, value);
- }
-
- // common.reflect
- @Generates private TypeToken<?> freshTypeToken() {
- return TypeToken.of(freshClass());
- }
-
- // io types
- @Generates private File freshFile() {
- return new File(freshString());
- }
-
- @Generates private static ByteArrayInputStream freshByteArrayInputStream() {
- return new ByteArrayInputStream(new byte[0]);
- }
-
- @Generates private static InputStream freshInputStream() {
- return freshByteArrayInputStream();
- }
-
- @Generates private StringReader freshStringReader() {
- return new StringReader(freshString());
- }
-
- @Generates private Reader freshReader() {
- return freshStringReader();
- }
-
- @Generates private Readable freshReadable() {
- return freshReader();
- }
-
- @Generates private Buffer freshBuffer() {
- return freshCharBuffer();
- }
-
- @Generates private CharBuffer freshCharBuffer() {
- return CharBuffer.allocate(freshInt());
- }
-
- @Generates private ByteBuffer freshByteBuffer() {
- return ByteBuffer.allocate(freshInt());
- }
-
- @Generates private ShortBuffer freshShortBuffer() {
- return ShortBuffer.allocate(freshInt());
- }
-
- @Generates private IntBuffer freshIntBuffer() {
- return IntBuffer.allocate(freshInt());
- }
-
- @Generates private LongBuffer freshLongBuffer() {
- return LongBuffer.allocate(freshInt());
- }
-
- @Generates private FloatBuffer freshFloatBuffer() {
- return FloatBuffer.allocate(freshInt());
- }
-
- @Generates private DoubleBuffer freshDoubleBuffer() {
- return DoubleBuffer.allocate(freshInt());
- }
-}
diff --git a/guava-testlib/src/com/google/common/testing/GcFinalization.java b/guava-testlib/src/com/google/common/testing/GcFinalization.java
index 7942b09..e541793 100644
--- a/guava-testlib/src/com/google/common/testing/GcFinalization.java
+++ b/guava-testlib/src/com/google/common/testing/GcFinalization.java
@@ -57,7 +57,7 @@ import java.util.concurrent.TimeoutException;
* ...
* protected void finalize() { latch.countDown(); ... }
* };
- * x = null; // Hint to the JIT that x is stack-unreachable
+ * x = null; // Hint to the JIT that x is unreachable
* GcFinalization.await(latch);
* }</pre>
*
@@ -73,31 +73,14 @@ import java.util.concurrent.TimeoutException;
* });
* }</pre>
*
- * <p>Even if your non-test code does not use finalization, you can
- * use this class to test for leaks, by ensuring that objects are no
- * longer strongly referenced:
- *
- * <pre> {@code
- * // Helper function keeps victim stack-unreachable.
- * private WeakReference<Foo> fooWeakRef() {
- * Foo x = ....;
- * WeakReference<Foo> weakRef = new WeakReference<Foo>(x);
- * // ... use x ...
- * x = null; // Hint to the JIT that x is stack-unreachable
- * return weakRef;
- * }
- * public void testFooLeak() {
- * GcFinalization.awaitClear(fooWeakRef());
- * }}</pre>
- *
* <p>This class cannot currently be used to test soft references, since this class does not try to
* create the memory pressure required to cause soft references to be cleared.
*
* <p>This class only provides testing utilities. It is not designed for direct use in production
* or for benchmarking.
*
- * @author mike nonemacher
- * @author Martin Buchholz
+ * @author schmoe@google.com (mike nonemacher)
+ * @author martinrb@google.com (Martin Buchholz)
* @since 11.0
*/
@Beta
@@ -261,40 +244,4 @@ public final class GcFinalization {
}
});
}
-
- /**
- * Tries to perform a "full" garbage collection cycle (including processing of weak references
- * and invocation of finalize methods) and waits for it to complete. Ensures that at least one
- * weak reference has been cleared and one {@code finalize} method has been run before this
- * method returns. This method may be useful when testing the garbage collection mechanism
- * itself, or inhibiting a spontaneous GC initiation in subsequent code.
- *
- * <p>In contrast, a plain call to {@link java.lang.System#gc()} does not ensure finalization
- * processing and may run concurrently, for example, if the JVM flag {@code
- * -XX:+ExplicitGCInvokesConcurrent} is used.
- *
- * <p>Whenever possible, it is preferable to test directly for some observable change resulting
- * from GC, as with {@link #awaitClear}. Because there are no guarantees for the order of GC
- * finalization processing, there may still be some unfinished work for the GC to do after this
- * method returns.
- *
- * <p>This method does not create any memory pressure as would be required to cause soft
- * references to be processed.
- *
- * @throws RuntimeException if timed out or interrupted while waiting
- * @since 12.0
- */
- public static void awaitFullGc() {
- final CountDownLatch finalizerRan = new CountDownLatch(1);
- WeakReference<Object> ref = new WeakReference<Object>(
- new Object() {
- @Override protected void finalize() { finalizerRan.countDown(); }
- });
-
- await(finalizerRan);
- awaitClear(ref);
-
- // Hope to catch some stragglers queued up behind our finalizable object
- System.runFinalization();
- }
}
diff --git a/guava-testlib/src/com/google/common/testing/NullPointerTester.java b/guava-testlib/src/com/google/common/testing/NullPointerTester.java
index b643182..1142056 100644
--- a/guava-testlib/src/com/google/common/testing/NullPointerTester.java
+++ b/guava-testlib/src/com/google/common/testing/NullPointerTester.java
@@ -16,149 +16,146 @@
package com.google.common.testing;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.collect.ClassToInstanceMap;
-import com.google.common.collect.ImmutableList;
+import com.google.common.base.Function;
+import com.google.common.base.Functions;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import com.google.common.collect.MutableClassToInstanceMap;
-import com.google.common.reflect.Invokable;
-import com.google.common.reflect.Parameter;
-import com.google.common.reflect.Reflection;
-import com.google.common.reflect.TypeToken;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
-import java.util.concurrent.ConcurrentMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
import javax.annotation.Nullable;
/**
- * A test utility that verifies that your methods and constructors throw {@link
- * NullPointerException} or {@link UnsupportedOperationException} whenever null
- * is passed to a parameter that isn't annotated with {@link Nullable}.
- *
- * <p>The tested methods and constructors are invoked -- each time with one
- * parameter being null and the rest not null -- and the test fails if no
- * expected exception is thrown. {@code NullPointerTester} uses best effort to
- * pick non-null default values for many common JDK and Guava types, and also
- * for interfaces and public classes that have public parameter-less
- * constructors. When the non-null default value for a particular parameter type
- * cannot be provided by {@code NullPointerTester}, the caller can provide a
- * custom non-null default value for the parameter type via {@link #setDefault}.
+ * A test utility that verifies that your methods throw {@link
+ * NullPointerException} or {@link UnsupportedOperationException} whenever any
+ * of their parameters are null. To use it, you must first provide valid default
+ * values for the parameter types used by the class.
*
* @author Kevin Bourrillion
* @since 10.0
*/
@Beta
public final class NullPointerTester {
-
- private final ClassToInstanceMap<Object> defaults =
- MutableClassToInstanceMap.create();
+ private final Map<Class<?>, Object> defaults = Maps.newHashMap();
private final List<Member> ignoredMembers = Lists.newArrayList();
+ public NullPointerTester() {
+ setCommonDefaults();
+ }
+
+ private final void setCommonDefaults() {
+ setDefault(Appendable.class, new StringBuilder());
+ setDefault(CharSequence.class, "");
+ setDefault(Class.class, Class.class);
+ setDefault(Collection.class, Collections.emptySet());
+ setDefault(Comparable.class, 0);
+ setDefault(Comparator.class, Collections.reverseOrder());
+ setDefault(Function.class, Functions.identity());
+ setDefault(Integer.class, 0);
+ setDefault(Iterable.class, Collections.emptySet());
+ setDefault(Iterator.class, Iterators.emptyIterator());
+ setDefault(List.class, Collections.emptyList());
+ setDefault(Map.class, Collections.emptyMap());
+ setDefault(Object.class, new Object());
+ setDefault(Object[].class, new Object[0]);
+ setDefault(Pattern.class, Pattern.compile(""));
+ setDefault(Predicate.class, Predicates.alwaysTrue());
+ setDefault(Set.class, Collections.emptySet());
+ setDefault(SortedSet.class, new TreeSet());
+ setDefault(String.class, "");
+ setDefault(Supplier.class, Suppliers.ofInstance(1));
+ setDefault(Throwable.class, new Exception());
+ setDefault(TimeUnit.class, TimeUnit.SECONDS);
+ setDefault(int.class, 0);
+ setDefault(long.class, 0L);
+ setDefault(short.class, (short) 0);
+ setDefault(char.class, 'a');
+ setDefault(byte.class, (byte) 0);
+ setDefault(float.class, 0.0f);
+ setDefault(double.class, 0.0d);
+ setDefault(boolean.class, false);
+ }
+
/**
* Sets a default value that can be used for any parameter of type
* {@code type}. Returns this object.
*/
public <T> NullPointerTester setDefault(Class<T> type, T value) {
- defaults.putInstance(type, checkNotNull(value));
+ defaults.put(type, value);
return this;
}
/**
- * Ignore {@code method} in the tests that follow. Returns this object.
- *
- * @since 13.0
+ * Ignore a member (constructor or method) in testAllXxx methods. Returns
+ * this object.
*/
- public NullPointerTester ignore(Method method) {
- ignoredMembers.add(checkNotNull(method));
+ public NullPointerTester ignore(Member member) {
+ ignoredMembers.add(member);
return this;
}
/**
- * Runs {@link #testConstructor} on every constructor in class {@code c} that
- * has at least {@code minimalVisibility}.
+ * Runs {@link #testConstructor} on every public constructor in class {@code
+ * c}.
*/
- public void testConstructors(Class<?> c, Visibility minimalVisibility) {
+ public void testAllPublicConstructors(Class<?> c) throws Exception {
for (Constructor<?> constructor : c.getDeclaredConstructors()) {
- if (minimalVisibility.isVisible(constructor) && !isIgnored(constructor)) {
+ if (isPublic(constructor) && !isStatic(constructor)
+ && !isIgnored(constructor)) {
testConstructor(constructor);
}
}
}
/**
- * Runs {@link #testConstructor} on every public constructor in class {@code
- * c}.
- */
- public void testAllPublicConstructors(Class<?> c) {
- testConstructors(c, Visibility.PUBLIC);
- }
-
- /**
- * Runs {@link #testMethod} on every static method of class {@code c} that has
- * at least {@code minimalVisibility}, including those "inherited" from
- * superclasses of the same package.
+ * Runs {@link #testMethod} on every public static method in class
+ * {@code c}.
*/
- public void testStaticMethods(Class<?> c, Visibility minimalVisibility) {
- for (Method method : minimalVisibility.getStaticMethods(c)) {
- if (!isIgnored(method)) {
+ public void testAllPublicStaticMethods(Class<?> c) throws Exception {
+ for (Method method : c.getDeclaredMethods()) {
+ if (isPublic(method) && isStatic(method) && !isIgnored(method)) {
testMethod(null, method);
}
}
}
/**
- * Runs {@link #testMethod} on every public static method of class {@code c},
- * including those "inherited" from superclasses of the same package.
- */
- public void testAllPublicStaticMethods(Class<?> c) {
- testStaticMethods(c, Visibility.PUBLIC);
- }
-
- /**
- * Runs {@link #testMethod} on every instance method of the class of
- * {@code instance} with at least {@code minimalVisibility}, including those
- * inherited from superclasses of the same package.
+ * Runs {@link #testMethod} on every public instance method of
+ * {@code instance}.
*/
- public void testInstanceMethods(Object instance, Visibility minimalVisibility) {
- for (Method method : getInstanceMethodsToTest(instance.getClass(), minimalVisibility)) {
- testMethod(instance, method);
- }
- }
-
- ImmutableList<Method> getInstanceMethodsToTest(Class<?> c, Visibility minimalVisibility) {
- ImmutableList.Builder<Method> builder = ImmutableList.builder();
- for (Method method : minimalVisibility.getInstanceMethods(c)) {
- if (!isIgnored(method)) {
- builder.add(method);
+ public void testAllPublicInstanceMethods(Object instance) throws Exception {
+ Class<?> c = instance.getClass();
+ for (Method method : c.getDeclaredMethods()) {
+ if (isPublic(method) && !isStatic(method) && !isIgnored(method)) {
+ testMethod(instance, method);
}
}
- return builder.build();
- }
-
- /**
- * Runs {@link #testMethod} on every public instance method of the class of
- * {@code instance}, including those inherited from superclasses of the same
- * package.
- */
- public void testAllPublicInstanceMethods(Object instance) {
- testInstanceMethods(instance, Visibility.PUBLIC);
}
/**
@@ -169,7 +166,7 @@ public final class NullPointerTester {
* @param instance the instance to invoke {@code method} on, or null if
* {@code method} is static
*/
- public void testMethod(@Nullable Object instance, Method method) {
+ public void testMethod(Object instance, Method method) throws Exception {
Class<?>[] types = method.getParameterTypes();
for (int nullIndex = 0; nullIndex < types.length; nullIndex++) {
testMethodParameter(instance, method, nullIndex);
@@ -181,11 +178,7 @@ public final class NullPointerTester {
* {@link UnsupportedOperationException} whenever <i>any</i> of its
* non-{@link Nullable} parameters are null.
*/
- public void testConstructor(Constructor<?> ctor) {
- Class<?> declaringClass = ctor.getDeclaringClass();
- checkArgument(Modifier.isStatic(declaringClass.getModifiers())
- || declaringClass.getEnclosingClass() == null,
- "Cannot test constructor of non-static inner class: %s", declaringClass.getName());
+ public void testConstructor(Constructor<?> ctor) throws Exception {
Class<?>[] types = ctor.getParameterTypes();
for (int nullIndex = 0; nullIndex < types.length; nullIndex++) {
testConstructorParameter(ctor, nullIndex);
@@ -201,10 +194,25 @@ public final class NullPointerTester {
* @param instance the instance to invoke {@code method} on, or null if
* {@code method} is static
*/
- public void testMethodParameter(
- @Nullable final Object instance, final Method method, int paramIndex) {
+ public void testMethodParameter(Object instance, final Method method,
+ int paramIndex) throws Exception {
method.setAccessible(true);
- testParameter(instance, invokable(instance, method), paramIndex, method.getDeclaringClass());
+ testFunctorParameter(instance, new Functor() {
+ @Override public Class<?>[] getParameterTypes() {
+ return method.getParameterTypes();
+ }
+ @Override public Annotation[][] getParameterAnnotations() {
+ return method.getParameterAnnotations();
+ }
+ @Override public void invoke(Object instance, Object[] params)
+ throws InvocationTargetException, IllegalAccessException {
+ method.invoke(instance, params);
+ }
+ @Override public String toString() {
+ return method.getName()
+ + "(" + Arrays.toString(getParameterTypes()) + ")";
+ }
+ }, paramIndex, method.getDeclaringClass());
}
/**
@@ -213,129 +221,42 @@ public final class NullPointerTester {
* paramIndex} is null. If this parameter is marked {@link Nullable}, this
* method does nothing.
*/
- public void testConstructorParameter(Constructor<?> ctor, int paramIndex) {
+ public void testConstructorParameter(final Constructor<?> ctor,
+ int paramIndex) throws Exception {
ctor.setAccessible(true);
- testParameter(null, Invokable.from(ctor), paramIndex, ctor.getDeclaringClass());
- }
-
- /** Visibility of any method or constructor. */
- public enum Visibility {
-
- PACKAGE {
- @Override boolean isVisible(int modifiers) {
- return !Modifier.isPrivate(modifiers);
- }
- },
-
- PROTECTED {
- @Override boolean isVisible(int modifiers) {
- return Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers);
- }
- },
-
- PUBLIC {
- @Override boolean isVisible(int modifiers) {
- return Modifier.isPublic(modifiers);
- }
- };
-
- abstract boolean isVisible(int modifiers);
-
- /**
- * Returns {@code true} if {@code member} is visible under {@code this}
- * visibility.
- */
- final boolean isVisible(Member member) {
- return isVisible(member.getModifiers());
- }
-
- final Iterable<Method> getStaticMethods(Class<?> cls) {
- ImmutableList.Builder<Method> builder = ImmutableList.builder();
- for (Method method : getVisibleMethods(cls)) {
- if (Invokable.from(method).isStatic()) {
- builder.add(method);
- }
- }
- return builder.build();
- }
-
- final Iterable<Method> getInstanceMethods(Class<?> cls) {
- ConcurrentMap<Signature, Method> map = Maps.newConcurrentMap();
- for (Method method : getVisibleMethods(cls)) {
- if (!Invokable.from(method).isStatic()) {
- map.putIfAbsent(new Signature(method), method);
+ testFunctorParameter(null, new Functor() {
+ @Override public Class<?>[] getParameterTypes() {
+ return ctor.getParameterTypes();
}
- }
- return map.values();
- }
-
- private ImmutableList<Method> getVisibleMethods(Class<?> cls) {
- // Don't use cls.getPackage() because it does nasty things like reading
- // a file.
- String visiblePackage = Reflection.getPackageName(cls);
- ImmutableList.Builder<Method> builder = ImmutableList.builder();
- for (Class<?> type : TypeToken.of(cls).getTypes().classes().rawTypes()) {
- if (!Reflection.getPackageName(type).equals(visiblePackage)) {
- break;
+ @Override public Annotation[][] getParameterAnnotations() {
+ return ctor.getParameterAnnotations();
}
- for (Method method : type.getDeclaredMethods()) {
- if (!method.isSynthetic() && isVisible(method)) {
- builder.add(method);
- }
+ @Override public void invoke(Object instance, Object[] params)
+ throws InvocationTargetException, IllegalAccessException,
+ InstantiationException {
+ ctor.newInstance(params);
}
- }
- return builder.build();
- }
- }
-
- // TODO(benyu): Use labs/reflect/Signature if it graduates.
- private static final class Signature {
- private final String name;
- private final ImmutableList<Class<?>> parameterTypes;
-
- Signature(Method method) {
- this(method.getName(), ImmutableList.copyOf(method.getParameterTypes()));
- }
-
- Signature(String name, ImmutableList<Class<?>> parameterTypes) {
- this.name = name;
- this.parameterTypes = parameterTypes;
- }
-
- @Override public boolean equals(Object obj) {
- if (obj instanceof Signature) {
- Signature that = (Signature) obj;
- return name.equals(that.name)
- && parameterTypes.equals(that.parameterTypes);
- }
- return false;
- }
-
- @Override public int hashCode() {
- return Objects.hashCode(name, parameterTypes);
- }
+ }, paramIndex, ctor.getDeclaringClass());
}
/**
- * Verifies that {@code invokable} produces a {@link NullPointerException} or
+ * Verifies that {@code func} produces a {@link NullPointerException} or
* {@link UnsupportedOperationException} when the parameter in position {@code
* paramIndex} is null. If this parameter is marked {@link Nullable}, this
* method does nothing.
*
- * @param instance the instance to invoke {@code invokable} on, or null if
- * {@code invokable} is static
+ * @param instance the instance to invoke {@code func} on, or null if
+ * {@code func} is static
*/
- private void testParameter(Object instance, Invokable<?, ?> invokable,
- int paramIndex, Class<?> testedClass) {
- if (isPrimitiveOrNullable(invokable.getParameters().get(paramIndex))) {
+ private void testFunctorParameter(Object instance, Functor func,
+ int paramIndex, Class<?> testedClass) throws Exception {
+ if (parameterIsPrimitiveOrNullable(func, paramIndex)) {
return; // there's nothing to test
}
- Object[] params = buildParamList(invokable, paramIndex);
+ Object[] params = buildParamList(func, paramIndex);
try {
- @SuppressWarnings("unchecked") // We'll get a runtime exception if the type is wrong.
- Invokable<Object, ?> unsafe = (Invokable<Object, ?>) invokable;
- unsafe.invoke(instance, params);
- Assert.fail("No exception thrown from " + invokable +
+ func.invoke(instance, params);
+ Assert.fail("No exception thrown from " + func +
Arrays.toString(params) + " for " + testedClass);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
@@ -344,89 +265,54 @@ public final class NullPointerTester {
return;
}
AssertionFailedError error = new AssertionFailedError(
- "wrong exception thrown from " + invokable + ": " + cause);
+ "wrong exception thrown from " + func + ": " + cause);
error.initCause(cause);
throw error;
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
}
}
- private Object[] buildParamList(Invokable<?, ?> invokable, int indexOfParamToSetToNull) {
- ImmutableList<Parameter> params = invokable.getParameters();
- Object[] args = new Object[params.size()];
-
- for (int i = 0; i < args.length; i++) {
- Parameter param = params.get(i);
- if (i != indexOfParamToSetToNull) {
- args[i] = getDefaultValue(param.getType());
- if (!isPrimitiveOrNullable(param)) {
- Assert.assertTrue("No default value found for " + param + " of "+ invokable,
- args[i] != null);
- }
+ private static boolean parameterIsPrimitiveOrNullable(
+ Functor func, int paramIndex) {
+ if (func.getParameterTypes()[paramIndex].isPrimitive()) {
+ return true;
+ }
+ Annotation[] annotations = func.getParameterAnnotations()[paramIndex];
+ for (Annotation annotation : annotations) {
+ if (annotation instanceof Nullable) {
+ return true;
}
}
- return args;
+ return false;
}
- private <T> T getDefaultValue(TypeToken<T> type) {
- // We assume that all defaults are generics-safe, even if they aren't,
- // we take the risk.
- @SuppressWarnings("unchecked")
- T defaultValue = (T) defaults.getInstance(type.getRawType());
- if (defaultValue != null) {
- return defaultValue;
- }
- @SuppressWarnings("unchecked") // All null values are generics-safe
- T nullValue = (T) ArbitraryInstances.get(type.getRawType());
- if (nullValue != null) {
- return nullValue;
- }
- if (type.getRawType() == Class.class) {
- // If parameter is Class<? extends Foo>, we return Foo.class
- @SuppressWarnings("unchecked")
- T defaultClass = (T) getFirstTypeParameter(type.getType()).getRawType();
- return defaultClass;
- }
- if (type.getRawType() == TypeToken.class) {
- // If parameter is TypeToken<? extends Foo>, we return TypeToken<Foo>.
- @SuppressWarnings("unchecked")
- T defaultType = (T) getFirstTypeParameter(type.getType());
- return defaultType;
- }
- if (type.getRawType().isInterface()) {
- return newDefaultReturningProxy(type);
- }
- return null;
- }
+ private Object[] buildParamList(Functor func, int indexOfParamToSetToNull) {
+ Class<?>[] types = func.getParameterTypes();
+ Object[] params = new Object[types.length];
- private static TypeToken<?> getFirstTypeParameter(Type type) {
- if (type instanceof ParameterizedType) {
- return TypeToken.of(
- ((ParameterizedType) type).getActualTypeArguments()[0]);
- } else {
- return TypeToken.of(Object.class);
+ for (int i = 0; i < types.length; i++) {
+ if (i != indexOfParamToSetToNull) {
+ params[i] = defaults.get(types[i]);
+ if (!parameterIsPrimitiveOrNullable(func, i)) {
+ Assert.assertTrue("No default value found for " + types[i].getName(),
+ params[i] != null);
+ }
+ }
}
+ return params;
}
- private <T> T newDefaultReturningProxy(final TypeToken<T> type) {
- return new DummyProxy() {
- @Override <R> R dummyReturnValue(TypeToken<R> returnType) {
- return getDefaultValue(returnType);
- }
- }.newProxy(type);
+ private interface Functor {
+ Class<?>[] getParameterTypes();
+ Annotation[][] getParameterAnnotations();
+ void invoke(Object o, Object[] params) throws Exception;
}
- private static Invokable<?, ?> invokable(@Nullable Object instance, Method method) {
- if (instance == null) {
- return Invokable.from(method);
- } else {
- return TypeToken.of(instance.getClass()).method(method);
- }
+ private static boolean isPublic(Member member) {
+ return Modifier.isPublic(member.getModifiers());
}
- static boolean isPrimitiveOrNullable(Parameter param) {
- return param.getType().getRawType().isPrimitive() || param.isAnnotationPresent(Nullable.class);
+ private static boolean isStatic(Member member) {
+ return Modifier.isStatic(member.getModifiers());
}
private boolean isIgnored(Member member) {
diff --git a/guava-testlib/src/com/google/common/testing/RelationshipTester.java b/guava-testlib/src/com/google/common/testing/RelationshipTester.java
index 97d6c21..88bea63 100644
--- a/guava-testlib/src/com/google/common/testing/RelationshipTester.java
+++ b/guava-testlib/src/com/google/common/testing/RelationshipTester.java
@@ -34,24 +34,11 @@ import java.util.List;
*/
@GwtCompatible
final class RelationshipTester<T> {
-
- static class ItemReporter {
- String reportItem(Item item) {
- return item.toString();
- }
- }
-
private final List<ImmutableList<T>> groups = Lists.newArrayList();
private final RelationshipAssertion<T> assertion;
- private final ItemReporter itemReporter;
-
- RelationshipTester(RelationshipAssertion<T> assertion, ItemReporter itemReporter) {
- this.assertion = checkNotNull(assertion);
- this.itemReporter = checkNotNull(itemReporter);
- }
RelationshipTester(RelationshipAssertion<T> assertion) {
- this(assertion, new ItemReporter());
+ this.assertion = checkNotNull(assertion);
}
public RelationshipTester<T> addRelatedGroup(Iterable<? extends T> group) {
@@ -93,9 +80,8 @@ final class RelationshipTester<T> {
} catch (AssertionFailedError e) {
// TODO(gak): special handling for ComparisonFailure?
throw new AssertionFailedError(e.getMessage()
- .replace("$ITEM", itemReporter.reportItem(new Item(item, groupNumber, itemNumber)))
- .replace("$RELATED",
- itemReporter.reportItem(new Item(related, groupNumber, relatedItemNumber))));
+ .replace("$ITEM", itemString(item, groupNumber, itemNumber))
+ .replace("$RELATED", itemString(related, groupNumber, relatedItemNumber)));
}
}
@@ -108,33 +94,20 @@ final class RelationshipTester<T> {
} catch (AssertionFailedError e) {
// TODO(gak): special handling for ComparisonFailure?
throw new AssertionFailedError(e.getMessage()
- .replace("$ITEM", itemReporter.reportItem(new Item(item, groupNumber, itemNumber)))
- .replace("$UNRELATED", itemReporter.reportItem(
- new Item(unrelated, unrelatedGroupNumber, unrelatedItemNumber))));
+ .replace("$ITEM", itemString(item, groupNumber, itemNumber))
+ .replace("$UNRELATED", itemString(unrelated, unrelatedGroupNumber, unrelatedItemNumber)));
}
}
- static final class Item {
- final Object value;
- final int groupNumber;
- final int itemNumber;
-
- Item(Object value, int groupNumber, int itemNumber) {
- this.value = value;
- this.groupNumber = groupNumber;
- this.itemNumber = itemNumber;
- }
-
- @Override public String toString() {
- return new StringBuilder()
- .append(value)
- .append(" [group ")
- .append(groupNumber + 1)
- .append(", item ")
- .append(itemNumber + 1)
- .append(']')
- .toString();
- }
+ private static String itemString(Object item, int groupNumber, int itemNumber) {
+ return new StringBuilder()
+ .append(item)
+ .append(" [group ")
+ .append(groupNumber + 1)
+ .append(", item ")
+ .append(itemNumber + 1)
+ .append(']')
+ .toString();
}
/**
@@ -146,8 +119,9 @@ final class RelationshipTester<T> {
* item number and group number of the respective item.
*
*/
- static abstract class RelationshipAssertion<T> {
- abstract void assertRelated(T item, T related);
- abstract void assertUnrelated(T item, T unrelated);
+ interface RelationshipAssertion<T> {
+ void assertRelated(T item, T related);
+
+ void assertUnrelated(T item, T unrelated);
}
}
diff --git a/guava-testlib/src/com/google/common/testing/TearDown.java b/guava-testlib/src/com/google/common/testing/TearDown.java
index 68aab68..c64a4f7 100644
--- a/guava-testlib/src/com/google/common/testing/TearDown.java
+++ b/guava-testlib/src/com/google/common/testing/TearDown.java
@@ -40,7 +40,7 @@ public interface TearDown {
*
* <p>tl4j details: For backwards compatibility, {@code
* junit3.TearDownTestCase} currently does not fail a test when an exception
- * is thrown from one of its {@link TearDown} instances, but this is subject to
+ * is thrown from one of its {@link TearDown}s, but this is subject to
* change. Also, {@code junit4.TearDownTestCase} will.
*
* @throws Exception for any reason. {@code TearDownTestCase} ensures that
diff --git a/guava-testlib/src/com/google/common/testing/TearDownStack.java b/guava-testlib/src/com/google/common/testing/TearDownStack.java
index 12f0762..e579d82 100644
--- a/guava-testlib/src/com/google/common/testing/TearDownStack.java
+++ b/guava-testlib/src/com/google/common/testing/TearDownStack.java
@@ -16,8 +16,6 @@
package com.google.common.testing;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
@@ -53,7 +51,7 @@ public class TearDownStack implements TearDownAccepter {
@Override
public final void addTearDown(TearDown tearDown) {
- stack.addFirst(checkNotNull(tearDown));
+ stack.addFirst(tearDown);
}
/**
diff --git a/guava-testlib/src/com/google/common/testing/TestLogHandler.java b/guava-testlib/src/com/google/common/testing/TestLogHandler.java
index cb5bcbd..1d45554 100644
--- a/guava-testlib/src/com/google/common/testing/TestLogHandler.java
+++ b/guava-testlib/src/com/google/common/testing/TestLogHandler.java
@@ -24,8 +24,6 @@ import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
-import javax.annotation.Nullable;
-
/**
* Tests may use this to intercept messages that are logged by the code under
* test. Example:
@@ -63,15 +61,15 @@ public class TestLogHandler extends Handler {
* Adds the most recently logged record to our list.
*/
@Override
- public void publish(@Nullable LogRecord record) {
+ public void publish(LogRecord record) {
list.add(record);
}
@Override
- public void flush() {}
+ public void flush() { }
@Override
- public void close() {}
+ public void close() { }
public void clear() {
list.clear();
diff --git a/guava-testlib/src/com/google/common/testing/package-info.java b/guava-testlib/src/com/google/common/testing/package-info.java
deleted file mode 100644
index 3b2f3b3..0000000
--- a/guava-testlib/src/com/google/common/testing/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-
-/**
- * This package contains testing utilities.
- * It is a part of the open-source
- * <a href="http://guava-libraries.googlecode.com">Guava libraries</a>.
- */
-@javax.annotation.ParametersAreNonnullByDefault
-package com.google.common.testing;
diff --git a/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java b/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java
deleted file mode 100644
index 4e51d34..0000000
--- a/guava-testlib/src/com/google/common/util/concurrent/testing/TestingExecutors.java
+++ /dev/null
@@ -1,117 +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.util.concurrent.testing;
-
-import com.google.common.annotations.Beta;
-import com.google.common.collect.ImmutableList;
-import com.google.common.primitives.Longs;
-import com.google.common.util.concurrent.AbstractFuture;
-import com.google.common.util.concurrent.AbstractListeningExecutorService;
-import com.google.common.util.concurrent.ListeningScheduledExecutorService;
-
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.Delayed;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-
-/**
- * Factory methods for {@link ExecutorService} for testing.
- *
- * @author Chris Nokleberg
- * @since 14.0
- */
-@Beta
-public final class TestingExecutors {
- private TestingExecutors() {}
-
- /**
- * Returns a {@link ScheduledExecutorService} that never executes anything.
- *
- * <p>The {@code shutdownNow} method of the returned executor always returns an empty list despite
- * the fact that everything is still technically awaiting execution.
- * The {@code getDelay} method of any {@link ScheduledFuture} returned by the executor will always
- * return the max long value instead of the time until the user-specified delay.
- */
- public static ListeningScheduledExecutorService noOpScheduledExecutor() {
- return new NoOpScheduledExecutorService();
- }
-
- private static final class NoOpScheduledExecutorService
- extends AbstractListeningExecutorService implements ListeningScheduledExecutorService {
-
- private volatile boolean shutdown;
-
- @Override public void shutdown() {
- shutdown = true;
- }
-
- @Override public List<Runnable> shutdownNow() {
- shutdown();
- return ImmutableList.of();
- }
-
- @Override public boolean isShutdown() {
- return shutdown;
- }
-
- @Override public boolean isTerminated() {
- return shutdown;
- }
-
- @Override public boolean awaitTermination(long timeout, TimeUnit unit) {
- return true;
- }
-
- @Override public void execute(Runnable runnable) {}
-
- @Override public <V> ScheduledFuture<V> schedule(
- Callable<V> callable, long delay, TimeUnit unit) {
- return NeverScheduledFuture.create();
- }
-
- @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
- return NeverScheduledFuture.create();
- }
-
- @Override public ScheduledFuture<?> scheduleAtFixedRate(
- Runnable command, long initialDelay, long period, TimeUnit unit) {
- return NeverScheduledFuture.create();
- }
-
- @Override public ScheduledFuture<?> scheduleWithFixedDelay(
- Runnable command, long initialDelay, long delay, TimeUnit unit) {
- return NeverScheduledFuture.create();
- }
-
- private static class NeverScheduledFuture<V>
- extends AbstractFuture<V> implements ScheduledFuture<V> {
-
- static <V> NeverScheduledFuture<V> create() {
- return new NeverScheduledFuture<V>();
- }
-
- @Override public long getDelay(TimeUnit unit) {
- return Long.MAX_VALUE;
- }
-
- @Override public int compareTo(Delayed other) {
- return Longs.compare(getDelay(TimeUnit.NANOSECONDS), other.getDelay(TimeUnit.NANOSECONDS));
- }
- }
- }
-}