diff options
Diffstat (limited to 'test-runner/src')
7 files changed, 66 insertions, 156 deletions
diff --git a/test-runner/src/android/test/InstrumentationTestRunner.java b/test-runner/src/android/test/InstrumentationTestRunner.java index 6e5492bd751c..3f8b7a7137e8 100644 --- a/test-runner/src/android/test/InstrumentationTestRunner.java +++ b/test-runner/src/android/test/InstrumentationTestRunner.java @@ -16,8 +16,9 @@ package android.test; +import android.test.suitebuilder.annotation.MediumTest; +import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.util.Predicate; -import com.android.internal.util.Predicates; import android.app.Activity; import android.app.Instrumentation; @@ -30,7 +31,6 @@ import android.os.PerformanceCollector.PerformanceResultsWriter; import android.test.suitebuilder.TestMethod; import android.test.suitebuilder.TestPredicates; import android.test.suitebuilder.TestSuiteBuilder; -import android.test.suitebuilder.annotation.HasAnnotation; import android.test.suitebuilder.annotation.LargeTest; import android.util.Log; @@ -52,6 +52,8 @@ import junit.framework.TestSuite; import junit.runner.BaseTestRunner; import junit.textui.ResultPrinter; +import static android.test.suitebuilder.TestPredicates.hasAnnotation; + /** * An {@link Instrumentation} that runs various types of {@link junit.framework.TestCase}s against * an Android package (application). @@ -196,6 +198,12 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu /** @hide */ static final String ARGUMENT_NOT_ANNOTATION = "notAnnotation"; + private static final Predicate<TestMethod> SELECT_SMALL = hasAnnotation(SmallTest.class); + + private static final Predicate<TestMethod> SELECT_MEDIUM = hasAnnotation(MediumTest.class); + + private static final Predicate<TestMethod> SELECT_LARGE = hasAnnotation(LargeTest.class); + /** * This constant defines the maximum allowed runtime (in ms) for a test included in the "small" * suite. It is used to make an educated guess at what suite an unlabeled test belongs. @@ -464,11 +472,11 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu private Predicate<TestMethod> getSizePredicateFromArg(String sizeArg) { if (SMALL_SUITE.equals(sizeArg)) { - return TestPredicates.SELECT_SMALL; + return SELECT_SMALL; } else if (MEDIUM_SUITE.equals(sizeArg)) { - return TestPredicates.SELECT_MEDIUM; + return SELECT_MEDIUM; } else if (LARGE_SUITE.equals(sizeArg)) { - return TestPredicates.SELECT_LARGE; + return SELECT_LARGE; } else { return null; } @@ -483,7 +491,7 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu private Predicate<TestMethod> getAnnotationPredicate(String annotationClassName) { Class<? extends Annotation> annotationClass = getAnnotationClass(annotationClassName); if (annotationClass != null) { - return new HasAnnotation(annotationClass); + return hasAnnotation(annotationClass); } return null; } @@ -497,7 +505,7 @@ public class InstrumentationTestRunner extends Instrumentation implements TestSu private Predicate<TestMethod> getNotAnnotationPredicate(String annotationClassName) { Class<? extends Annotation> annotationClass = getAnnotationClass(annotationClassName); if (annotationClass != null) { - return Predicates.not(new HasAnnotation(annotationClass)); + return TestPredicates.not(hasAnnotation(annotationClass)); } return null; } diff --git a/test-runner/src/android/test/suitebuilder/AssignableFrom.java b/test-runner/src/android/test/suitebuilder/AssignableFrom.java index 38b4ee3f8c6e..84db06669cf4 100644 --- a/test-runner/src/android/test/suitebuilder/AssignableFrom.java +++ b/test-runner/src/android/test/suitebuilder/AssignableFrom.java @@ -20,9 +20,9 @@ import com.android.internal.util.Predicate; class AssignableFrom implements Predicate<TestMethod> { - private final Class root; + private final Class<?> root; - AssignableFrom(Class root) { + AssignableFrom(Class<?> root) { this.root = root; } diff --git a/test-runner/src/android/test/suitebuilder/TestPredicates.java b/test-runner/src/android/test/suitebuilder/TestPredicates.java index 47aca55f9972..616d1a972612 100644 --- a/test-runner/src/android/test/suitebuilder/TestPredicates.java +++ b/test-runner/src/android/test/suitebuilder/TestPredicates.java @@ -17,30 +17,63 @@ package android.test.suitebuilder; import android.test.InstrumentationTestCase; -import android.test.suitebuilder.annotation.HasAnnotation; -import android.test.suitebuilder.annotation.Suppress; -import android.test.suitebuilder.annotation.LargeTest; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.Smoke; +import android.test.suitebuilder.annotation.Suppress; import com.android.internal.util.Predicate; -import com.android.internal.util.Predicates; +import java.lang.annotation.Annotation; /** * {@hide} Not needed for 1.0 SDK. */ public class TestPredicates { - public static final Predicate<TestMethod> SELECT_INSTRUMENTATION = - new AssignableFrom(InstrumentationTestCase.class); - public static final Predicate<TestMethod> REJECT_INSTRUMENTATION = - Predicates.not(SELECT_INSTRUMENTATION); + static final Predicate<TestMethod> REJECT_INSTRUMENTATION = + not(new AssignableFrom(InstrumentationTestCase.class)); + + static final Predicate<TestMethod> SELECT_SMOKE = hasAnnotation(Smoke.class); + + static final Predicate<TestMethod> REJECT_SUPPRESSED = not(hasAnnotation(Suppress.class)); + + /** + * Return a predicate that checks to see if a {@link TestMethod} has an instance of the supplied + * annotation class, either on the method or on the containing class. + */ + public static Predicate<TestMethod> hasAnnotation(Class<? extends Annotation> annotationClass) { + return new HasAnnotation(annotationClass); + } + + private static class HasAnnotation implements Predicate<TestMethod> { + + private final Class<? extends Annotation> annotationClass; + + private HasAnnotation(Class<? extends Annotation> annotationClass) { + this.annotationClass = annotationClass; + } + + @Override + public boolean apply(TestMethod testMethod) { + return testMethod.getAnnotation(annotationClass) != null || + testMethod.getEnclosingClass().getAnnotation(annotationClass) != null; + } + } + + /** + * Returns a Predicate that evaluates to true iff the given Predicate + * evaluates to false. + */ + public static <T> Predicate<T> not(Predicate<? super T> predicate) { + return new NotPredicate<T>(predicate); + } + + private static class NotPredicate<T> implements Predicate<T> { + private final Predicate<? super T> predicate; - public static final Predicate<TestMethod> SELECT_SMOKE = new HasAnnotation(Smoke.class); - public static final Predicate<TestMethod> SELECT_SMALL = new HasAnnotation(SmallTest.class); - public static final Predicate<TestMethod> SELECT_MEDIUM = new HasAnnotation(MediumTest.class); - public static final Predicate<TestMethod> SELECT_LARGE = new HasAnnotation(LargeTest.class); - public static final Predicate<TestMethod> REJECT_SUPPRESSED = - Predicates.not(new HasAnnotation(Suppress.class)); + private NotPredicate(Predicate<? super T> predicate) { + this.predicate = predicate; + } + public boolean apply(T t) { + return !predicate.apply(t); + } + } } diff --git a/test-runner/src/android/test/suitebuilder/annotation/HasAnnotation.java b/test-runner/src/android/test/suitebuilder/annotation/HasAnnotation.java deleted file mode 100644 index a2868fc9e0fd..000000000000 --- a/test-runner/src/android/test/suitebuilder/annotation/HasAnnotation.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.test.suitebuilder.annotation; - -import static com.android.internal.util.Predicates.or; -import com.android.internal.util.Predicate; -import android.test.suitebuilder.TestMethod; - -import java.lang.annotation.Annotation; - -/** - * A predicate that checks to see if a {@link TestMethod} has a specific annotation, either on the - * method or on the containing class. - * - * {@hide} Not needed for 1.0 SDK. - */ -public class HasAnnotation implements Predicate<TestMethod> { - - private Predicate<TestMethod> hasMethodOrClassAnnotation; - - public HasAnnotation(Class<? extends Annotation> annotationClass) { - this.hasMethodOrClassAnnotation = or( - new HasMethodAnnotation(annotationClass), - new HasClassAnnotation(annotationClass)); - } - - public boolean apply(TestMethod testMethod) { - return hasMethodOrClassAnnotation.apply(testMethod); - } -} diff --git a/test-runner/src/android/test/suitebuilder/annotation/HasClassAnnotation.java b/test-runner/src/android/test/suitebuilder/annotation/HasClassAnnotation.java deleted file mode 100644 index ac76f4cb46fe..000000000000 --- a/test-runner/src/android/test/suitebuilder/annotation/HasClassAnnotation.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.test.suitebuilder.annotation; - -import java.lang.annotation.Annotation; - -import android.test.suitebuilder.TestMethod; -import com.android.internal.util.Predicate; - -/** - * A predicate that checks to see if a {@link android.test.suitebuilder.TestMethod} has a specific annotation on the - * containing class. Consider using the public {@link HasAnnotation} class instead of this class. - * - * {@hide} Not needed for 1.0 SDK. - */ -class HasClassAnnotation implements Predicate<TestMethod> { - - private Class<? extends Annotation> annotationClass; - - public HasClassAnnotation(Class<? extends Annotation> annotationClass) { - this.annotationClass = annotationClass; - } - - public boolean apply(TestMethod testMethod) { - return testMethod.getEnclosingClass().getAnnotation(annotationClass) != null; - } -} diff --git a/test-runner/src/android/test/suitebuilder/annotation/HasMethodAnnotation.java b/test-runner/src/android/test/suitebuilder/annotation/HasMethodAnnotation.java deleted file mode 100644 index 96bd922721ea..000000000000 --- a/test-runner/src/android/test/suitebuilder/annotation/HasMethodAnnotation.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.test.suitebuilder.annotation; - -import com.android.internal.util.Predicate; -import android.test.suitebuilder.TestMethod; - -import java.lang.annotation.Annotation; - -/** - * A predicate that checks to see if a the method represented by {@link TestMethod} has a certain - * annotation on it. Consider using the public {@link HasAnnotation} class instead of this class. - * - * {@hide} Not needed for 1.0 SDK. - */ -class HasMethodAnnotation implements Predicate<TestMethod> { - - private final Class<? extends Annotation> annotationClass; - - public HasMethodAnnotation(Class<? extends Annotation> annotationClass) { - this.annotationClass = annotationClass; - } - - public boolean apply(TestMethod testMethod) { - return testMethod.getAnnotation(annotationClass) != null; - } -} diff --git a/test-runner/src/android/test/suitebuilder/annotation/package.html b/test-runner/src/android/test/suitebuilder/annotation/package.html deleted file mode 100644 index ffba2e9bf980..000000000000 --- a/test-runner/src/android/test/suitebuilder/annotation/package.html +++ /dev/null @@ -1,5 +0,0 @@ -<HTML> -<BODY> -Utility classes supporting the test runner classes. -</BODY> -</HTML> |