diff options
| author | 2024-11-22 23:26:15 +0000 | |
|---|---|---|
| committer | 2024-11-22 23:26:15 +0000 | |
| commit | c7dd11a00fb0db5afa654f77665f124055ce6fd1 (patch) | |
| tree | 95127b8a80a45a7907c391248f3d1f225f4cf466 | |
| parent | e15c785b9b4131858df5384ffaf18e466b0ce21d (diff) | |
| parent | 558cd71f0f6ec8f1af5d49fd9c208411f7b77615 (diff) | |
Merge "[Ravenwood] Fully remove RavenwoodConfig support" into main am: 558cd71f0f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3370507
Change-Id: Iab1df31f9aa43905accfacf70fe9343b98bd1e1c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
6 files changed, 106 insertions, 721 deletions
| diff --git a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRunnerState.java b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRunnerState.java index 4ab1fa1579e1..110de989b524 100644 --- a/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRunnerState.java +++ b/ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRunnerState.java @@ -15,22 +15,10 @@   */  package android.platform.test.ravenwood; -import static com.android.ravenwood.common.RavenwoodCommonUtils.ensureIsPublicMember; - -import static org.junit.Assert.fail; - -import android.annotation.Nullable;  import android.util.Log; -import com.android.ravenwood.common.RavenwoodRuntimeException; - -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.rules.TestRule;  import org.junit.runner.Description; -import java.lang.reflect.Field; -  /**   * Used to store various states associated with the current test runner that's inly needed   * in junit-impl. @@ -52,30 +40,10 @@ public final class RavenwoodRunnerState {          mRunner = runner;      } -    /** -     * The RavenwoodConfig declared in the test class -     */ -    private RavenwoodConfig mConfig; -    /** -     * The RavenwoodRule currently in effect, declared in the test class -     */ -    private RavenwoodRule mRule; -    private boolean mHasRavenwoodRule;      private Description mMethodDescription;      public void enterTestRunner() {          Log.i(TAG, "enterTestRunner: " + mRunner); - -        mHasRavenwoodRule = hasRavenwoodRule(mRunner.mTestJavaClass); -        mConfig = extractConfiguration(mRunner.mTestJavaClass); - -        if (mConfig != null) { -            if (mHasRavenwoodRule) { -                fail("RavenwoodConfig and RavenwoodRule cannot be used in the same class." -                        + " Suggest migrating to RavenwoodConfig."); -            } -        } -          RavenwoodRuntimeEnvironmentController.initForRunner();      } @@ -85,12 +53,7 @@ public final class RavenwoodRunnerState {      public void exitTestClass() {          Log.i(TAG, "exitTestClass: " + mRunner.mTestJavaClass.getName()); -        try { -            RavenwoodRuntimeEnvironmentController.exitTestClass(); -        } finally { -            mConfig = null; -            mRule = null; -        } +        RavenwoodRuntimeEnvironmentController.exitTestClass();      }      public void enterTestMethod(Description description) { @@ -103,132 +66,9 @@ public final class RavenwoodRunnerState {      }      public void enterRavenwoodRule(RavenwoodRule rule) { -        if (!mHasRavenwoodRule) { -            fail("If you have a RavenwoodRule in your test, make sure the field type is" -                    + " RavenwoodRule so Ravenwood can detect it."); -        } -        if (mRule != null) { -            fail("Multiple nesting RavenwoodRule's are detected in the same class," -                    + " which is not supported."); -        } -        mRule = rule;          RavenwoodRuntimeEnvironmentController.setSystemProperties(rule.mSystemProperties);      }      public void exitRavenwoodRule(RavenwoodRule rule) { -        if (mRule != rule) { -            fail("RavenwoodRule did not take effect."); -        } -        mRule = null; -    } - -    /** -     * @return a configuration from a test class, if any. -     */ -    @Nullable -    private static RavenwoodConfig extractConfiguration(Class<?> testClass) { -        var field = findConfigurationField(testClass); -        if (field == null) { -            return null; -        } - -        try { -            return (RavenwoodConfig) field.get(null); -        } catch (IllegalAccessException e) { -            throw new RavenwoodRuntimeException("Failed to fetch from the configuration field", e); -        } -    } - -    /** -     * @return true if the current target class (or its super classes) has any @Rule / @ClassRule -     * fields of type RavenwoodRule. -     * -     * Note, this check won't detect cases where a Rule is of type -     * {@link TestRule} and still be a {@link RavenwoodRule}. But that'll be detected at runtime -     * as a failure, in {@link #enterRavenwoodRule}. -     */ -    private static boolean hasRavenwoodRule(Class<?> testClass) { -        for (var field : testClass.getDeclaredFields()) { -            if (!field.isAnnotationPresent(Rule.class) -                    && !field.isAnnotationPresent(ClassRule.class)) { -                continue; -            } -            if (field.getType().equals(RavenwoodRule.class)) { -                return true; -            } -        } -        // JUnit supports rules as methods, so we need to check them too. -        for (var method : testClass.getDeclaredMethods()) { -            if (!method.isAnnotationPresent(Rule.class) -                    && !method.isAnnotationPresent(ClassRule.class)) { -                continue; -            } -            if (method.getReturnType().equals(RavenwoodRule.class)) { -                return true; -            } -        } -        // Look into the super class. -        if (!testClass.getSuperclass().equals(Object.class)) { -            return hasRavenwoodRule(testClass.getSuperclass()); -        } -        return false; -    } - -    /** -     * Find and return a field with @RavenwoodConfig.Config, which must be of type -     * RavenwoodConfig. -     */ -    @Nullable -    private static Field findConfigurationField(Class<?> testClass) { -        Field foundField = null; - -        for (var field : testClass.getDeclaredFields()) { -            final var hasAnot = field.isAnnotationPresent(RavenwoodConfig.Config.class); -            final var isType = field.getType().equals(RavenwoodConfig.class); - -            if (hasAnot) { -                if (isType) { -                    // Good, use this field. -                    if (foundField != null) { -                        fail(String.format( -                                "Class %s has multiple fields with %s", -                                testClass.getCanonicalName(), -                                "@RavenwoodConfig.Config")); -                    } -                    // Make sure it's static public -                    ensureIsPublicMember(field, true); - -                    foundField = field; -                } else { -                    fail(String.format( -                            "Field %s.%s has %s but type is not %s", -                            testClass.getCanonicalName(), -                            field.getName(), -                            "@RavenwoodConfig.Config", -                            "RavenwoodConfig")); -                    return null; // unreachable -                } -            } else { -                if (isType) { -                    fail(String.format( -                            "Field %s.%s does not have %s but type is %s", -                            testClass.getCanonicalName(), -                            field.getName(), -                            "@RavenwoodConfig.Config", -                            "RavenwoodConfig")); -                    return null; // unreachable -                } else { -                    // Unrelated field, ignore. -                    continue; -                } -            } -        } -        if (foundField != null) { -            return foundField; -        } -        if (!testClass.getSuperclass().equals(Object.class)) { -            return findConfigurationField(testClass.getSuperclass()); -        } -        return null;      }  } diff --git a/ravenwood/tests/bivalenttest/test/com/android/ravenwoodtest/bivalenttest/RavenwoodMultipleRuleTest.java b/ravenwood/tests/bivalenttest/test/com/android/ravenwoodtest/bivalenttest/RavenwoodMultipleRuleTest.java deleted file mode 100644 index c25d2b4cbc4d..000000000000 --- a/ravenwood/tests/bivalenttest/test/com/android/ravenwoodtest/bivalenttest/RavenwoodMultipleRuleTest.java +++ /dev/null @@ -1,57 +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.bivalenttest; - -import android.platform.test.ravenwood.RavenwoodConfig; -import android.platform.test.ravenwood.RavenwoodRule; - -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Assume; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; - -/** - * Make sure having multiple RavenwoodRule's is detected. - * (But only when running on ravenwod. Otherwise it'll be ignored.) - */ -@RunWith(AndroidJUnit4.class) -public class RavenwoodMultipleRuleTest { - -    @Rule(order = Integer.MIN_VALUE) -    public final ExpectedException mExpectedException = ExpectedException.none(); - -    @Rule -    public final RavenwoodRule mRavenwood1 = new RavenwoodRule(); - -    @Rule -    public final RavenwoodRule mRavenwood2 = new RavenwoodRule(); - -    public RavenwoodMultipleRuleTest() { -        // We can't call it within the test method because the exception happens before -        // calling the method, so set it up here. -        if (RavenwoodConfig.isOnRavenwood()) { -            mExpectedException.expectMessage("Multiple nesting RavenwoodRule"); -        } -    } - -    @Test -    public void testMultipleRulesNotAllowed() { -        Assume.assumeTrue(RavenwoodConfig.isOnRavenwood()); -    } -} diff --git a/ravenwood/tests/coretest/test/com/android/ravenwoodtest/runnercallbacktests/RavenwoodRuleValidationTest.java b/ravenwood/tests/coretest/test/com/android/ravenwoodtest/runnercallbacktests/RavenwoodRuleValidationTest.java new file mode 100644 index 000000000000..f9e73db23740 --- /dev/null +++ b/ravenwood/tests/coretest/test/com/android/ravenwoodtest/runnercallbacktests/RavenwoodRuleValidationTest.java @@ -0,0 +1,103 @@ +/* + * 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.runnercallbacktests; + +import static com.google.common.truth.Truth.assertThat; + +import android.os.SystemProperties; +import android.platform.test.annotations.NoRavenizer; +import android.platform.test.ravenwood.RavenwoodRule; + +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.junit.runner.RunWith; + +/** + * Test for RavenwoodRule. + */ +@NoRavenizer // This class shouldn't be executed with RavenwoodAwareTestRunner. +public class RavenwoodRuleValidationTest extends RavenwoodRunnerTestBase { + +    public static class RuleInBaseClass { +        static String PROPERTY_KEY = "debug.ravenwood.prop.in.base"; +        static String PROPERTY_VAL = "ravenwood"; +        @Rule +        public final RavenwoodRule mRavenwood1 = new RavenwoodRule.Builder() +                .setSystemPropertyImmutable(PROPERTY_KEY, PROPERTY_VAL).build(); +    } + +    /** +     * Make sure that RavenwoodRule in a base class takes effect. +     */ +    @RunWith(AndroidJUnit4.class) +    // CHECKSTYLE:OFF +    @Expected(""" +    testRunStarted: classes +    testSuiteStarted: classes +    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRuleValidationTest$RuleInBaseClassSuccessTest +    testStarted: testRuleInBaseClass(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRuleValidationTest$RuleInBaseClassSuccessTest) +    testFinished: testRuleInBaseClass(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRuleValidationTest$RuleInBaseClassSuccessTest) +    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRuleValidationTest$RuleInBaseClassSuccessTest +    testSuiteFinished: classes +    testRunFinished: 1,0,0,0 +    """) +    // CHECKSTYLE:ON +    public static class RuleInBaseClassSuccessTest extends RuleInBaseClass { + +        @Test +        public void testRuleInBaseClass() { +            assertThat(SystemProperties.get(PROPERTY_KEY)).isEqualTo(PROPERTY_VAL); +        } +    } + +    /** +     * Same as {@link RuleInBaseClass}, but the type of the rule field is not {@link RavenwoodRule}. +     */ +    public abstract static class RuleWithDifferentTypeInBaseClass { +        static String PROPERTY_KEY = "debug.ravenwood.prop.in.base.different.type"; +        static String PROPERTY_VAL = "ravenwood"; +        @Rule +        public final TestRule mRavenwood1 = new RavenwoodRule.Builder() +                .setSystemPropertyImmutable(PROPERTY_KEY, PROPERTY_VAL).build(); +    } + +    /** +     * Make sure that RavenwoodRule in a base class takes effect, even if the field type is not +     */ +    @RunWith(AndroidJUnit4.class) +    // CHECKSTYLE:OFF +    @Expected(""" +    testRunStarted: classes +    testSuiteStarted: classes +    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRuleValidationTest$RuleWithDifferentTypeInBaseClassSuccessTest +    testStarted: testRuleInBaseClass(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRuleValidationTest$RuleWithDifferentTypeInBaseClassSuccessTest) +    testFinished: testRuleInBaseClass(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRuleValidationTest$RuleWithDifferentTypeInBaseClassSuccessTest) +    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRuleValidationTest$RuleWithDifferentTypeInBaseClassSuccessTest +    testSuiteFinished: classes +    testRunFinished: 1,0,0,0 +    """) +    // CHECKSTYLE:ON +    public static class RuleWithDifferentTypeInBaseClassSuccessTest extends RuleWithDifferentTypeInBaseClass { + +        @Test +        public void testRuleInBaseClass() { +            assertThat(SystemProperties.get(PROPERTY_KEY)).isEqualTo(PROPERTY_VAL); +        } +    } +} diff --git a/ravenwood/tests/coretest/test/com/android/ravenwoodtest/runnercallbacktests/RavenwoodRunnerConfigValidationTest.java b/ravenwood/tests/coretest/test/com/android/ravenwoodtest/runnercallbacktests/RavenwoodRunnerConfigValidationTest.java deleted file mode 100644 index f94b98bc1fb8..000000000000 --- a/ravenwood/tests/coretest/test/com/android/ravenwoodtest/runnercallbacktests/RavenwoodRunnerConfigValidationTest.java +++ /dev/null @@ -1,484 +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.runnercallbacktests; - -import static com.google.common.truth.Truth.assertThat; - -import android.platform.test.annotations.NoRavenizer; -import android.platform.test.ravenwood.RavenwoodConfig; -import android.platform.test.ravenwood.RavenwoodRule; - -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.platform.app.InstrumentationRegistry; - -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.runner.RunWith; - - -/** - * Test for @Config field extraction and validation. - * - * TODO(b/377765941) Most of the tests here will be obsolete and deleted with b/377765941, but - * some of the tests may need to be re-implemented one way or another. (e.g. the package name - * test.) Until that happens, we'll keep all tests here but add an {@code @Ignore} instead. - */ -@NoRavenizer // This class shouldn't be executed with RavenwoodAwareTestRunner. -public class RavenwoodRunnerConfigValidationTest extends RavenwoodRunnerTestBase { -    public abstract static class ConfigInBaseClass { -        static String PACKAGE_NAME = "com.ConfigInBaseClass"; - -        @RavenwoodConfig.Config -        public static RavenwoodConfig sConfig = new RavenwoodConfig.Builder() -                .setPackageName(PACKAGE_NAME).build(); -    } - -    /** -     * Make sure a config in the base class is detected. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigInBaseClassTest -    testStarted: test(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigInBaseClassTest) -    testFinished: test(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigInBaseClassTest) -    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigInBaseClassTest -    testSuiteFinished: classes -    testRunFinished: 1,0,0,0 -    """) -    // CHECKSTYLE:ON -    @Ignore // Package name is no longer set via config. -    public static class ConfigInBaseClassTest extends ConfigInBaseClass { -        @Test -        public void test() { -            assertThat(InstrumentationRegistry.getInstrumentation().getContext().getPackageName()) -                    .isEqualTo(PACKAGE_NAME); -        } -    } - -    /** -     * Make sure a config in the base class is detected. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigOverridingTest -    testStarted: test(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigOverridingTest) -    testFinished: test(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigOverridingTest) -    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigOverridingTest -    testSuiteFinished: classes -    testRunFinished: 1,0,0,0 -    """) -    // CHECKSTYLE:ON -    @Ignore // Package name is no longer set via config. -    public static class ConfigOverridingTest extends ConfigInBaseClass { -        static String PACKAGE_NAME_OVERRIDE = "com.ConfigOverridingTest"; - -        @RavenwoodConfig.Config -        public static RavenwoodConfig sConfig = new RavenwoodConfig.Builder() -                .setPackageName(PACKAGE_NAME_OVERRIDE).build(); - -        @Test -        public void test() { -            assertThat(InstrumentationRegistry.getInstrumentation().getContext().getPackageName()) -                    .isEqualTo(PACKAGE_NAME_OVERRIDE); -        } -    } - -    /** -     * Test to make sure that if a test has a config error, the failure would be reported from -     * each test method. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testStarted: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ErrorMustBeReportedFromEachTest) -    testFailure: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ErrorMustBeReportedFromEachTest.sConfig expected to be public static -    testFinished: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ErrorMustBeReportedFromEachTest) -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class ErrorMustBeReportedFromEachTest { -        @RavenwoodConfig.Config -        private static RavenwoodConfig sConfig = // Invalid because it's private. -                new RavenwoodConfig.Builder().build(); - -        @Test -        public void testMethod1() { -        } - -        @Test -        public void testMethod2() { -        } - -        @Test -        public void testMethod3() { -        } -    } - -    /** -     * Invalid because there are two @Config's. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testStarted: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$DuplicateConfigTest) -    testFailure: Class com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest.DuplicateConfigTest has multiple fields with @RavenwoodConfig.Config -    testFinished: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$DuplicateConfigTest) -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class DuplicateConfigTest { - -        @RavenwoodConfig.Config -        public static RavenwoodConfig sConfig1 = -                new RavenwoodConfig.Builder().build(); - -        @RavenwoodConfig.Config -        public static RavenwoodConfig sConfig2 = -                new RavenwoodConfig.Builder().build(); - -        @Test -        public void testConfig() { -        } -    } - -    /** -     * @Config's must be static. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testStarted: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$NonStaticConfigTest) -    testFailure: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$NonStaticConfigTest.sConfig expected to be public static -    testFinished: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$NonStaticConfigTest) -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class NonStaticConfigTest { - -        @RavenwoodConfig.Config -        public RavenwoodConfig sConfig = -                new RavenwoodConfig.Builder().build(); - -        @Test -        public void testConfig() { -        } -    } - -    /** -     * @Config's must be public. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testStarted: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$NonPublicConfigTest) -    testFailure: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$NonPublicConfigTest.sConfig expected to be public static -    testFinished: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$NonPublicConfigTest) -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class NonPublicConfigTest { - -        @RavenwoodConfig.Config -        RavenwoodConfig sConfig = -                new RavenwoodConfig.Builder().build(); - -        @Test -        public void testConfig() { -        } -    } - -    /** -     * @Config's must be of type RavenwoodConfig. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testStarted: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WrongTypeConfigTest) -    testFailure: Field com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest.WrongTypeConfigTest.sConfig has @RavenwoodConfig.Config but type is not RavenwoodConfig -    testFinished: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WrongTypeConfigTest) -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class WrongTypeConfigTest { - -        @RavenwoodConfig.Config -        public static Object sConfig = -                new RavenwoodConfig.Builder().build(); - -        @Test -        public void testConfig() { -        } - -    } - -    /** -     * @Rule must be of type RavenwoodRule. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WrongTypeRuleTest -    testStarted: testConfig(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WrongTypeRuleTest) -    testFailure: If you have a RavenwoodRule in your test, make sure the field type is RavenwoodRule so Ravenwood can detect it. -    testFinished: testConfig(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WrongTypeRuleTest) -    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WrongTypeRuleTest -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class WrongTypeRuleTest { - -        @Rule -        public TestRule mRule = new RavenwoodRule.Builder().build(); - -        @Test -        public void testConfig() { -        } - -    } - -    /** -     * Config can't be used with a (instance) Rule. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testStarted: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WithInstanceRuleTest) -    testFailure: RavenwoodConfig and RavenwoodRule cannot be used in the same class. Suggest migrating to RavenwoodConfig. -    testFinished: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WithInstanceRuleTest) -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class WithInstanceRuleTest { - -        @RavenwoodConfig.Config -        public static RavenwoodConfig sConfig = -                new RavenwoodConfig.Builder().build(); - -        @Rule -        public RavenwoodRule mRule = new RavenwoodRule.Builder().build(); - -        @Test -        public void testConfig() { -        } -    } - -    /** -     * Config can't be used with a (static) Rule. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testStarted: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WithStaticRuleTest) -    testFailure: Failed to instantiate class androidx.test.ext.junit.runners.AndroidJUnit4 -    testFinished: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$WithStaticRuleTest) -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class WithStaticRuleTest { - -        @RavenwoodConfig.Config -        public static RavenwoodConfig sConfig = -                new RavenwoodConfig.Builder().build(); - -        @Rule -        public static RavenwoodRule sRule = new RavenwoodRule.Builder().build(); - -        @Test -        public void testConfig() { -        } -    } - -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$DuplicateRulesTest -    testStarted: testMultipleRulesNotAllowed(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$DuplicateRulesTest) -    testFailure: Multiple nesting RavenwoodRule's are detected in the same class, which is not supported. -    testFinished: testMultipleRulesNotAllowed(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$DuplicateRulesTest) -    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$DuplicateRulesTest -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class DuplicateRulesTest { - -        @Rule -        public final RavenwoodRule mRavenwood1 = new RavenwoodRule(); - -        @Rule -        public final RavenwoodRule mRavenwood2 = new RavenwoodRule(); - -        @Test -        public void testMultipleRulesNotAllowed() { -        } -    } - -    public static class RuleInBaseClass { -        static String PACKAGE_NAME = "com.RuleInBaseClass"; -        @Rule -        public final RavenwoodRule mRavenwood1 = new RavenwoodRule.Builder() -                .setPackageName(PACKAGE_NAME).build(); -    } - -    /** -     * Make sure that RavenwoodRule in a base class takes effect. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$RuleInBaseClassSuccessTest -    testStarted: testRuleInBaseClass(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$RuleInBaseClassSuccessTest) -    testFinished: testRuleInBaseClass(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$RuleInBaseClassSuccessTest) -    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$RuleInBaseClassSuccessTest -    testSuiteFinished: classes -    testRunFinished: 1,0,0,0 -    """) -    // CHECKSTYLE:ON -    @Ignore // Package name is no longer set via config. -    public static class RuleInBaseClassSuccessTest extends RuleInBaseClass { - -        @Test -        public void testRuleInBaseClass() { -            assertThat(InstrumentationRegistry.getInstrumentation().getContext().getPackageName()) -                    .isEqualTo(PACKAGE_NAME); -        } -    } - -    /** -     * Make sure that having a config and a rule in a base class should fail. -     * RavenwoodRule. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testStarted: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigWithRuleInBaseClassTest) -    testFailure: RavenwoodConfig and RavenwoodRule cannot be used in the same class. Suggest migrating to RavenwoodConfig. -    testFinished: initializationError(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigWithRuleInBaseClassTest) -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class ConfigWithRuleInBaseClassTest extends RuleInBaseClass { -        @RavenwoodConfig.Config -        public static RavenwoodConfig sConfig = new RavenwoodConfig.Builder().build(); - -        @Test -        public void test() { -        } -    } - -    /** -     * Same as {@link RuleInBaseClass}, but the type of the rule field is not {@link RavenwoodRule}. -     */ -    public abstract static class RuleWithDifferentTypeInBaseClass { -        static String PACKAGE_NAME = "com.RuleWithDifferentTypeInBaseClass"; -        @Rule -        public final TestRule mRavenwood1 = new RavenwoodRule.Builder() -                .setPackageName(PACKAGE_NAME).build(); -    } - -    /** -     * Make sure that RavenwoodRule in a base class takes effect, even if the field type is not -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$RuleWithDifferentTypeInBaseClassSuccessTest -    testStarted: testRuleInBaseClass(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$RuleWithDifferentTypeInBaseClassSuccessTest) -    testFailure: If you have a RavenwoodRule in your test, make sure the field type is RavenwoodRule so Ravenwood can detect it. -    testFinished: testRuleInBaseClass(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$RuleWithDifferentTypeInBaseClassSuccessTest) -    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$RuleWithDifferentTypeInBaseClassSuccessTest -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    @Ignore // Package name is no longer set via config. -    public static class RuleWithDifferentTypeInBaseClassSuccessTest extends RuleWithDifferentTypeInBaseClass { - -        @Test -        public void testRuleInBaseClass() { -            assertThat(InstrumentationRegistry.getInstrumentation().getContext().getPackageName()) -                    .isEqualTo(PACKAGE_NAME); -        } -    } - -    /** -     * Make sure that having a config and a rule in a base class should fail, even if the field type is not -     * RavenwoodRule. -     */ -    @RunWith(AndroidJUnit4.class) -    // CHECKSTYLE:OFF -    @Expected(""" -    testRunStarted: classes -    testSuiteStarted: classes -    testSuiteStarted: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigWithRuleWithDifferentTypeInBaseClassTest -    testStarted: test(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigWithRuleWithDifferentTypeInBaseClassTest) -    testFailure: If you have a RavenwoodRule in your test, make sure the field type is RavenwoodRule so Ravenwood can detect it. -    testFinished: test(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigWithRuleWithDifferentTypeInBaseClassTest) -    testSuiteFinished: com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerConfigValidationTest$ConfigWithRuleWithDifferentTypeInBaseClassTest -    testSuiteFinished: classes -    testRunFinished: 1,1,0,0 -    """) -    // CHECKSTYLE:ON -    public static class ConfigWithRuleWithDifferentTypeInBaseClassTest extends RuleWithDifferentTypeInBaseClass { -        @RavenwoodConfig.Config -        public static RavenwoodConfig sConfig = new RavenwoodConfig.Builder().build(); - -        @Test -        public void test() { -        } -    } -} diff --git a/ravenwood/tests/runtime-test/test/com/android/ravenwoodtest/runtimetest/IdentityTest.java b/ravenwood/tests/runtime-test/test/com/android/ravenwoodtest/runtimetest/IdentityTest.java index 8e04b698c9d9..271c27f6ae93 100644 --- a/ravenwood/tests/runtime-test/test/com/android/ravenwoodtest/runtimetest/IdentityTest.java +++ b/ravenwood/tests/runtime-test/test/com/android/ravenwoodtest/runtimetest/IdentityTest.java @@ -15,7 +15,6 @@   */  package com.android.ravenwoodtest.runtimetest; -import static android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE;  import static android.os.Process.FIRST_APPLICATION_UID;  import static org.junit.Assert.assertEquals; @@ -23,7 +22,6 @@ import static org.junit.Assert.assertEquals;  import android.os.Binder;  import android.os.Build;  import android.os.Process; -import android.platform.test.ravenwood.RavenwoodConfig;  import android.system.Os;  import com.android.ravenwood.RavenwoodRuntimeState; @@ -34,13 +32,6 @@ import org.junit.Test;  public class IdentityTest { -    @RavenwoodConfig.Config -    public static final RavenwoodConfig sConfig = -            new RavenwoodConfig.Builder() -                    .setTargetSdkLevel(UPSIDE_DOWN_CAKE) -                    .setProcessApp() -                    .build(); -      @Test      public void testUid() {          assertEquals(FIRST_APPLICATION_UID, RavenwoodRuntimeState.sUid); @@ -60,7 +51,7 @@ public class IdentityTest {      @Test      public void testTargetSdkLevel() {          assertEquals(Build.VERSION_CODES.CUR_DEVELOPMENT, RavenwoodRuntimeState.CUR_DEVELOPMENT); -        assertEquals(UPSIDE_DOWN_CAKE, RavenwoodRuntimeState.sTargetSdkLevel); -        assertEquals(UPSIDE_DOWN_CAKE, VMRuntime.getRuntime().getTargetSdkVersion()); +        assertEquals(RavenwoodRuntimeState.sTargetSdkLevel, +                VMRuntime.getRuntime().getTargetSdkVersion());      }  } diff --git a/ravenwood/tests/services-test/test/com/android/ravenwoodtest/servicestest/RavenwoodServicesTest.java b/ravenwood/tests/services-test/test/com/android/ravenwoodtest/servicestest/RavenwoodServicesTest.java index 4aae1e11b72e..e83a247bd769 100644 --- a/ravenwood/tests/services-test/test/com/android/ravenwoodtest/servicestest/RavenwoodServicesTest.java +++ b/ravenwood/tests/services-test/test/com/android/ravenwoodtest/servicestest/RavenwoodServicesTest.java @@ -24,8 +24,6 @@ import static org.junit.Assert.fail;  import android.content.Context;  import android.hardware.SerialManager;  import android.hardware.SerialManagerInternal; -import android.platform.test.ravenwood.RavenwoodConfig; -import android.platform.test.ravenwood.RavenwoodConfig.Config;  import androidx.test.ext.junit.runners.AndroidJUnit4;  import androidx.test.platform.app.InstrumentationRegistry; @@ -42,12 +40,6 @@ import org.junit.runner.RunWith;  public class RavenwoodServicesTest {      private static final String TEST_VIRTUAL_PORT = "virtual:example"; -    @Config -    public static final RavenwoodConfig sRavenwood = new RavenwoodConfig.Builder() -            .setProcessSystem() -            .setServicesRequired(SerialManager.class) -            .build(); -      private Context mContext;      @Before |