1 /* 2 * Copyright (C) 2012 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.collect.testing.google; 18 19 import com.google.common.collect.SetMultimap; 20 import com.google.common.collect.testing.AbstractTester; 21 import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; 22 import com.google.common.collect.testing.Helpers; 23 import com.google.common.collect.testing.OneSizeTestContainerGenerator; 24 import com.google.common.collect.testing.SortedSetTestSuiteBuilder; 25 import com.google.common.collect.testing.features.CollectionSize; 26 import com.google.common.collect.testing.features.Feature; 27 28 import junit.framework.TestSuite; 29 30 import java.util.Collections; 31 import java.util.EnumSet; 32 import java.util.List; 33 import java.util.Map.Entry; 34 import java.util.Set; 35 36 /** 37 * Creates, based on your criteria, a JUnit test suite that exhaustively tests 38 * a {@code SortedSetMultimap} implementation. 39 * 40 * @author Louis Wasserman 41 */ 42 public class SortedSetMultimapTestSuiteBuilder<K, V> 43 extends MultimapTestSuiteBuilder<K, V, SetMultimap<K, V>> { 44 using( TestSetMultimapGenerator<K, V> generator)45 public static <K, V> SortedSetMultimapTestSuiteBuilder<K, V> using( 46 TestSetMultimapGenerator<K, V> generator) { 47 SortedSetMultimapTestSuiteBuilder<K, V> result = new SortedSetMultimapTestSuiteBuilder<K, V>(); 48 result.usingGenerator(generator); 49 return result; 50 } 51 getTesters()52 @Override protected List<Class<? extends AbstractTester>> getTesters() { 53 List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters()); 54 testers.add(SetMultimapAsMapTester.class); 55 testers.add(SetMultimapEqualsTester.class); 56 testers.add(SetMultimapPutTester.class); 57 testers.add(SetMultimapPutAllTester.class); 58 testers.add(SetMultimapReplaceValuesTester.class); 59 testers.add(SortedSetMultimapAsMapTester.class); 60 testers.add(SortedSetMultimapGetTester.class); 61 return testers; 62 } 63 64 @Override computeMultimapGetTestSuite( FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>> parentBuilder)65 TestSuite computeMultimapGetTestSuite( 66 FeatureSpecificTestSuiteBuilder<?, ? extends 67 OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>> parentBuilder) { 68 return SortedSetTestSuiteBuilder.using( 69 new SetMultimapTestSuiteBuilder.MultimapGetGenerator<K, V>( 70 parentBuilder.getSubjectGenerator())) 71 .withFeatures(computeMultimapGetFeatures(parentBuilder.getFeatures())) 72 .named(parentBuilder.getName() + ".get[key]") 73 .suppressing(parentBuilder.getSuppressedTests()) 74 .createTestSuite(); 75 } 76 77 @Override computeMultimapAsMapGetTestSuite( FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>> parentBuilder)78 TestSuite computeMultimapAsMapGetTestSuite( 79 FeatureSpecificTestSuiteBuilder<?, ? extends 80 OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>> parentBuilder) { 81 Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures()); 82 if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) { 83 return new TestSuite(); 84 } else { 85 return SortedSetTestSuiteBuilder.using( 86 new SetMultimapTestSuiteBuilder.MultimapAsMapGetGenerator<K, V>( 87 parentBuilder.getSubjectGenerator())) 88 .withFeatures(features) 89 .named(parentBuilder.getName() + ".asMap[].get[key]") 90 .suppressing(parentBuilder.getSuppressedTests()) 91 .createTestSuite(); 92 } 93 } 94 } 95