Coverage Summary for Class: SortedSetTestSuiteBuilder (com.google.common.collect.testing)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| SortedSetTestSuiteBuilder | 100% (1/1) | 100% (7/7) | 89.7% (26/29) |
1 /* 2 * Copyright (C) 2010 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; 18 19 import com.google.common.annotations.GwtIncompatible; 20 import com.google.common.collect.testing.DerivedCollectionGenerators.Bound; 21 import com.google.common.collect.testing.DerivedCollectionGenerators.SortedSetSubsetTestSetGenerator; 22 import com.google.common.collect.testing.features.CollectionFeature; 23 import com.google.common.collect.testing.features.Feature; 24 import com.google.common.collect.testing.testers.SortedSetNavigationTester; 25 import java.util.ArrayList; 26 import java.util.Collection; 27 import java.util.List; 28 import junit.framework.TestSuite; 29 30 /** 31 * Creates, based on your criteria, a JUnit test suite that exhaustively tests a SortedSet 32 * implementation. 33 */ 34 @GwtIncompatible 35 public class SortedSetTestSuiteBuilder<E> extends SetTestSuiteBuilder<E> { 36 public static <E> SortedSetTestSuiteBuilder<E> using(TestSortedSetGenerator<E> generator) { 37 SortedSetTestSuiteBuilder<E> builder = new SortedSetTestSuiteBuilder<E>(); 38 builder.usingGenerator(generator); 39 return builder; 40 } 41 42 @Override 43 protected List<Class<? extends AbstractTester>> getTesters() { 44 List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters()); 45 testers.add(SortedSetNavigationTester.class); 46 return testers; 47 } 48 49 @Override 50 public TestSuite createTestSuite() { 51 if (!getFeatures().contains(CollectionFeature.KNOWN_ORDER)) { 52 List<Feature<?>> features = Helpers.copyToList(getFeatures()); 53 features.add(CollectionFeature.KNOWN_ORDER); 54 withFeatures(features); 55 } 56 return super.createTestSuite(); 57 } 58 59 @Override 60 protected List<TestSuite> createDerivedSuites( 61 FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>> 62 parentBuilder) { 63 List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder); 64 65 if (!parentBuilder.getFeatures().contains(CollectionFeature.SUBSET_VIEW)) { 66 derivedSuites.add(createSubsetSuite(parentBuilder, Bound.NO_BOUND, Bound.EXCLUSIVE)); 67 derivedSuites.add(createSubsetSuite(parentBuilder, Bound.INCLUSIVE, Bound.NO_BOUND)); 68 derivedSuites.add(createSubsetSuite(parentBuilder, Bound.INCLUSIVE, Bound.EXCLUSIVE)); 69 } 70 71 return derivedSuites; 72 } 73 74 /** 75 * Creates a suite whose set has some elements filtered out of view. 76 * 77 * <p>Because the set may be ascending or descending, this test must derive the relative order of 78 * these extreme values rather than relying on their regular sort ordering. 79 */ 80 final TestSuite createSubsetSuite( 81 final FeatureSpecificTestSuiteBuilder< 82 ?, ? extends OneSizeTestContainerGenerator<Collection<E>, E>> 83 parentBuilder, 84 final Bound from, 85 final Bound to) { 86 final TestSortedSetGenerator<E> delegate = 87 (TestSortedSetGenerator<E>) parentBuilder.getSubjectGenerator().getInnerGenerator(); 88 89 List<Feature<?>> features = new ArrayList<>(parentBuilder.getFeatures()); 90 features.remove(CollectionFeature.ALLOWS_NULL_VALUES); 91 features.add(CollectionFeature.SUBSET_VIEW); 92 93 return newBuilderUsing(delegate, to, from) 94 .named(parentBuilder.getName() + " subSet " + from + "-" + to) 95 .withFeatures(features) 96 .suppressing(parentBuilder.getSuppressedTests()) 97 .createTestSuite(); 98 } 99 100 /** Like using() but overrideable by NavigableSetTestSuiteBuilder. */ 101 SortedSetTestSuiteBuilder<E> newBuilderUsing( 102 TestSortedSetGenerator<E> delegate, Bound to, Bound from) { 103 return using(new SortedSetSubsetTestSetGenerator<E>(delegate, to, from)); 104 } 105 }