Skip to content

Instantly share code, notes, and snippets.

@mister11
Created January 30, 2019 13:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mister11/a9c04e35bb3083416cf9651d91f463c4 to your computer and use it in GitHub Desktop.
Save mister11/a9c04e35bb3083416cf9651d91f463c4 to your computer and use it in GitHub Desktop.
Lint XML Test
class ExportedActivityDetectorTest {
private val validXmlFile = xml(
"AndroidManifest.xml",
"""
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.infinum.lint">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
/>
</application>
</manifest>
""".inline()
)
private val invalidXmlFile = xml(
"AndroidManifest.xml",
"""
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.infinum.lint">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true"/>
</application>
</manifest>
""".inline()
)
@Test
fun exportedActivity() {
lint()
.files(invalidXmlFile)
.issues(ISSUE_EXPORTED_ACTIVITY)
.run()
.expectErrorCount(1)
.checkFix(null, validXmlFile)
}
@Test
fun noExportedActivities() {
lint()
.files(validXmlFile)
.issues(ISSUE_EXPORTED_ACTIVITY)
.run()
.expectClean()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment