Coverage Summary for Class: BiMapTestSuiteBuilder (com.google.common.collect.testing.google)

Class Method, % Line, %
BiMapTestSuiteBuilder 0% (0/7) 0% (0/52)
BiMapTestSuiteBuilder$NoRecurse 0% (0/2) 0% (0/3)
Total 0% (0/9) 0% (0/55)


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.BiMap; 21 import com.google.common.collect.testing.AbstractTester; 22 import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder; 23 import com.google.common.collect.testing.MapTestSuiteBuilder; 24 import com.google.common.collect.testing.OneSizeTestContainerGenerator; 25 import com.google.common.collect.testing.PerCollectionSizeTestSuiteBuilder; 26 import com.google.common.collect.testing.SetTestSuiteBuilder; 27 import com.google.common.collect.testing.features.CollectionFeature; 28 import com.google.common.collect.testing.features.Feature; 29 import com.google.common.collect.testing.features.MapFeature; 30 import com.google.common.collect.testing.google.DerivedGoogleCollectionGenerators.BiMapValueSetGenerator; 31 import com.google.common.collect.testing.google.DerivedGoogleCollectionGenerators.InverseBiMapGenerator; 32 import com.google.common.collect.testing.google.DerivedGoogleCollectionGenerators.MapGenerator; 33 import com.google.common.collect.testing.testers.SetCreationTester; 34 import java.util.ArrayList; 35 import java.util.Collections; 36 import java.util.HashSet; 37 import java.util.List; 38 import java.util.Map.Entry; 39 import java.util.Set; 40 import junit.framework.TestSuite; 41  42 /** 43  * Creates, based on your criteria, a JUnit test suite that exhaustively tests a {@code BiMap} 44  * implementation. 45  * 46  * @author Louis Wasserman 47  */ 48 @GwtIncompatible 49 public class BiMapTestSuiteBuilder<K, V> 50  extends PerCollectionSizeTestSuiteBuilder< 51  BiMapTestSuiteBuilder<K, V>, TestBiMapGenerator<K, V>, BiMap<K, V>, Entry<K, V>> { 52  public static <K, V> BiMapTestSuiteBuilder<K, V> using(TestBiMapGenerator<K, V> generator) { 53  return new BiMapTestSuiteBuilder<K, V>().usingGenerator(generator); 54  } 55  56  @Override 57  protected List<Class<? extends AbstractTester>> getTesters() { 58  List<Class<? extends AbstractTester>> testers = new ArrayList<>(); 59  testers.add(BiMapEntrySetTester.class); 60  testers.add(BiMapPutTester.class); 61  testers.add(BiMapInverseTester.class); 62  testers.add(BiMapRemoveTester.class); 63  testers.add(BiMapClearTester.class); 64  return testers; 65  } 66  67  enum NoRecurse implements Feature<Void> { 68  INVERSE; 69  70  @Override 71  public Set<Feature<? super Void>> getImpliedFeatures() { 72  return Collections.emptySet(); 73  } 74  } 75  76  @Override 77  protected List<TestSuite> createDerivedSuites( 78  FeatureSpecificTestSuiteBuilder< 79  ?, ? extends OneSizeTestContainerGenerator<BiMap<K, V>, Entry<K, V>>> 80  parentBuilder) { 81  List<TestSuite> derived = super.createDerivedSuites(parentBuilder); 82  // TODO(cpovirk): consider using this approach (derived suites instead of extension) in 83  // ListTestSuiteBuilder, etc.? 84  derived.add( 85  MapTestSuiteBuilder.using(new MapGenerator<K, V>(parentBuilder.getSubjectGenerator())) 86  .withFeatures(parentBuilder.getFeatures()) 87  .named(parentBuilder.getName() + " [Map]") 88  .suppressing(parentBuilder.getSuppressedTests()) 89  .suppressing(SetCreationTester.class.getMethods()) 90  // BiMap.entrySet() duplicate-handling behavior is too confusing for SetCreationTester 91  .createTestSuite()); 92  /* 93  * TODO(cpovirk): the Map tests duplicate most of this effort by using a 94  * CollectionTestSuiteBuilder on values(). It would be nice to avoid that 95  */ 96  derived.add( 97  SetTestSuiteBuilder.using( 98  new BiMapValueSetGenerator<K, V>(parentBuilder.getSubjectGenerator())) 99  .withFeatures(computeValuesSetFeatures(parentBuilder.getFeatures())) 100  .named(parentBuilder.getName() + " values [Set]") 101  .suppressing(parentBuilder.getSuppressedTests()) 102  .suppressing(SetCreationTester.class.getMethods()) 103  // BiMap.values() duplicate-handling behavior is too confusing for SetCreationTester 104  .createTestSuite()); 105  if (!parentBuilder.getFeatures().contains(NoRecurse.INVERSE)) { 106  derived.add( 107  BiMapTestSuiteBuilder.using( 108  new InverseBiMapGenerator<K, V>(parentBuilder.getSubjectGenerator())) 109  .withFeatures(computeInverseFeatures(parentBuilder.getFeatures())) 110  .named(parentBuilder.getName() + " inverse") 111  .suppressing(parentBuilder.getSuppressedTests()) 112  .createTestSuite()); 113  } 114  115  return derived; 116  } 117  118  private static Set<Feature<?>> computeInverseFeatures(Set<Feature<?>> mapFeatures) { 119  Set<Feature<?>> inverseFeatures = new HashSet<>(mapFeatures); 120  121  boolean nullKeys = inverseFeatures.remove(MapFeature.ALLOWS_NULL_KEYS); 122  boolean nullValues = inverseFeatures.remove(MapFeature.ALLOWS_NULL_VALUES); 123  124  if (nullKeys) { 125  inverseFeatures.add(MapFeature.ALLOWS_NULL_VALUES); 126  } 127  if (nullValues) { 128  inverseFeatures.add(MapFeature.ALLOWS_NULL_KEYS); 129  } 130  131  inverseFeatures.add(NoRecurse.INVERSE); 132  inverseFeatures.remove(CollectionFeature.KNOWN_ORDER); 133  inverseFeatures.add(MapFeature.REJECTS_DUPLICATES_AT_CREATION); 134  135  return inverseFeatures; 136  } 137  138  // TODO(lowasser): can we eliminate the duplication from MapTestSuiteBuilder here? 139  140  private static Set<Feature<?>> computeValuesSetFeatures(Set<Feature<?>> mapFeatures) { 141  Set<Feature<?>> valuesCollectionFeatures = computeCommonDerivedCollectionFeatures(mapFeatures); 142  valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES); 143  144  if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) { 145  valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES); 146  } 147  148  valuesCollectionFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION); 149  150  return valuesCollectionFeatures; 151  } 152  153  private static Set<Feature<?>> computeCommonDerivedCollectionFeatures( 154  Set<Feature<?>> mapFeatures) { 155  return MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures); 156  } 157 }