View Javadoc
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.annotations.GwtIncompatible;
20  import com.google.common.collect.SetMultimap;
21  import com.google.common.collect.testing.AbstractTester;
22  import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
23  import com.google.common.collect.testing.Helpers;
24  import com.google.common.collect.testing.OneSizeTestContainerGenerator;
25  import com.google.common.collect.testing.SortedSetTestSuiteBuilder;
26  import com.google.common.collect.testing.features.CollectionSize;
27  import com.google.common.collect.testing.features.Feature;
28  import java.util.Collections;
29  import java.util.EnumSet;
30  import java.util.List;
31  import java.util.Map.Entry;
32  import java.util.Set;
33  import junit.framework.TestSuite;
34  
35  /**
36   * Creates, based on your criteria, a JUnit test suite that exhaustively tests
37   * a {@code SortedSetMultimap} implementation.
38   *
39   * @author Louis Wasserman
40   */
41  @GwtIncompatible
42  public class SortedSetMultimapTestSuiteBuilder<K, V>
43      extends MultimapTestSuiteBuilder<K, V, SetMultimap<K, V>> {
44  
45    public static <K, V> SortedSetMultimapTestSuiteBuilder<K, V> using(
46        TestSetMultimapGenerator<K, V> generator) {
47      SortedSetMultimapTestSuiteBuilder<K, V> result = new SortedSetMultimapTestSuiteBuilder<>();
48      result.usingGenerator(generator);
49      return result;
50    }
51  
52    @Override
53    protected List<Class<? extends AbstractTester>> getTesters() {
54      List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
55      testers.add(SetMultimapAsMapTester.class);
56      testers.add(SetMultimapEqualsTester.class);
57      testers.add(SetMultimapPutTester.class);
58      testers.add(SetMultimapPutAllTester.class);
59      testers.add(SetMultimapReplaceValuesTester.class);
60      testers.add(SortedSetMultimapAsMapTester.class);
61      testers.add(SortedSetMultimapGetTester.class);
62      return testers;
63    }
64  
65    @Override
66    TestSuite computeMultimapGetTestSuite(
67        FeatureSpecificTestSuiteBuilder<
68                ?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>>
69            parentBuilder) {
70      return SortedSetTestSuiteBuilder.using(
71              new SetMultimapTestSuiteBuilder.MultimapGetGenerator<K, V>(
72                  parentBuilder.getSubjectGenerator()))
73          .withFeatures(computeMultimapGetFeatures(parentBuilder.getFeatures()))
74          .named(parentBuilder.getName() + ".get[key]")
75          .suppressing(parentBuilder.getSuppressedTests())
76          .createTestSuite();
77    }
78  
79    @Override
80    TestSuite computeMultimapAsMapGetTestSuite(
81        FeatureSpecificTestSuiteBuilder<
82                ?, ? extends OneSizeTestContainerGenerator<SetMultimap<K, V>, Entry<K, V>>>
83            parentBuilder) {
84      Set<Feature<?>> features = computeMultimapAsMapGetFeatures(parentBuilder.getFeatures());
85      if (Collections.disjoint(features, EnumSet.allOf(CollectionSize.class))) {
86        return new TestSuite();
87      } else {
88        return SortedSetTestSuiteBuilder.using(
89                new SetMultimapTestSuiteBuilder.MultimapAsMapGetGenerator<K, V>(
90                    parentBuilder.getSubjectGenerator()))
91            .withFeatures(features)
92            .named(parentBuilder.getName() + ".asMap[].get[key]")
93            .suppressing(parentBuilder.getSuppressedTests())
94            .createTestSuite();
95      }
96    }
97  }