diff options
14 files changed, 87 insertions, 483 deletions
diff --git a/core/tests/utiltests/Android.mk b/core/tests/utiltests/Android.mk index f2e02e332bfc..233d070f9507 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-minus-junit4 \ - legacy-android-tests LOCAL_JAVA_LIBRARIES := android.test.runner diff --git a/legacy-test/Android.mk b/legacy-test/Android.mk index 8efda2ad0c20..e6839997d57e 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 index ffba2e9bf980..ffba2e9bf980 100644 --- a/test-runner/src/android/test/suitebuilder/annotation/package.html +++ b/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 fe1ff1529138..000000000000 --- 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 <T> Predicate<T> and(Predicate<? super T>... components) { - return Predicates.<T>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 <T> Predicate<T> and(Iterable<? extends Predicate<? super T>> 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 <T> Predicate<T> or(Predicate<? super T>... components) { - return Predicates.<T>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 <T> Predicate<T> or(Iterable<? extends Predicate<? super T>> components) { - return new OrPredicate(components); - } - - /** - * 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 AndPredicate<T> implements Predicate<T> { - private final Iterable<? extends Predicate<? super T>> components; - - private AndPredicate(Iterable<? extends Predicate<? super T>> components) { - this.components = components; - } - - public boolean apply(T t) { - for (Predicate<? super T> predicate : components) { - if (!predicate.apply(t)) { - return false; - } - } - return true; - } - } - - private static class OrPredicate<T> implements Predicate<T> { - private final Iterable<? extends Predicate<? super T>> components; - - private OrPredicate(Iterable<? extends Predicate<? super T>> components) { - this.components = components; - } - - public boolean apply(T t) { - for (Predicate<? super T> predicate : components) { - if (predicate.apply(t)) { - return true; - } - } - return false; - } - } - - private static class NotPredicate<T> implements Predicate<T> { - private final Predicate<? super T> predicate; - - private NotPredicate(Predicate<? super T> 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 c46ff051dd33..000000000000 --- 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<Object> TRUE = new Predicate<Object>() { - public boolean apply(Object o) { - return true; - } - }; - - private static final Predicate<Object> FALSE = new Predicate<Object>() { - 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 <E> ArrayList<E> newArrayList(E... elements) { - ArrayList<E> list = new ArrayList<E>(); - 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 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/tests/src/android/test/suitebuilder/annotation/HasAnnotationTest.java b/test-runner/tests/src/android/test/suitebuilder/TestPredicatesTest.java index edf067dce48b..3d8d5f1dc071 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<Object> TRUE = new Predicate<Object>() { + public boolean apply(Object o) { + return true; + } + }; + + private static final Predicate<Object> FALSE = new Predicate<Object>() { + 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 051ea547dbbd..000000000000 --- 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<? extends TestCase> aClass, - Class<Smoke> 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 c864e288702e..000000000000 --- 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<? extends TestCase> aClass, - String methodName, - Class<? extends Annotation> 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() { - } - } -} |