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

Commit a2c3ef27 authored by mattgilbride's avatar mattgilbride
Browse files

Add EnforcePermissionDetectorTest documenting "short string" behavior

Bug: 270686198
Test: atest --host AndroidGlobalLintCheckerTest
Change-Id: Ic3fc868cf1a74ad9044da3d5a2ce764f86b43ad4
parent 1a12606c
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -321,6 +321,34 @@ class EnforcePermissionDetectorTest : LintDetectorTest() {
            )
    }

    fun testDoesDetectIssuesShortStringsNotAllowed() {
        lint().files(java(
            """
            package test.pkg;
            import android.annotation.EnforcePermission;
            public class TestClass121 extends IFooMethod.Stub {
                @Override
                @EnforcePermission(anyOf={"INTERNET", "READ_PHONE_STATE"})
                public void testMethodAnyLiteral() {}
            }
            """).indented(),
            *stubs
        )
            .run()
            .expect(
                """
                src/test/pkg/TestClass121.java:6: Error: The method \
                TestClass121.testMethodAnyLiteral is annotated with @EnforcePermission(anyOf={"INTERNET", "READ_PHONE_STATE"}) \
                which differs from the overridden method Stub.testMethodAnyLiteral: \
                @android.annotation.EnforcePermission(anyOf={android.Manifest.permission.INTERNET, "android.permission.READ_PHONE_STATE"}). \
                The same annotation must be used for both methods. [MismatchingEnforcePermissionAnnotation]
                    public void testMethodAnyLiteral() {}
                                ~~~~~~~~~~~~~~~~~~~~
                1 errors, 0 warnings
                """.addLineContinuation()
            )
    }

    /* Stubs */

    // A service with permission annotation on the method.