Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.