From 7581738796675d732d0b1acdf3ed692cdbdb1d53 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Sat, 24 Mar 2018 16:42:37 +0000 Subject: [PATCH 1/7] improve code coverage for report + notifier classes --- .../java/com/bugsnag/android/ReportTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java index 37650ff248..3a81d1bc12 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java @@ -50,4 +50,26 @@ public void testModifyingGroupingHash() throws JSONException, IOException { JSONObject event = events.getJSONObject(0); assertEquals(groupingHash, event.getString("groupingHash")); } + + @Test + public void testModifyReportDetails() throws Exception { + String apiKey = "custom-api-key"; + String notifierName = "React Native"; + String notifierURL = "https://bugsnag.com/reactnative"; + String notifierVersion = "3.4.5"; + + report.setApiKey(apiKey); + report.setNotifierName(notifierName); + report.setNotifierURL(notifierURL); + report.setNotifierVersion(notifierVersion); + + JSONObject reportJson = streamableToJson(report); + assertEquals(apiKey, reportJson.getString("apiKey")); + + JSONObject notifier = reportJson.getJSONObject("notifier"); + assertEquals(notifierName, notifier.getString("name")); + assertEquals(notifierVersion, notifier.getString("version")); + assertEquals(notifierURL, notifier.getString("url")); + } + } From 0f5b8a90c7ea290f820a5d92dfe9cfed7041c729 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Sat, 24 Mar 2018 17:03:18 +0000 Subject: [PATCH 2/7] appease the checkstyle gods --- .../androidTest/java/com/bugsnag/android/ReportTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java index 3a81d1bc12..a447bd82b7 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ReportTest.java @@ -55,12 +55,12 @@ public void testModifyingGroupingHash() throws JSONException, IOException { public void testModifyReportDetails() throws Exception { String apiKey = "custom-api-key"; String notifierName = "React Native"; - String notifierURL = "https://bugsnag.com/reactnative"; + String notifierUrl = "https://bugsnag.com/reactnative"; String notifierVersion = "3.4.5"; report.setApiKey(apiKey); report.setNotifierName(notifierName); - report.setNotifierURL(notifierURL); + report.setNotifierURL(notifierUrl); report.setNotifierVersion(notifierVersion); JSONObject reportJson = streamableToJson(report); @@ -69,7 +69,7 @@ public void testModifyReportDetails() throws Exception { JSONObject notifier = reportJson.getJSONObject("notifier"); assertEquals(notifierName, notifier.getString("name")); assertEquals(notifierVersion, notifier.getString("version")); - assertEquals(notifierURL, notifier.getString("url")); + assertEquals(notifierUrl, notifier.getString("url")); } } From da55f24c4abbe7cee0df028b526899927ebae8b6 Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Mon, 26 Mar 2018 18:28:34 +0100 Subject: [PATCH 3/7] Add coverage for metadata clearTab serialisation (#278) --- .../java/com/bugsnag/android/MetaDataTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sdk/src/androidTest/java/com/bugsnag/android/MetaDataTest.java b/sdk/src/androidTest/java/com/bugsnag/android/MetaDataTest.java index d6be1be989..d2f592d528 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/MetaDataTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/MetaDataTest.java @@ -3,6 +3,7 @@ import static com.bugsnag.android.BugsnagTestUtils.streamableToJson; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.support.test.filters.SmallTest; @@ -233,4 +234,13 @@ public void testFilterMetadataOverride() throws Exception { client.setMetaData(data); assertArrayEquals(new String[]{"CUSTOM"}, data.getFilters()); } + + @Test + public void testClearTab() throws Exception { + MetaData metaData = new MetaData(); + metaData.addToTab("example", "string", "value"); + metaData.clearTab("example"); + JSONObject json = streamableToJson(metaData); + assertFalse(json.has("example")); + } } From 06627c89191b94ade76440a4e240e121d74580a1 Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Mon, 26 Mar 2018 18:30:02 +0100 Subject: [PATCH 4/7] Add coverage for public methods in client (misc setters/getters) (#280) --- .../com/bugsnag/android/ClientConfigTest.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 sdk/src/androidTest/java/com/bugsnag/android/ClientConfigTest.java diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ClientConfigTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ClientConfigTest.java new file mode 100644 index 0000000000..875a1d571c --- /dev/null +++ b/sdk/src/androidTest/java/com/bugsnag/android/ClientConfigTest.java @@ -0,0 +1,89 @@ +package com.bugsnag.android; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +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 ClientConfigTest { + + private Configuration config; + private Client client; + + /** + * 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 { + Context context = InstrumentationRegistry.getContext(); + config = new Configuration("api-key"); + client = new Client(context, config); + } + + @Test + public void testSetReleaseStage() throws Exception { + client.setReleaseStage("beta"); + assertEquals("beta", config.getReleaseStage()); + } + + @Test + public void testSetAutoCaptureSessions() throws Exception { + client.setAutoCaptureSessions(true); + assertEquals(true, config.shouldAutoCaptureSessions()); + } + + @Test + public void testSetAppVersion() throws Exception { + client.setAppVersion("5.6.7"); + assertEquals("5.6.7", config.getAppVersion()); + } + + @Test + public void testSetContext() throws Exception { + client.setContext("JunitTest"); + assertEquals("JunitTest", client.getContext()); + assertEquals("JunitTest", config.getContext()); + } + + @Test + public void testSetEndpoint() throws Exception { + client.setEndpoint("http://example.com/bugsnag"); + assertEquals("http://example.com/bugsnag", config.getEndpoint()); + } + + @Test + public void testSetBuildUuid() throws Exception { + client.setBuildUUID("gh905"); + assertEquals("gh905", config.getBuildUUID()); + } + + @Test + public void testSetIgnoreClasses() throws Exception { + client.setIgnoreClasses("RuntimeException", "Foo"); + assertArrayEquals(new String[]{"RuntimeException", "Foo"}, config.getIgnoreClasses()); + } + + @Test + public void testSetNotifyReleaseStages() throws Exception { + client.setNotifyReleaseStages("beta", "prod"); + assertArrayEquals(new String[]{"beta", "prod"}, config.getNotifyReleaseStages()); + } + + @Test + public void testSetSendThreads() throws Exception { + client.setSendThreads(false); + assertFalse(config.getSendThreads()); + } + +} From e4af846fb92fd5d0e6676cac27cee09cb51c8fb5 Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Mon, 26 Mar 2018 18:33:53 +0100 Subject: [PATCH 5/7] tests: Improve code coverage in Error class (#277) --- .../java/com/bugsnag/android/ErrorTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java index 66161f5b91..3e9e5c4eb8 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ErrorTest.java @@ -1,13 +1,17 @@ package com.bugsnag.android; import static com.bugsnag.android.BugsnagTestUtils.generateSession; +import static com.bugsnag.android.BugsnagTestUtils.generateSessionTracker; import static com.bugsnag.android.BugsnagTestUtils.streamableToJson; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import android.content.Context; +import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; @@ -264,6 +268,85 @@ public void checkExceptionMessageNullity() throws Exception { assertEquals("", err.getExceptionMessage()); } + @Test + public void testNullSeverity() throws Exception { + error.setSeverity(null); + assertEquals(Severity.WARNING, error.getSeverity()); + } + + @Test + public void testSendThreadsDisabled() throws Exception { + config.setSendThreads(false); + JSONObject errorJson = streamableToJson(error); + assertFalse(errorJson.has("threads")); + } + + @Test + public void testBugsnagExceptionName() throws Exception { + BugsnagException exception = new BugsnagException("Busgang", "exceptional", + new StackTraceElement[]{}); + Error err = new Error.Builder(config, exception, null).build(); + assertEquals("Busgang", err.getExceptionName()); + } + + @Test + public void testConfigContext() throws Exception { + String expected = "Junit test suite"; + error.setContext(null); + config.setContext(expected); + assertEquals(expected, error.getContext()); + } + + @Test + public void testNullContext() throws Exception { + error.setContext(null); + error.setAppData(null); + assertNull(error.getContext()); + } + + @Test + public void testAppDataContext() throws Exception { + error.setContext(null); + Context context = InstrumentationRegistry.getContext(); + SessionTracker sessionTracker = generateSessionTracker(); + String expectedContext = "FooActivity"; + sessionTracker.updateForegroundTracker(expectedContext, + true, System.currentTimeMillis()); + error.setAppData(new AppData(context, config, sessionTracker)); + assertEquals(expectedContext, error.getContext()); + } + + + @Test + public void testSetUser() throws Exception { + String firstId = "123"; + String firstEmail = "fake@example.com"; + String firstName = "Bob Swaggins"; + error.setUser(firstId, firstEmail, firstName); + + assertEquals(firstId, error.getUser().getId()); + assertEquals(firstEmail, error.getUser().getEmail()); + assertEquals(firstName, error.getUser().getName()); + + String userId = "foo"; + error.setUserId(userId); + assertEquals(userId, error.getUser().getId()); + assertEquals(firstEmail, error.getUser().getEmail()); + assertEquals(firstName, error.getUser().getName()); + + String userEmail = "another@example.com"; + error.setUserEmail(userEmail); + assertEquals(userId, error.getUser().getId()); + assertEquals(userEmail, error.getUser().getEmail()); + assertEquals(firstName, error.getUser().getName()); + + String userName = "Isaac"; + error.setUserName(userName); + assertEquals(userId, error.getUser().getId()); + assertEquals(userEmail, error.getUser().getEmail()); + assertEquals(userName, error.getUser().getName()); + } + private void validateEmptyAttributes(JSONObject severityReason) { try { severityReason.getJSONObject("attributes"); From 35d6339343b4dada365963a3005726e829385328 Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Mon, 26 Mar 2018 18:34:51 +0100 Subject: [PATCH 6/7] tests: Test misc setters/getters in public methods in configuration (#279) --- .../bugsnag/android/ConfigurationTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/sdk/src/androidTest/java/com/bugsnag/android/ConfigurationTest.java b/sdk/src/androidTest/java/com/bugsnag/android/ConfigurationTest.java index ba78b03d5f..ddf1c0ad18 100644 --- a/sdk/src/androidTest/java/com/bugsnag/android/ConfigurationTest.java +++ b/sdk/src/androidTest/java/com/bugsnag/android/ConfigurationTest.java @@ -1,5 +1,6 @@ package com.bugsnag.android; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -89,6 +90,10 @@ public void testInProject() { // Shouldn't be inProject if class not in projectPackages config.setProjectPackages(new String[]{"com.bugsnag.android"}); assertFalse(config.inProject("java.io.IOException")); + + // Should be inProject if class is in projectPackages with null element + config.setProjectPackages(new String[]{null, "java.io.IOException"}); + assertTrue(config.inProject("java.io.IOException")); } @Test @@ -124,4 +129,39 @@ public void testSessionApiHeaders() throws Exception { assertNotNull(headers.get("Bugsnag-Payload-Version")); } + @Test + public void testOverrideContext() throws Exception { + config.setContext("LevelOne"); + assertEquals("LevelOne", config.getContext()); + } + + @Test + public void testOverrideFilters() throws Exception { + config.setFilters(new String[]{"Foo"}); + assertArrayEquals(new String[]{"Foo"}, config.getFilters()); + } + + @Test + public void testOverrideIgnoreClasses() throws Exception { + config.setIgnoreClasses(new String[]{"Bar"}); + assertArrayEquals(new String[]{"Bar"}, config.getIgnoreClasses()); + } + + @Test + public void testOverrideNotifyReleaseStages() throws Exception { + config.setNotifyReleaseStages(new String[]{"Test"}); + assertArrayEquals(new String[]{"Test"}, config.getNotifyReleaseStages()); + } + + @Test + public void testOverrideNotifierType() throws Exception { + config.setNotifierType("React Native"); + assertEquals("React Native", config.getNotifierType()); + } + + @Test + public void testOverrideCodeBundleId() throws Exception { + config.setCodeBundleId("abc123"); + assertEquals("abc123", config.getCodeBundleId()); + } } From ac2a1dbc56605e84ce9cd3f37cf06dbc3d5b0715 Mon Sep 17 00:00:00 2001 From: Delisa Mason Date: Tue, 3 Apr 2018 14:50:03 -0700 Subject: [PATCH 7/7] Release v4.3.3 --- CHANGELOG.md | 9 +++++++++ gradle.properties | 2 +- sdk/src/main/java/com/bugsnag/android/Notifier.java | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8336437fed..70a1a51d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 4.3.3 (2018-04-04) + +### Bug fixes + +* Prevent duplicate reports being delivered in low connectivity situations + [#270](https://github.com/bugsnag/bugsnag-android/pull/270) +* Fix possible NPE when reading default metadata filters + [#263](https://github.com/bugsnag/bugsnag-android/pull/263) + ## 4.3.2 (2018-03-09) ### Bug fixes diff --git a/gradle.properties b/gradle.properties index fd51f85366..df80939f92 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=4.3.2 +VERSION_NAME=4.3.3 GROUP=com.bugsnag POM_SCM_URL=https://github.com/bugsnag/bugsnag-android POM_SCM_CONNECTION=scm:git@github.com:bugsnag/bugsnag-android.git diff --git a/sdk/src/main/java/com/bugsnag/android/Notifier.java b/sdk/src/main/java/com/bugsnag/android/Notifier.java index f58c841380..f31616b938 100644 --- a/sdk/src/main/java/com/bugsnag/android/Notifier.java +++ b/sdk/src/main/java/com/bugsnag/android/Notifier.java @@ -9,7 +9,7 @@ */ public class Notifier implements JsonStream.Streamable { static final String NOTIFIER_NAME = "Android Bugsnag Notifier"; - static final String NOTIFIER_VERSION = "4.3.2"; + static final String NOTIFIER_VERSION = "4.3.3"; static final String NOTIFIER_URL = "https://bugsnag.com"; private String name; private String version;