Search in sources :

Example 1 with CrashReportDataFactory

use of org.acra.data.CrashReportDataFactory in project AnkiChinaAndroid by ankichinateam.

the class ACRATest method testCrashReportLimit.

@Test
public void testCrashReportLimit() throws Exception {
    // To test ACRA switch on  reporting, plant a production tree, and trigger a report
    Timber.plant(new AnkiDroidApp.ProductionCrashReportingTree());
    // set up as if the user had prefs saved to full auto
    setReportConfig(FEEDBACK_REPORT_ALWAYS);
    // If the user is set to always, then it's production, with interaction mode toast
    // will be useful with ACRA 5.2.0
    setAcraConfig("Production");
    // The same class/method combo is only sent once, so we face a new method each time (should test that system later)
    Exception crash = new Exception("testCrashReportSend at " + System.currentTimeMillis());
    StackTraceElement[] trace = new StackTraceElement[] { new StackTraceElement("Class", "Method" + (int) System.currentTimeMillis(), "File", (int) System.currentTimeMillis()) };
    crash.setStackTrace(trace);
    // one send should work
    CrashReportData crashData = new CrashReportDataFactory(InstrumentationRegistry.getInstrumentation().getTargetContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build()).createCrashData(new ReportBuilder().exception(crash));
    assertTrue(new LimitingReportAdministrator().shouldSendReport(InstrumentationRegistry.getInstrumentation().getTargetContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
    // A second send should not work
    assertFalse(new LimitingReportAdministrator().shouldSendReport(InstrumentationRegistry.getInstrumentation().getTargetContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
    // Now let's clear data
    AnkiDroidApp.deleteACRALimiterData(InstrumentationRegistry.getInstrumentation().getTargetContext());
    // A third send should work again
    assertTrue(new LimitingReportAdministrator().shouldSendReport(InstrumentationRegistry.getInstrumentation().getTargetContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
}
Also used : CrashReportData(org.acra.data.CrashReportData) ReportBuilder(org.acra.builder.ReportBuilder) LimitingReportAdministrator(org.acra.config.LimitingReportAdministrator) AnkiDroidApp(com.ichi2.anki.AnkiDroidApp) CrashReportDataFactory(org.acra.data.CrashReportDataFactory) ACRAConfigurationException(org.acra.config.ACRAConfigurationException) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 2 with CrashReportDataFactory

use of org.acra.data.CrashReportDataFactory in project Anki-Android by ankidroid.

the class ACRATest method testCrashReportLimit.

@Test
public void testCrashReportLimit() throws Exception {
    // To test ACRA switch on  reporting, plant a production tree, and trigger a report
    Timber.plant(new AnkiDroidApp.ProductionCrashReportingTree());
    // set up as if the user had prefs saved to full auto
    setReportConfig(FEEDBACK_REPORT_ALWAYS);
    // If the user is set to always, then it's production, with interaction mode toast
    // will be useful with ACRA 5.2.0
    setAcraConfig("Production");
    // The same class/method combo is only sent once, so we face a new method each time (should test that system later)
    Exception crash = new Exception("testCrashReportSend at " + System.currentTimeMillis());
    StackTraceElement[] trace = new StackTraceElement[] { new StackTraceElement("Class", "Method" + (int) System.currentTimeMillis(), "File", (int) System.currentTimeMillis()) };
    crash.setStackTrace(trace);
    // one send should work
    CrashReportData crashData = new CrashReportDataFactory(getTestContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build()).createCrashData(new ReportBuilder().exception(crash));
    assertTrue(new LimitingReportAdministrator().shouldSendReport(getTestContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
    // A second send should not work
    assertFalse(new LimitingReportAdministrator().shouldSendReport(getTestContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
    // Now let's clear data
    AnkiDroidApp.deleteACRALimiterData(getTestContext());
    // A third send should work again
    assertTrue(new LimitingReportAdministrator().shouldSendReport(getTestContext(), AnkiDroidApp.getInstance().getAcraCoreConfigBuilder().build(), crashData));
}
Also used : CrashReportData(org.acra.data.CrashReportData) ReportBuilder(org.acra.builder.ReportBuilder) LimitingReportAdministrator(org.acra.config.LimitingReportAdministrator) AnkiDroidApp(com.ichi2.anki.AnkiDroidApp) CrashReportDataFactory(org.acra.data.CrashReportDataFactory) ACRAConfigurationException(org.acra.config.ACRAConfigurationException) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (androidx.test.annotation.UiThreadTest)2 AnkiDroidApp (com.ichi2.anki.AnkiDroidApp)2 ReportBuilder (org.acra.builder.ReportBuilder)2 ACRAConfigurationException (org.acra.config.ACRAConfigurationException)2 LimitingReportAdministrator (org.acra.config.LimitingReportAdministrator)2 CrashReportData (org.acra.data.CrashReportData)2 CrashReportDataFactory (org.acra.data.CrashReportDataFactory)2 Test (org.junit.Test)2