-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from bugsnag/v5-test-coverage
Add additional unit test coverage
- Loading branch information
Showing
7 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bugsnag.android.gradle | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
|
||
class AbiTest { | ||
|
||
@Test | ||
fun findExisting() { | ||
val obs = Abi.findByName(Abi.ARM64_V8A.abiName) | ||
assertEquals(Abi.ARM64_V8A, obs) | ||
} | ||
|
||
@Test | ||
fun findNonExisting() { | ||
val obs = Abi.findByName("foo") | ||
assertNull(obs) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/kotlin/com/bugsnag/android/gradle/AndroidManifestInfoTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.bugsnag.android.gradle | ||
|
||
import groovy.util.GroovyTestCase.assertEquals | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.io.File | ||
|
||
class AndroidManifestInfoTest { | ||
|
||
private val info = AndroidManifestInfo( | ||
"api-key", | ||
"12", | ||
"build-123", | ||
"5.2", | ||
"com.example" | ||
) | ||
|
||
private lateinit var jsonFile: File | ||
|
||
@Before | ||
fun setUp() { | ||
jsonFile = File.createTempFile("test", ".json") | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
jsonFile.delete() | ||
} | ||
|
||
@Test | ||
fun testManifestReadWrite() { | ||
info.write(jsonFile) | ||
val json = jsonFile.readText() | ||
assertEquals(json, """ | ||
{"apiKey":"api-key","versionCode":"12","buildUUID":"build-123","versionName":"5.2","applicationId":"com.example"} | ||
""".trimIndent()) | ||
|
||
val copy = AndroidManifestInfo.read(jsonFile) | ||
assertEquals(info, copy) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/kotlin/com/bugsnag/android/gradle/AndroidManifestParseTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.bugsnag.android.gradle | ||
|
||
import org.gradle.api.logging.Logger | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.MockitoJUnitRunner | ||
import java.io.File | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
class AndroidManifestParseTest { | ||
|
||
private val info = AndroidManifestInfo( | ||
"api-key", | ||
"12", | ||
"build-uuid-123", | ||
"5.2", | ||
"com.example" | ||
) | ||
|
||
@Mock | ||
lateinit var logger: Logger | ||
|
||
private lateinit var manifestFile: File | ||
|
||
@Before | ||
fun setUp() { | ||
manifestFile = File.createTempFile("AndroidManifest", ".xml") | ||
val classLoader = AndroidManifestParseTest::class.java.classLoader | ||
val res = classLoader.getResource("AndroidManifest.xml")!! | ||
File(res.file).copyTo(manifestFile, true) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
manifestFile.delete() | ||
} | ||
|
||
@Test | ||
fun readManifest() { | ||
val read = AndroidManifestParser().readManifest(manifestFile, logger) | ||
assertEquals(info, read) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/kotlin/com/bugsnag/android/gradle/AndroidManifestWriteUuidTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.bugsnag.android.gradle | ||
|
||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import java.io.File | ||
|
||
class AndroidManifestWriteUuidTest { | ||
|
||
private val classLoader = AndroidManifestWriteUuidTest::class.java.classLoader | ||
|
||
private lateinit var manifestFile: File | ||
private lateinit var outputFile: File | ||
|
||
@Before | ||
fun setUp() { | ||
outputFile = File.createTempFile("output", ".xml") | ||
manifestFile = File.createTempFile("manifest_no_uuid", ".xml") | ||
val res = classLoader.getResource("manifest_no_uuid.xml")!! | ||
File(res.file).copyTo(manifestFile, true) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
manifestFile.delete() | ||
outputFile.delete() | ||
} | ||
|
||
@Test | ||
fun writeBuildUuid() { | ||
AndroidManifestParser().writeBuildUuid(manifestFile, outputFile, "build-uuid-123") | ||
val obs = outputFile.readText() | ||
val expected = classLoader.getResource("AndroidManifest.xml")!!.readText() | ||
assertEquals(expected, obs) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<manifest package="com.example" android:versionCode="12" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="5.2"> | ||
<application android:name="com.example.android.gradle.plugin.FooApp"> | ||
<meta-data android:name="com.bugsnag.android.API_KEY" android:value="api-key"/> | ||
<meta-data android:name="com.bugsnag.android.BUILD_UUID" android:value="build-uuid-123"/> | ||
</application> | ||
</manifest> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example" | ||
android:versionCode="12" | ||
android:versionName="5.2"> | ||
<application android:name="com.example.android.gradle.plugin.FooApp"> | ||
|
||
<meta-data | ||
android:name="com.bugsnag.android.API_KEY" | ||
android:value="api-key"/> | ||
</application> | ||
</manifest> |