From 1c0939c36504656259b450f74e962f7434762b78 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Thu, 20 Feb 2025 15:46:39 +0900 Subject: [PATCH] Support Paramerized in SetFeatureFlagsRule Make Parameterized compatible with SetFeatureFlagsRule. If both are used, the method names seen by SetFeatureFlagsRule may be followed by [\d+] in Parameterized style, leading to a method not found exception in SetFeatureFlagsRule. With this patch, both can be used at the same time. Test: add a Parameterized rule to CaptivePortalLoginActivityTest see how it fails with MethodNotFoundError without this patch see how it works as expected with this patch Change-Id: I3fe1e63600dd792bc290ed130b8598b49f2b95e1 --- .../com/android/testutils/SetFeatureFlagsRule.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/staticlibs/testutils/devicetests/com/android/testutils/SetFeatureFlagsRule.kt b/staticlibs/testutils/devicetests/com/android/testutils/SetFeatureFlagsRule.kt index 7b970d3a49..0b239b4b29 100644 --- a/staticlibs/testutils/devicetests/com/android/testutils/SetFeatureFlagsRule.kt +++ b/staticlibs/testutils/devicetests/com/android/testutils/SetFeatureFlagsRule.kt @@ -68,10 +68,15 @@ class SetFeatureFlagsRule( * If any `@FeatureFlag` annotation is found, it passes every feature flag's name * and enabled state into the user-specified lambda to apply custom actions. */ + private val parameterizedRegexp = Regex("\\[\\d+\\]$") override fun apply(base: Statement, description: Description): Statement { return object : Statement() { override fun evaluate() { - val testMethod = description.testClass.getMethod(description.methodName) + // If the same class also uses Parameterized, depending on evaluation order the + // method names here may be synthetic method names, where [0] [1] or so are added + // at the end of the method name. Find the original method name. + val methodName = description.methodName.replace(parameterizedRegexp, "") + val testMethod = description.testClass.getMethod(methodName) val featureFlagAnnotations = testMethod.getAnnotationsByType( FeatureFlag::class.java )