diff options
Diffstat (limited to 'guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java')
-rw-r--r-- | guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java | 106 |
1 files changed, 62 insertions, 44 deletions
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 0d921a580..92c7bf285 100644 --- a/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java +++ b/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java @@ -19,11 +19,15 @@ package com.google.common.collect.testing; import static java.util.Collections.disjoint; import static java.util.logging.Level.FINER; -import com.google.common.annotations.GwtIncompatible; import com.google.common.collect.testing.features.ConflictingRequirementsException; import com.google.common.collect.testing.features.Feature; import com.google.common.collect.testing.features.FeatureUtil; import com.google.common.collect.testing.features.TesterRequirements; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -35,23 +39,23 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.logging.Logger; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; /** - * Creates, based on your criteria, a JUnit test suite that exhaustively tests the object generated - * by a G, selecting appropriate tests by matching them against specified features. + * Creates, based on your criteria, a JUnit test suite that exhaustively tests + * the object generated by a G, selecting appropriate tests by matching them + * against specified features. + * + * @param <B> The concrete type of this builder (the 'self-type'). All the + * Builder methods of this class (such as {@link #named}) return this type, so + * that Builder methods of more derived classes can be chained onto them without + * casting. + * @param <G> The type of the generator to be passed to testers in the + * generated test suite. An instance of G should somehow provide an + * instance of the class under test, plus any other information required + * to parameterize the test. * - * @param <B> The concrete type of this builder (the 'self-type'). All the Builder methods of this - * class (such as {@link #named}) return this type, so that Builder methods of more derived - * classes can be chained onto them without casting. - * @param <G> The type of the generator to be passed to testers in the generated test suite. An - * instance of G should somehow provide an instance of the class under test, plus any other - * information required to parameterize the test. * @author George van den Driessche */ -@GwtIncompatible public abstract class FeatureSpecificTestSuiteBuilder< B extends FeatureSpecificTestSuiteBuilder<B, G>, G> { @SuppressWarnings("unchecked") @@ -96,11 +100,12 @@ public abstract class FeatureSpecificTestSuiteBuilder< // Features - private Set<Feature<?>> features = new LinkedHashSet<>(); + private Set<Feature<?>> features = new LinkedHashSet<Feature<?>>(); /** - * 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. + * 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. */ public B withFeatures(Feature<?>... features) { return withFeatures(Arrays.asList(features)); @@ -124,9 +129,8 @@ public abstract class FeatureSpecificTestSuiteBuilder< /** Configures this builder produce a TestSuite with the given name. */ public B named(String name) { if (name.contains("(")) { - throw new IllegalArgumentException( - "Eclipse hides all characters after " - + "'('; please use '[]' or other characters instead of parentheses"); + throw new IllegalArgumentException("Eclipse hides all characters after " + + "'('; please use '[]' or other characters instead of parentheses"); } this.name = name; return self(); @@ -138,14 +142,15 @@ public abstract class FeatureSpecificTestSuiteBuilder< // Test suppression - private Set<Method> suppressedTests = new HashSet<>(); + private Set<Method> suppressedTests = new HashSet<Method>(); /** * Prevents the given methods from being run as part of the test suite. * - * <p><em>Note:</em> in principle this should never need to be used, but it might be useful if the - * semantics of an implementation disagree in unforeseen ways with the semantics expected by a - * test, or to keep dependent builds clean in spite of an erroneous test. + * <em>Note:</em> in principle this should never need to be used, but it + * might be useful if the semantics of an implementation disagree in + * unforeseen ways with the semantics expected by a test, or to keep dependent + * builds clean in spite of an erroneous test. */ public B suppressing(Method... methods) { return suppressing(Arrays.asList(methods)); @@ -160,10 +165,12 @@ public abstract class FeatureSpecificTestSuiteBuilder< return suppressedTests; } - private static final Logger logger = - Logger.getLogger(FeatureSpecificTestSuiteBuilder.class.getName()); + private static final Logger logger = Logger.getLogger( + FeatureSpecificTestSuiteBuilder.class.getName()); - /** Creates a runnable JUnit test suite based on the criteria already given. */ + /** + * Creates a runnable JUnit test suite based on the criteria already given. + */ /* * Class parameters must be raw. This annotation should go on testerClass in * the for loop, but the 1.5 javac crashes on annotations in for loops: @@ -185,8 +192,8 @@ public abstract class FeatureSpecificTestSuiteBuilder< TestSuite suite = new TestSuite(name); for (Class<? extends AbstractTester> testerClass : testers) { - final TestSuite testerSuite = - makeSuiteForTesterClass((Class<? extends AbstractTester<?>>) testerClass); + final TestSuite testerSuite = makeSuiteForTesterClass( + (Class<? extends AbstractTester<?>>) testerClass); if (testerSuite.countTestCases() > 0) { suite.addTest(testerSuite); } @@ -194,7 +201,10 @@ public abstract class FeatureSpecificTestSuiteBuilder< return suite; } - /** Throw {@link IllegalStateException} if {@link #createTestSuite()} can't be called yet. */ + /** + * Throw {@link IllegalStateException} if {@link #createTestSuite()} can't + * be called yet. + */ protected void checkCanCreate() { if (subjectGenerator == null) { throw new IllegalStateException("Call using() before createTestSuite()."); @@ -203,23 +213,27 @@ public abstract class FeatureSpecificTestSuiteBuilder< throw new IllegalStateException("Call named() before createTestSuite()."); } if (features == null) { - throw new IllegalStateException("Call withFeatures() before createTestSuite()."); + throw new IllegalStateException( + "Call withFeatures() before createTestSuite()."); } } // Class parameters must be raw. - protected abstract List<Class<? extends AbstractTester>> getTesters(); + protected abstract List<Class<? extends AbstractTester>> + getTesters(); private boolean matches(Test test) { final Method method; try { method = extractMethod(test); } catch (IllegalArgumentException e) { - logger.finer(Platform.format("%s: including by default: %s", test, e.getMessage())); + logger.finer(Platform.format( + "%s: including by default: %s", test, e.getMessage())); return true; } if (suppressedTests.contains(method)) { - logger.finer(Platform.format("%s: excluding because it was explicitly suppressed.", test)); + logger.finer(Platform.format( + "%s: excluding because it was explicitly suppressed.", test)); return false; } final TesterRequirements requirements; @@ -230,21 +244,23 @@ public abstract class FeatureSpecificTestSuiteBuilder< } if (!features.containsAll(requirements.getPresentFeatures())) { if (logger.isLoggable(FINER)) { - Set<Feature<?>> missingFeatures = Helpers.copyToSet(requirements.getPresentFeatures()); + Set<Feature<?>> missingFeatures = + Helpers.copyToSet(requirements.getPresentFeatures()); missingFeatures.removeAll(features); - logger.finer( - Platform.format( - "%s: skipping because these features are absent: %s", method, missingFeatures)); + logger.finer(Platform.format( + "%s: skipping because these features are absent: %s", + method, missingFeatures)); } return false; } if (intersect(features, requirements.getAbsentFeatures())) { if (logger.isLoggable(FINER)) { - Set<Feature<?>> unwantedFeatures = Helpers.copyToSet(requirements.getAbsentFeatures()); + Set<Feature<?>> unwantedFeatures = + Helpers.copyToSet(requirements.getAbsentFeatures()); unwantedFeatures.retainAll(features); - logger.finer( - Platform.format( - "%s: skipping because these features are present: %s", method, unwantedFeatures)); + logger.finer(Platform.format( + "%s: skipping because these features are present: %s", + method, unwantedFeatures)); } return false; } @@ -263,11 +279,13 @@ public abstract class FeatureSpecificTestSuiteBuilder< TestCase testCase = (TestCase) test; return Helpers.getMethod(testCase.getClass(), testCase.getName()); } else { - throw new IllegalArgumentException("unable to extract method from test: not a TestCase."); + throw new IllegalArgumentException( + "unable to extract method from test: not a TestCase."); } } - protected TestSuite makeSuiteForTesterClass(Class<? extends AbstractTester<?>> testerClass) { + protected TestSuite makeSuiteForTesterClass( + Class<? extends AbstractTester<?>> testerClass) { final TestSuite candidateTests = new TestSuite(testerClass); final TestSuite suite = filterSuite(candidateTests); @@ -297,7 +315,7 @@ public abstract class FeatureSpecificTestSuiteBuilder< } protected static String formatFeatureSet(Set<? extends Feature<?>> features) { - List<String> temp = new ArrayList<>(); + List<String> temp = new ArrayList<String>(); for (Feature<?> feature : features) { Object featureAsObject = feature; // to work around bogus JDK warning if (featureAsObject instanceof Enum) { |