-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
continue with anr message improvements
- Loading branch information
1 parent
73795be
commit 5673b0a
Showing
9 changed files
with
211 additions
and
56 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
bugsnag-android-core/src/androidTest/java/com/bugsnag/android/ErrorNameTest.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,48 @@ | ||
package com.bugsnag.android | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class ErrorNameTest { | ||
|
||
private lateinit var error: Error | ||
|
||
@Before | ||
fun setUp() { | ||
val config = Configuration("api-key") | ||
val exception = RuntimeException("Example message", RuntimeException("Another")) | ||
error = Error.Builder(config, exception, null, Thread.currentThread(), false).build() | ||
} | ||
|
||
@Test | ||
fun exceptionTypeConverted() { | ||
assertTrue(error.exception is BugsnagException) | ||
assertTrue(error.exceptions.exception is BugsnagException) | ||
assertTrue(error.exceptions.exception.cause is RuntimeException) | ||
} | ||
|
||
@Test | ||
fun defaultExceptionName() { | ||
assertEquals("java.lang.RuntimeException", error.exceptionName) | ||
} | ||
|
||
@Test | ||
fun defaultExceptionMessage() { | ||
assertEquals("Example message", error.exceptionMessage) | ||
} | ||
|
||
@Test | ||
fun overrideExceptionName() { | ||
error.exceptionName = "Foo" | ||
assertEquals("Foo", error.exceptionName) | ||
} | ||
|
||
@Test | ||
fun overrideExceptionMessage() { | ||
error.exceptionMessage = "Some custom message" | ||
assertEquals("Some custom message", error.exceptionMessage) | ||
} | ||
|
||
} |
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
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
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
87 changes: 87 additions & 0 deletions
87
...ag-plugin-android-anr/src/androidTest/java/com/bugsnag/android/AnrDetailsCollectorTest.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,87 @@ | ||
package com.bugsnag.android | ||
|
||
import android.app.ActivityManager | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNull | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.Mockito | ||
import org.mockito.junit.MockitoJUnitRunner | ||
|
||
@RunWith(MockitoJUnitRunner::class) | ||
class AnrDetailsCollectorTest { | ||
|
||
private companion object { | ||
private const val PID_EXAMPLE = 5902 | ||
} | ||
|
||
private val collector = AnrDetailsCollector() | ||
private val stateInfo = ActivityManager.ProcessErrorStateInfo() | ||
private lateinit var error: Error | ||
|
||
@Mock | ||
lateinit var am: ActivityManager | ||
|
||
@Before | ||
fun setUp() { | ||
stateInfo.pid = PID_EXAMPLE | ||
stateInfo.tag = "com.bugsnag.android.example/.ExampleActivity" | ||
stateInfo.shortMsg = "ANR Input dispatching timed out" | ||
stateInfo.longMsg = "ANR in com.bugsnag.android.example" | ||
|
||
error = Error.Builder( | ||
Configuration("f"), | ||
RuntimeException(), | ||
null, | ||
Thread.currentThread(), | ||
true | ||
).build() | ||
} | ||
|
||
@Test | ||
fun exceptionReturnsNull() { | ||
Mockito.`when`(am.processesInErrorState).thenThrow(RuntimeException()) | ||
assertNull(collector.captureProcessErrorState(am, 0)) | ||
} | ||
|
||
@Test | ||
fun emptyListReturnsNull() { | ||
Mockito.`when`(am.processesInErrorState).thenReturn(listOf()) | ||
assertNull(collector.captureProcessErrorState(am, 0)) | ||
} | ||
|
||
@Test | ||
fun differentPidReturnsNull() { | ||
Mockito.`when`(am.processesInErrorState).thenReturn(listOf(stateInfo)) | ||
val captureProcessErrorState = collector.captureProcessErrorState(am, PID_EXAMPLE) | ||
assertEquals(stateInfo, captureProcessErrorState) | ||
} | ||
|
||
@Test | ||
fun samePidReturnsObj() { | ||
val second = ActivityManager.ProcessErrorStateInfo() | ||
Mockito.`when`(am.processesInErrorState).thenReturn(listOf(stateInfo, second)) | ||
val captureProcessErrorState = collector.captureProcessErrorState(am, PID_EXAMPLE) | ||
assertEquals(stateInfo, captureProcessErrorState) | ||
} | ||
|
||
@Test | ||
fun errMsgAltered() { | ||
collector.mutateError(error, stateInfo) | ||
assertEquals(stateInfo.shortMsg, error.exceptionName) | ||
} | ||
|
||
@Test | ||
fun contextAltered() { | ||
collector.mutateError(error, stateInfo) | ||
assertEquals(stateInfo.tag, error.context) | ||
} | ||
|
||
@Test | ||
fun anrDetailsAltered() { | ||
collector.mutateError(error, stateInfo) | ||
assertEquals(stateInfo.longMsg, error.exceptionMessage) | ||
} | ||
} |
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