Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25e1399e authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Add @BrokenWithSceneContainer annotation to mark tests that require remedy

Test: atest SystemUITests
Flag: NA
Change-Id: I80dc27b1ac1bedf75ed71c5094cb5d03c50be6f3
parent 670ba514
Loading
Loading
Loading
Loading
+27 −0
Original line number Original line Diff line number Diff line
/*
 * 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.systemui.flags

import com.android.systemui.Flags.FLAG_SCENE_CONTAINER

/**
 * This is used by [SceneContainerRule] to assert that the test is broken when
 * [FLAG_SCENE_CONTAINER] is enabled.
 */
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
annotation class BrokenWithSceneContainer(val bugId: Int)
+25 −4
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.flags


import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import org.junit.Assert
import org.junit.Assert
import org.junit.AssumptionViolatedException
import org.junit.rules.TestRule
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.junit.runners.model.Statement
@@ -33,10 +34,7 @@ class SceneContainerRule : TestRule {
        return object : Statement() {
        return object : Statement() {
            @Throws(Throwable::class)
            @Throws(Throwable::class)
            override fun evaluate() {
            override fun evaluate() {
                val hasAnnotation =
                if (description.hasAnnotation<EnableSceneContainer>()) {
                    description?.testClass?.getAnnotation(EnableSceneContainer::class.java) !=
                        null || description?.getAnnotation(EnableSceneContainer::class.java) != null
                if (hasAnnotation) {
                    Assert.assertTrue(
                    Assert.assertTrue(
                        "SceneContainerFlag.isEnabled is false:" +
                        "SceneContainerFlag.isEnabled is false:" +
                            "\n * Did you forget to add a new aconfig flag dependency in" +
                            "\n * Did you forget to add a new aconfig flag dependency in" +
@@ -45,8 +43,31 @@ class SceneContainerRule : TestRule {
                        SceneContainerFlag.isEnabled
                        SceneContainerFlag.isEnabled
                    )
                    )
                }
                }
                if (
                    description.hasAnnotation<BrokenWithSceneContainer>() &&
                        SceneContainerFlag.isEnabled
                ) {
                    runCatching { base?.evaluate() }
                        .onFailure { exception ->
                            if (exception is AssumptionViolatedException) {
                                throw AssertionError(
                                    "This is marked @BrokenWithSceneContainer, but was skipped.",
                                    exception
                                )
                            }
                            throw AssumptionViolatedException("Test is still broken", exception)
                        }
                    throw AssertionError(
                        "HOORAY! You fixed a test that was marked @BrokenWithSceneContainer. " +
                            "Remove the obsolete annotation to fix this failure."
                    )
                }
                base?.evaluate()
                base?.evaluate()
            }
            }
        }
        }
    }
    }

    inline fun <reified T : Annotation> Description?.hasAnnotation(): Boolean =
        this?.testClass?.getAnnotation(T::class.java) != null ||
            this?.getAnnotation(T::class.java) != null
}
}