diff options
author | Paul Duffin <paulduffin@google.com> | 2017-06-26 13:15:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-06-26 13:15:09 +0000 |
commit | 50826c5f2efd8e301a17db2164709c12e6ff0d06 (patch) | |
tree | d9c473bfd9195b66684505627adcffb24cd7d48a /test-runner/tests | |
parent | 834cf8d664d4955696555b7bc47dbe8d58d8164d (diff) | |
parent | fedb4b745693afba9627f8971346d5151101fb88 (diff) |
Merge "Clean up Predicate related code in android.test" into oc-dev-plus-aosp
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.java | 57 | ||||
-rw-r--r-- | test-runner/tests/src/android/test/suitebuilder/annotation/HasMethodAnnotationTest.java | 56 |
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() { - } - } -} |