diff options
9 files changed, 1 insertions, 401 deletions
diff --git a/ravenwood/TEST_MAPPING b/ravenwood/TEST_MAPPING index 691d06e0b2bf..7e2ee3e2a052 100644 --- a/ravenwood/TEST_MAPPING +++ b/ravenwood/TEST_MAPPING @@ -52,10 +52,6 @@ "host": true }, { - "name": "RavenwoodCoreTest", - "host": true - }, - { "name": "RavenwoodResApkTest", "host": true }, diff --git a/ravenwood/coretest/Android.bp b/ravenwood/coretest/Android.bp deleted file mode 100644 index a78c5c1e8227..000000000000 --- a/ravenwood/coretest/Android.bp +++ /dev/null @@ -1,23 +0,0 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_base_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_base_license"], -} - -android_ravenwood_test { - name: "RavenwoodCoreTest", - - static_libs: [ - "androidx.annotation_annotation", - "androidx.test.ext.junit", - "androidx.test.rules", - ], - srcs: [ - "test/**/*.java", - ], - sdk_version: "test_current", - auto_gen_config: true, -} diff --git a/ravenwood/coretest/README.md b/ravenwood/coretest/README.md deleted file mode 100644 index b60bfbfcb6f4..000000000000 --- a/ravenwood/coretest/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Ravenwood core test - -This test contains (non-bivalent) tests for Ravenwood itself -- e.g. tests for the ravenwood rules.
\ No newline at end of file diff --git a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/RavenwoodTestRunnerValidationTest.java b/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/RavenwoodTestRunnerValidationTest.java deleted file mode 100644 index f1e33cb686f1..000000000000 --- a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/RavenwoodTestRunnerValidationTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2024 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.ravenwoodtest.coretest; - -import android.platform.test.ravenwood.RavenwoodRule; - -import androidx.test.runner.AndroidJUnit4; // Intentionally use the deprecated one. - -import org.junit.Assume; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.RuleChain; -import org.junit.runner.RunWith; - -/** - * Test for the test runner validator in RavenwoodRule. - */ -@RunWith(AndroidJUnit4.class) -public class RavenwoodTestRunnerValidationTest { - // Note the following rules don't have a @Rule, because they need to be applied in a specific - // order. So we use a RuleChain instead. - private ExpectedException mThrown = ExpectedException.none(); - private final RavenwoodRule mRavenwood = new RavenwoodRule(); - - @Rule - public final RuleChain chain = RuleChain.outerRule(mThrown).around(mRavenwood); - - public RavenwoodTestRunnerValidationTest() { - Assume.assumeTrue(RavenwoodRule._$RavenwoodPrivate.isOptionalValidationEnabled()); - // Because RavenwoodRule will throw this error before executing the test method, - // we can't do it in the test method itself. - // So instead, we initialize it here. - mThrown.expectMessage("Switch to androidx.test.ext.junit.runners.AndroidJUnit4"); - } - - @Test - public void testValidateTestRunner() { - } -} diff --git a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail01_Test.java b/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail01_Test.java deleted file mode 100644 index db95fad2a3ad..000000000000 --- a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail01_Test.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2024 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.ravenwoodtest.coretest.methodvalidation; - -import android.platform.test.ravenwood.RavenwoodRule; - -import androidx.test.runner.AndroidJUnit4; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.RuleChain; -import org.junit.runner.RunWith; - -/** - * RavenwoodRule has a validator to ensure "test-looking" methods have valid JUnit annotations. - * This class contains tests for this validator. - */ -@RunWith(AndroidJUnit4.class) -public class RavenwoodTestMethodValidation_Fail01_Test { - private ExpectedException mThrown = ExpectedException.none(); - private final RavenwoodRule mRavenwood = new RavenwoodRule(); - - @Rule - public final RuleChain chain = RuleChain.outerRule(mThrown).around(mRavenwood); - - public RavenwoodTestMethodValidation_Fail01_Test() { - mThrown.expectMessage("Method setUp() doesn't have @Before"); - } - - @SuppressWarnings("JUnit4SetUpNotRun") - public void setUp() { - } - - @Test - public void testEmpty() { - } -} diff --git a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail02_Test.java b/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail02_Test.java deleted file mode 100644 index ddc66c73a7c0..000000000000 --- a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail02_Test.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2024 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.ravenwoodtest.coretest.methodvalidation; - -import android.platform.test.ravenwood.RavenwoodRule; - -import androidx.test.runner.AndroidJUnit4; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.RuleChain; -import org.junit.runner.RunWith; - -/** - * RavenwoodRule has a validator to ensure "test-looking" methods have valid JUnit annotations. - * This class contains tests for this validator. - */ -@RunWith(AndroidJUnit4.class) -public class RavenwoodTestMethodValidation_Fail02_Test { - private ExpectedException mThrown = ExpectedException.none(); - private final RavenwoodRule mRavenwood = new RavenwoodRule(); - - @Rule - public final RuleChain chain = RuleChain.outerRule(mThrown).around(mRavenwood); - - public RavenwoodTestMethodValidation_Fail02_Test() { - mThrown.expectMessage("Method tearDown() doesn't have @After"); - } - - @SuppressWarnings("JUnit4TearDownNotRun") - public void tearDown() { - } - - @Test - public void testEmpty() { - } -} diff --git a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail03_Test.java b/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail03_Test.java deleted file mode 100644 index ec8e907dcdb3..000000000000 --- a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_Fail03_Test.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2024 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.ravenwoodtest.coretest.methodvalidation; - -import android.platform.test.ravenwood.RavenwoodRule; - -import androidx.test.runner.AndroidJUnit4; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.RuleChain; -import org.junit.runner.RunWith; - -/** - * RavenwoodRule has a validator to ensure "test-looking" methods have valid JUnit annotations. - * This class contains tests for this validator. - */ -@RunWith(AndroidJUnit4.class) -public class RavenwoodTestMethodValidation_Fail03_Test { - private ExpectedException mThrown = ExpectedException.none(); - private final RavenwoodRule mRavenwood = new RavenwoodRule(); - - @Rule - public final RuleChain chain = RuleChain.outerRule(mThrown).around(mRavenwood); - - public RavenwoodTestMethodValidation_Fail03_Test() { - mThrown.expectMessage("Method testFoo() doesn't have @Test"); - } - - @SuppressWarnings("JUnit4TestNotRun") - public void testFoo() { - } - - @Test - public void testEmpty() { - } -} diff --git a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_OkTest.java b/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_OkTest.java deleted file mode 100644 index d952d07b3817..000000000000 --- a/ravenwood/coretest/test/com/android/ravenwoodtest/coretest/methodvalidation/RavenwoodTestMethodValidation_OkTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2024 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.ravenwoodtest.coretest.methodvalidation; - -import android.platform.test.ravenwood.RavenwoodRule; - -import androidx.test.runner.AndroidJUnit4; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * RavenwoodRule has a validator to ensure "test-looking" methods have valid JUnit annotations. - * This class contains tests for this validator. - */ -@RunWith(AndroidJUnit4.class) -public class RavenwoodTestMethodValidation_OkTest { - @Rule - public final RavenwoodRule mRavenwood = new RavenwoodRule(); - - @Before - public void setUp() { - } - - @Before - public void testSetUp() { - } - - @After - public void tearDown() { - } - - @After - public void testTearDown() { - } - - @Test - public void testEmpty() { - } -} diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java index 3ea4cb7fb69f..31be7a10403b 100644 --- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java +++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuleImpl.java @@ -18,7 +18,6 @@ package android.platform.test.ravenwood; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_RESOURCE_APK; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -39,24 +38,12 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.internal.os.RuntimeInit; import com.android.server.LocalServices; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; import org.junit.runner.Description; -import org.junit.runner.RunWith; import org.junit.runners.model.Statement; import java.io.File; import java.io.IOException; import java.io.PrintStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.Executors; @@ -243,102 +230,7 @@ public class RavenwoodRuleImpl { public static void validate(Statement base, Description description, boolean enableOptionalValidation) { - validateTestRunner(base, description, enableOptionalValidation); - validateTestAnnotations(base, description, enableOptionalValidation); - } - - private static void validateTestRunner(Statement base, Description description, - boolean shouldFail) { - final var testClass = description.getTestClass(); - final var runWith = testClass.getAnnotation(RunWith.class); - if (runWith == null) { - return; - } - - // Due to build dependencies, we can't directly refer to androidx classes here, - // so just check the class name instead. - if (runWith.value().getCanonicalName().equals("androidx.test.runner.AndroidJUnit4")) { - var message = "Test " + testClass.getCanonicalName() + " uses deprecated" - + " test runner androidx.test.runner.AndroidJUnit4." - + " Switch to androidx.test.ext.junit.runners.AndroidJUnit4."; - if (shouldFail) { - Assert.fail(message); - } else { - System.err.println("Warning: " + message); - } - } - } - - /** - * @return if a method has any of annotations. - */ - private static boolean hasAnyAnnotations(Method m, Class<? extends Annotation>... annotations) { - for (var anno : annotations) { - if (m.getAnnotation(anno) != null) { - return true; - } - } - return false; - } - - private static void validateTestAnnotations(Statement base, Description description, - boolean enableOptionalValidation) { - final var testClass = description.getTestClass(); - - final var message = new StringBuilder(); - - boolean hasErrors = false; - for (Method m : collectMethods(testClass)) { - if (Modifier.isPublic(m.getModifiers()) && m.getName().startsWith("test")) { - if (!hasAnyAnnotations(m, Test.class, Before.class, After.class, - BeforeClass.class, AfterClass.class)) { - message.append("\nMethod " + m.getName() + "() doesn't have @Test"); - hasErrors = true; - } - } - if ("setUp".equals(m.getName())) { - if (!hasAnyAnnotations(m, Before.class)) { - message.append("\nMethod " + m.getName() + "() doesn't have @Before"); - hasErrors = true; - } - if (!Modifier.isPublic(m.getModifiers())) { - message.append("\nMethod " + m.getName() + "() must be public"); - hasErrors = true; - } - } - if ("tearDown".equals(m.getName())) { - if (!hasAnyAnnotations(m, After.class)) { - message.append("\nMethod " + m.getName() + "() doesn't have @After"); - hasErrors = true; - } - if (!Modifier.isPublic(m.getModifiers())) { - message.append("\nMethod " + m.getName() + "() must be public"); - hasErrors = true; - } - } - } - assertFalse("Problem(s) detected in class " + testClass.getCanonicalName() + ":" - + message, hasErrors); - } - - /** - * Collect all (public or private or any) methods in a class, including inherited methods. - */ - private static List<Method> collectMethods(Class<?> clazz) { - var ret = new ArrayList<Method>(); - collectMethods(clazz, ret); - return ret; - } - - private static void collectMethods(Class<?> clazz, List<Method> result) { - // Class.getMethods() only return public methods, so we need to use getDeclaredMethods() - // instead, and recurse. - for (var m : clazz.getDeclaredMethods()) { - result.add(m); - } - if (clazz.getSuperclass() != null) { - collectMethods(clazz.getSuperclass(), result); - } + // Nothing to check, for now. } /** |