-
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.
Merge branch 'master' into api-client-safety
- Loading branch information
Showing
18 changed files
with
437 additions
and
103 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
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
38 changes: 38 additions & 0 deletions
38
sdk/src/androidTest/java/com/bugsnag/android/BreadcrumbLifecycleCrashTest.java
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,38 @@ | ||
package com.bugsnag.android; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.filters.SmallTest; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@SmallTest | ||
public class BreadcrumbLifecycleCrashTest { | ||
|
||
private SessionTracker sessionTracker; | ||
|
||
/** | ||
* Creates a SessionTracker with a null client | ||
* | ||
* @throws Exception if the SessionTracker couldn't be created | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
Configuration configuration = new Configuration("api-key"); | ||
Context context = InstrumentationRegistry.getContext(); | ||
SessionStore sessionStore = new SessionStore(configuration, context); | ||
SessionTrackingApiClient apiClient = BugsnagTestUtils.generateSessionTrackingApiClient(); | ||
sessionTracker = new SessionTracker(configuration, null, sessionStore, apiClient); | ||
} | ||
|
||
@Test | ||
public void testLifecycleBreadcrumbCrash() { | ||
// should not crash with a null client | ||
sessionTracker.leaveLifecycleBreadcrumb("FooActivity", "onCreate"); | ||
} | ||
|
||
} |
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
114 changes: 114 additions & 0 deletions
114
sdk/src/androidTest/java/com/bugsnag/android/ClientNotifyAsyncTest.java
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,114 @@ | ||
package com.bugsnag.android; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import android.support.test.filters.SmallTest; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
@SmallTest | ||
public class ClientNotifyAsyncTest { | ||
|
||
private Client client; | ||
private NullCheckClient apiClient; | ||
|
||
/** | ||
* Generates a configuration and clears sharedPrefs values to begin the test with a clean slate | ||
* | ||
* @throws Exception if initialisation failed | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
client = BugsnagTestUtils.generateClient(); | ||
apiClient = new NullCheckClient(); | ||
client.setErrorReportApiClient(apiClient); | ||
} | ||
|
||
@Test | ||
public void testNotifyAsyncMetadata() throws Exception { | ||
MetaData metaData = new MetaData(); | ||
metaData.addToTab("animals", "dog", true); | ||
|
||
client.notify(new RuntimeException("Foo"), metaData); | ||
assertNull(apiClient.report); | ||
apiClient.nullCheckLatch.countDown(); | ||
|
||
apiClient.awaitReport(); | ||
assertNotNull(apiClient.report); | ||
MetaData data = apiClient.report.getError().getMetaData(); | ||
assertTrue((Boolean) data.getTab("animals").get("dog")); | ||
} | ||
|
||
@Test | ||
public void testNotifyAsyncSeverity() throws Exception { | ||
client.notify(new RuntimeException("Foo"), Severity.INFO); | ||
assertNull(apiClient.report); | ||
apiClient.nullCheckLatch.countDown(); | ||
|
||
apiClient.awaitReport(); | ||
assertNotNull(apiClient.report); | ||
assertEquals(Severity.INFO, apiClient.report.getError().getSeverity()); | ||
} | ||
|
||
@Test | ||
public void testNotifyAsyncSeverityMetadata() throws Exception { | ||
MetaData metaData = new MetaData(); | ||
metaData.addToTab("animals", "bird", "chicken"); | ||
|
||
client.notify(new RuntimeException("Foo"), Severity.ERROR, metaData); | ||
assertNull(apiClient.report); | ||
apiClient.nullCheckLatch.countDown(); | ||
|
||
apiClient.awaitReport(); | ||
assertNotNull(apiClient.report); | ||
MetaData data = apiClient.report.getError().getMetaData(); | ||
assertEquals("chicken", data.getTab("animals").get("bird")); | ||
assertEquals(Severity.ERROR, apiClient.report.getError().getSeverity()); | ||
} | ||
|
||
@Test | ||
public void testNotifyAsyncCallback() throws Exception { | ||
client.notify(new RuntimeException("Foo"), new Callback() { | ||
@Override | ||
public void beforeNotify(Report report) { | ||
report.getError().setContext("Manual"); | ||
} | ||
}); | ||
assertNull(apiClient.report); | ||
apiClient.nullCheckLatch.countDown(); | ||
|
||
apiClient.awaitReport(); | ||
assertNotNull(apiClient.report); | ||
assertEquals("Manual", apiClient.report.getError().getContext()); | ||
} | ||
|
||
static class NullCheckClient extends ClientNotifyTest.FakeClient { | ||
|
||
CountDownLatch nullCheckLatch = new CountDownLatch(1); | ||
|
||
@Override | ||
public void postReport(String urlString, | ||
Report report, | ||
Map<String, String> headers) | ||
throws NetworkException, BadResponseException { | ||
try { | ||
nullCheckLatch.await(100, TimeUnit.MILLISECONDS); | ||
} catch (InterruptedException exception) { | ||
exception.printStackTrace(); | ||
} | ||
super.postReport(urlString, report, headers); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.