Created
January 30, 2019 13:24
-
-
Save mister11/a9c04e35bb3083416cf9651d91f463c4 to your computer and use it in GitHub Desktop.
Lint XML Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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