From 2a4d009ee15f0d620e273879feba74d3db28cbab Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 22 Jun 2017 10:47:25 +0100 Subject: [PATCH] Clean up Predicate related code in android.test Part of the work of removing JUnit and dependent android.test classes from the Android API involves providing a static library that developers can include in their test applications to ease migration. That library will be built directly from the source (as opposed to android.jar which is built from stubs) and so developers will be able to see classes and methods that are not present in the stubs. This change is one of a number of similar changes that cleanup the existing non-API code in order to minimize the additional methods and classes exposed externally. The basic approach is to remove unused classes and methods, use least visible access modifier possible and generally minimize the amount of publicly visible code. The HasClassAnnotation and HasMethodAnnotation were never used separately and only used by HasAnnotation. This merges the functionality into a single nested class in TestPredicates, hidden behind the new TestPredicates.hasAnnotation(). The HasAnnotationTest was renamed as TestPredicatesTest and the HasClassAnnotationTest and HasMethodAnnotationTest classes were removed as their tests provide no additional coverage. The removal of the Has*Annotation.java files means that the test-runner/src/android/test/suitebuilder/annotation/ directory is empty apart from the package.html file so that was moved to legacy-test to sit alongside the actual annotation classes. The Predicates class, while part of the legacy-test module was only ever used by the test-runner module and only its not() method was actually used. So, the not() method and associated nested class were moved to TestPredicates, the tests for not() were moved to TestPredicatesTest and the Predicates* classes were removed. That allowed for the removal of the legacy-android-tests as that is now empty. TestPredicates has a number of constants that were public. They were hidden by moving them to the class that actually used them. A minor generic issue was fixed in AssignableFrom. Bug: 30188076 Test: make checkbuild and run FrameworkTestRunnerTests Change-Id: I861da388a4146bb28e1e480d1b7ba9137b7b270e --- core/tests/utiltests/Android.mk | 1 - legacy-test/Android.mk | 13 -- .../test/suitebuilder/annotation/package.html | 0 .../com/android/internal/util/Predicates.java | 127 ------------------ .../android/internal/util/PredicatesTest.java | 74 ---------- .../test/InstrumentationTestRunner.java | 22 ++- .../test/suitebuilder/AssignableFrom.java | 4 +- .../test/suitebuilder/TestPredicates.java | 65 ++++++--- .../annotation/HasAnnotation.java | 44 ------ .../annotation/HasClassAnnotation.java | 41 ------ .../annotation/HasMethodAnnotation.java | 41 ------ ...ationTest.java => TestPredicatesTest.java} | 25 +++- .../annotation/HasClassAnnotationTest.java | 57 -------- .../annotation/HasMethodAnnotationTest.java | 56 -------- 14 files changed, 87 insertions(+), 483 deletions(-) rename {test-runner => legacy-test}/src/android/test/suitebuilder/annotation/package.html (100%) delete mode 100644 legacy-test/src/com/android/internal/util/Predicates.java delete mode 100644 legacy-test/tests/com/android/internal/util/PredicatesTest.java delete mode 100644 test-runner/src/android/test/suitebuilder/annotation/HasAnnotation.java delete mode 100644 test-runner/src/android/test/suitebuilder/annotation/HasClassAnnotation.java delete mode 100644 test-runner/src/android/test/suitebuilder/annotation/HasMethodAnnotation.java rename test-runner/tests/src/android/test/suitebuilder/{annotation/HasAnnotationTest.java => TestPredicatesTest.java} (76%) delete mode 100644 test-runner/tests/src/android/test/suitebuilder/annotation/HasClassAnnotationTest.java delete mode 100644 test-runner/tests/src/android/test/suitebuilder/annotation/HasMethodAnnotationTest.java diff --git a/core/tests/utiltests/Android.mk b/core/tests/utiltests/Android.mk index e69a2cc53f205..853d78b29bd7c 100644 --- a/core/tests/utiltests/Android.mk +++ b/core/tests/utiltests/Android.mk @@ -18,7 +18,6 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ android-support-test \ frameworks-base-testutils \ mockito-target \ - legacy-android-tests LOCAL_JAVA_LIBRARIES := android.test.runner diff --git a/legacy-test/Android.mk b/legacy-test/Android.mk index 8efda2ad0c203..e6839997d57e5 100644 --- a/legacy-test/Android.mk +++ b/legacy-test/Android.mk @@ -48,19 +48,6 @@ LOCAL_JAVA_LIBRARIES := core-oj core-libart framework junit include $(BUILD_STATIC_JAVA_LIBRARY) -# Build the legacy-android-tests library -# ====================================== -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := \ - $(call all-java-files-under, tests) -LOCAL_MODULE := legacy-android-tests -LOCAL_NO_STANDARD_LIBRARIES := true -LOCAL_JAVA_LIBRARIES := core-oj core-libart framework junit -LOCAL_STATIC_JAVA_LIBRARIES := legacy-android-test - -include $(BUILD_STATIC_JAVA_LIBRARY) - ifeq ($(HOST_OS),linux) # Build the legacy-performance-test-hostdex library # ================================================= diff --git a/test-runner/src/android/test/suitebuilder/annotation/package.html b/legacy-test/src/android/test/suitebuilder/annotation/package.html similarity index 100% rename from test-runner/src/android/test/suitebuilder/annotation/package.html rename to legacy-test/src/android/test/suitebuilder/annotation/package.html diff --git a/legacy-test/src/com/android/internal/util/Predicates.java b/legacy-test/src/com/android/internal/util/Predicates.java deleted file mode 100644 index fe1ff1529138f..0000000000000 --- a/legacy-test/src/com/android/internal/util/Predicates.java +++ /dev/null @@ -1,127 +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 com.android.internal.util; - -import java.util.Arrays; - -/** - * Predicates contains static methods for creating the standard set of - * {@code Predicate} objects. - * - * @hide - */ -public class Predicates { - - private Predicates() { - } - - /** - * Returns a Predicate that evaluates to true iff each of its components - * evaluates to true. The components are evaluated in order, and evaluation - * will be "short-circuited" as soon as the answer is determined. - */ - public static Predicate and(Predicate... components) { - return Predicates.and(Arrays.asList(components)); - } - - /** - * Returns a Predicate that evaluates to true iff each of its components - * evaluates to true. The components are evaluated in order, and evaluation - * will be "short-circuited" as soon as the answer is determined. Does not - * defensively copy the iterable passed in, so future changes to it will alter - * the behavior of this Predicate. If components is empty, the returned - * Predicate will always evaluate to true. - */ - public static Predicate and(Iterable> components) { - return new AndPredicate(components); - } - - /** - * Returns a Predicate that evaluates to true iff any one of its components - * evaluates to true. The components are evaluated in order, and evaluation - * will be "short-circuited" as soon as the answer is determined. - */ - public static Predicate or(Predicate... components) { - return Predicates.or(Arrays.asList(components)); - } - - /** - * Returns a Predicate that evaluates to true iff any one of its components - * evaluates to true. The components are evaluated in order, and evaluation - * will be "short-circuited" as soon as the answer is determined. Does not - * defensively copy the iterable passed in, so future changes to it will alter - * the behavior of this Predicate. If components is empty, the returned - * Predicate will always evaluate to false. - */ - public static Predicate or(Iterable> components) { - return new OrPredicate(components); - } - - /** - * Returns a Predicate that evaluates to true iff the given Predicate - * evaluates to false. - */ - public static Predicate not(Predicate predicate) { - return new NotPredicate(predicate); - } - - private static class AndPredicate implements Predicate { - private final Iterable> components; - - private AndPredicate(Iterable> components) { - this.components = components; - } - - public boolean apply(T t) { - for (Predicate predicate : components) { - if (!predicate.apply(t)) { - return false; - } - } - return true; - } - } - - private static class OrPredicate implements Predicate { - private final Iterable> components; - - private OrPredicate(Iterable> components) { - this.components = components; - } - - public boolean apply(T t) { - for (Predicate predicate : components) { - if (predicate.apply(t)) { - return true; - } - } - return false; - } - } - - private static class NotPredicate implements Predicate { - private final Predicate predicate; - - private NotPredicate(Predicate predicate) { - this.predicate = predicate; - } - - public boolean apply(T t) { - return !predicate.apply(t); - } - } -} diff --git a/legacy-test/tests/com/android/internal/util/PredicatesTest.java b/legacy-test/tests/com/android/internal/util/PredicatesTest.java deleted file mode 100644 index c46ff051dd335..0000000000000 --- a/legacy-test/tests/com/android/internal/util/PredicatesTest.java +++ /dev/null @@ -1,74 +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 com.android.internal.util; - -import junit.framework.TestCase; - -import java.util.ArrayList; -import java.util.Collections; - -public class PredicatesTest extends TestCase { - - private static final Predicate TRUE = new Predicate() { - public boolean apply(Object o) { - return true; - } - }; - - private static final Predicate FALSE = new Predicate() { - public boolean apply(Object o) { - return false; - } - }; - - public void testAndPredicate_AllConditionsTrue() throws Exception { - assertTrue(Predicates.and(newArrayList(TRUE)).apply(null)); - assertTrue(Predicates.and(newArrayList(TRUE, TRUE)).apply(null)); - } - - public void testAndPredicate_AtLeastOneConditionIsFalse() throws Exception { - assertFalse(Predicates.and(newArrayList(FALSE, TRUE, TRUE)).apply(null)); - assertFalse(Predicates.and(newArrayList(TRUE, FALSE, TRUE)).apply(null)); - assertFalse(Predicates.and(newArrayList(TRUE, TRUE, FALSE)).apply(null)); - } - - public void testOrPredicate_AllConditionsTrue() throws Exception { - assertTrue(Predicates.or(newArrayList(TRUE, TRUE, TRUE)).apply(null)); - } - - public void testOrPredicate_AllConditionsFalse() throws Exception { - assertFalse(Predicates.or(newArrayList(FALSE, FALSE, FALSE)).apply(null)); - } - - public void testOrPredicate_AtLeastOneConditionIsTrue() throws Exception { - assertTrue(Predicates.or(newArrayList(TRUE, FALSE, FALSE)).apply(null)); - assertTrue(Predicates.or(newArrayList(FALSE, TRUE, FALSE)).apply(null)); - assertTrue(Predicates.or(newArrayList(FALSE, FALSE, TRUE)).apply(null)); - } - - public void testNotPredicate() throws Exception { - assertTrue(Predicates.not(FALSE).apply(null)); - assertFalse(Predicates.not(TRUE).apply(null)); - } - - private static ArrayList newArrayList(E... elements) { - ArrayList list = new ArrayList(); - Collections.addAll(list, elements); - return list; - } - -} diff --git a/test-runner/src/android/test/InstrumentationTestRunner.java b/test-runner/src/android/test/InstrumentationTestRunner.java index 6e5492bd751c1..3f8b7a7137e8e 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 SELECT_SMALL = hasAnnotation(SmallTest.class); + + private static final Predicate SELECT_MEDIUM = hasAnnotation(MediumTest.class); + + private static final Predicate 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 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 getAnnotationPredicate(String annotationClassName) { Class 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 getNotAnnotationPredicate(String annotationClassName) { Class 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 38b4ee3f8c6e4..84db06669cf44 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 { - 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 47aca55f99729..616d1a9726121 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 SELECT_INSTRUMENTATION = - new AssignableFrom(InstrumentationTestCase.class); - public static final Predicate REJECT_INSTRUMENTATION = - Predicates.not(SELECT_INSTRUMENTATION); + static final Predicate REJECT_INSTRUMENTATION = + not(new AssignableFrom(InstrumentationTestCase.class)); - public static final Predicate SELECT_SMOKE = new HasAnnotation(Smoke.class); - public static final Predicate SELECT_SMALL = new HasAnnotation(SmallTest.class); - public static final Predicate SELECT_MEDIUM = new HasAnnotation(MediumTest.class); - public static final Predicate SELECT_LARGE = new HasAnnotation(LargeTest.class); - public static final Predicate REJECT_SUPPRESSED = - Predicates.not(new HasAnnotation(Suppress.class)); + static final Predicate SELECT_SMOKE = hasAnnotation(Smoke.class); + static final Predicate 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 hasAnnotation(Class annotationClass) { + return new HasAnnotation(annotationClass); + } + + private static class HasAnnotation implements Predicate { + + private final Class annotationClass; + + private HasAnnotation(Class 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 Predicate not(Predicate predicate) { + return new NotPredicate(predicate); + } + + private static class NotPredicate implements Predicate { + private final Predicate predicate; + + private NotPredicate(Predicate 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 a2868fc9e0fd2..0000000000000 --- 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 { - - private Predicate hasMethodOrClassAnnotation; - - public HasAnnotation(Class 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 ac76f4cb46fe2..0000000000000 --- 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 { - - private Class annotationClass; - - public HasClassAnnotation(Class 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 96bd922721ea5..0000000000000 --- 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 { - - private final Class annotationClass; - - public HasMethodAnnotation(Class annotationClass) { - this.annotationClass = annotationClass; - } - - public boolean apply(TestMethod testMethod) { - return testMethod.getAnnotation(annotationClass) != null; - } -} diff --git a/test-runner/tests/src/android/test/suitebuilder/annotation/HasAnnotationTest.java b/test-runner/tests/src/android/test/suitebuilder/TestPredicatesTest.java similarity index 76% rename from test-runner/tests/src/android/test/suitebuilder/annotation/HasAnnotationTest.java rename to test-runner/tests/src/android/test/suitebuilder/TestPredicatesTest.java index edf067dce48b2..3d8d5f1dc0712 100644 --- a/test-runner/tests/src/android/test/suitebuilder/annotation/HasAnnotationTest.java +++ b/test-runner/tests/src/android/test/suitebuilder/TestPredicatesTest.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package android.test.suitebuilder.annotation; +package android.test.suitebuilder; -import android.test.suitebuilder.TestMethod; +import com.android.internal.util.Predicate; import junit.framework.TestCase; import java.lang.annotation.ElementType; @@ -25,7 +25,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; -public class HasAnnotationTest extends TestCase { +public class TestPredicatesTest extends TestCase { public void testThatMethodWithAnnotationIsReportedAsBeingAnnotated() throws Exception { assertTrue(hasExampleAnnotation(ClassWithAnnotation.class, "testWithAnnotation")); @@ -45,7 +45,7 @@ public class HasAnnotationTest extends TestCase { throws NoSuchMethodException { Method method = aClass.getMethod(methodName); TestMethod testMethod = new TestMethod(method, aClass); - return new HasAnnotation(Example.class).apply(testMethod); + return TestPredicates.hasAnnotation(Example.class).apply(testMethod); } @Retention(RetentionPolicy.RUNTIME) @@ -73,4 +73,21 @@ public class HasAnnotationTest extends TestCase { public void testWithoutAnnotation() { } } + + private static final Predicate TRUE = new Predicate() { + public boolean apply(Object o) { + return true; + } + }; + + private static final Predicate FALSE = new Predicate() { + public boolean apply(Object o) { + return false; + } + }; + + public void testNotPredicate() throws Exception { + assertTrue(TestPredicates.not(FALSE).apply(null)); + assertFalse(TestPredicates.not(TRUE).apply(null)); + } } diff --git a/test-runner/tests/src/android/test/suitebuilder/annotation/HasClassAnnotationTest.java b/test-runner/tests/src/android/test/suitebuilder/annotation/HasClassAnnotationTest.java deleted file mode 100644 index 051ea547dbbd0..0000000000000 --- a/test-runner/tests/src/android/test/suitebuilder/annotation/HasClassAnnotationTest.java +++ /dev/null @@ -1,57 +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 android.test.suitebuilder.TestMethod; -import junit.framework.TestCase; - -import java.lang.reflect.Method; - -public class HasClassAnnotationTest extends TestCase { - - public void testShouldTellIfParentClassHasSpecifiedClassification() - throws NoSuchMethodException { - assertTrue(classHasAnnotation(SmokeTestExample.class, Smoke.class)); - } - - public void testShouldTellIfParentClassDoesNotHaveSpecifiedClassification() - throws NoSuchMethodException { - assertFalse(classHasAnnotation(NonSmokeTestExample.class, Smoke.class)); - } - - private boolean classHasAnnotation( - Class aClass, - Class expectedClassification) throws NoSuchMethodException { - Method method = aClass.getMethod("testSomeTest"); - - TestMethod testMethod = new TestMethod(method, aClass); - return new HasClassAnnotation(expectedClassification).apply(testMethod); - } - - @Smoke - static class SmokeTestExample extends TestCase { - - public void testSomeTest() { - } - } - - static class NonSmokeTestExample extends TestCase { - - public void testSomeTest() { - } - } -} diff --git a/test-runner/tests/src/android/test/suitebuilder/annotation/HasMethodAnnotationTest.java b/test-runner/tests/src/android/test/suitebuilder/annotation/HasMethodAnnotationTest.java deleted file mode 100644 index c864e288702eb..0000000000000 --- a/test-runner/tests/src/android/test/suitebuilder/annotation/HasMethodAnnotationTest.java +++ /dev/null @@ -1,56 +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 android.test.suitebuilder.TestMethod; -import junit.framework.TestCase; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; - - -public class HasMethodAnnotationTest extends TestCase { - - public void testMethodWithSpecifiedAttribute() throws Exception { - assertTrue(methodHasAnnotation(AnnotatedMethodExample.class, - "testThatIsAnnotated", Smoke.class)); - } - - public void testMethodWithoutSpecifiedAttribute() throws Exception { - assertFalse(methodHasAnnotation(AnnotatedMethodExample.class, - "testThatIsNotAnnotated", Smoke.class)); - } - - private boolean methodHasAnnotation(Class aClass, - String methodName, - Class expectedClassification - ) throws NoSuchMethodException { - Method method = aClass.getMethod(methodName); - TestMethod testMethod = new TestMethod(method, aClass); - return new HasMethodAnnotation(expectedClassification).apply(testMethod); - } - - static class AnnotatedMethodExample extends TestCase { - - @Smoke - public void testThatIsAnnotated() { - } - - public void testThatIsNotAnnotated() { - } - } -}