summaryrefslogtreecommitdiff
path: root/test-runner/tests
diff options
context:
space:
mode:
authorPaul Duffin <paulduffin@google.com>2017-06-22 10:47:25 +0100
committerPaul Duffin <paulduffin@google.com>2017-06-22 15:48:44 +0100
commitfedb4b745693afba9627f8971346d5151101fb88 (patch)
tree73d4ab78b4a0877817f19ff34b60dbff9ddc9e0d /test-runner/tests
parente211119fea8e01e573ecde57ced2e9bf8dfbf65e (diff)
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
Diffstat (limited to 'test-runner/tests')
-rw-r--r--test-runner/tests/src/android/test/suitebuilder/TestPredicatesTest.java (renamed from test-runner/tests/src/android/test/suitebuilder/annotation/HasAnnotationTest.java)25
-rw-r--r--test-runner/tests/src/android/test/suitebuilder/annotation/HasClassAnnotationTest.java57
-rw-r--r--test-runner/tests/src/android/test/suitebuilder/annotation/HasMethodAnnotationTest.java56
3 files changed, 21 insertions, 117 deletions
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() {
- }
- }
-}