diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java index 0ef9322bf1..23e4ad053f 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ErrorStoreTest.java @@ -98,6 +98,18 @@ public void testComparator() throws Exception { assertTrue(ERROR_REPORT_COMPARATOR.compare(new File(second), new File(startup)) > 0); } + @Test + public void isStartupCrash() throws Exception { + assertTrue(errorStore.isStartupCrash(0)); + + config.setLaunchCrashThresholdMs(0); + assertFalse(errorStore.isStartupCrash(0)); + + config.setLaunchCrashThresholdMs(10000); + assertTrue(errorStore.isStartupCrash(5345)); + assertTrue(errorStore.isStartupCrash(9999)); + assertFalse(errorStore.isStartupCrash(10000)); + } /** * Ensures that the file can be serialised back into a JSON report, and contains the same info diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ExceptionHandlerTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ExceptionHandlerTest.java index 3423163170..3886c701d2 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ExceptionHandlerTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ExceptionHandlerTest.java @@ -9,8 +9,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Date; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -50,9 +48,4 @@ public void testMultipleClients() { assertEquals(2, bugsnagHandler.clientMap.size()); } - @Test - public void testIsCrashOnLaunch() throws Exception { - //TODO:SM Replace this - } - } diff --git a/sdk/src/main/java/com/bugsnag/android/ErrorStore.java b/sdk/src/main/java/com/bugsnag/android/ErrorStore.java index 4b8b16ded5..a03f718d22 100644 --- a/sdk/src/main/java/com/bugsnag/android/ErrorStore.java +++ b/sdk/src/main/java/com/bugsnag/android/ErrorStore.java @@ -151,9 +151,13 @@ private List findLaunchCrashReports() { @NonNull @Override String getFilename(Error error) { - boolean isStartupCrash = AppData.getDurationMs() < config.getLaunchCrashThresholdMs(); + boolean isStartupCrash = isStartupCrash(AppData.getDurationMs()); String suffix = isStartupCrash ? STARTUP_CRASH : ""; return String.format(Locale.US, "%s%d%s.json", storeDirectory, System.currentTimeMillis(), suffix); } + boolean isStartupCrash(long durationMs) { + return durationMs < config.getLaunchCrashThresholdMs(); + } + }