Skip to content

Instantly share code, notes, and snippets.

@coyarzun89
Created May 7, 2021 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coyarzun89/f7ae848392c1ebef56cf0548f0a31b40 to your computer and use it in GitHub Desktop.
Save coyarzun89/f7ae848392c1ebef56cf0548f0a31b40 to your computer and use it in GitHub Desktop.
HardcodedColorXmlDetectorTest.kt
class HardcodedColorXmlDetectorTest {
@Test
fun `Given a hardcoded color on a custom text view property, When we analyze our custom rule, Then display an error`() {
lint()
.files(
xml(
"res/layout/layout.xml",
"""
<TextView xmlns:app="http://schemas.android.com/apk/res-auto"
app:someCustomColor="#fff"/>
"""
).indented()
)
.issues(HardcodedColorXmlDetector.ISSUE)
.allowMissingSdk()
.run()
.expectCount(1, Severity.ERROR)
}
@Test
fun `Given a hardcoded color on a text view, When we analyze our custom rule, Then display an error`() {
lint()
.files(
xml(
"res/layout/layout.xml",
"""
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:textColor="#80000000"/>
"""
).indented()
)
.issues(HardcodedColorXmlDetector.ISSUE)
.allowMissingSdk()
.run()
.expectCount(1, Severity.ERROR)
}
@Test
fun `Given a color from our resources on a text view, When we analyze our custom rule, Then expect no errors`() {
lint()
.files(
xml(
"res/layout/layout.xml",
"""
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:textColor="@color/primaryColor"/>
"""
).indented()
)
.issues(HardcodedColorXmlDetector.ISSUE)
.allowMissingSdk()
.run()
.expectClean()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment