Skip to content

Commit

Permalink
Merge a11adf0 into 1f32b6d
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Jul 5, 2018
2 parents 1f32b6d + a11adf0 commit cd0b549
Show file tree
Hide file tree
Showing 24 changed files with 806 additions and 1,349 deletions.
@@ -1,6 +1,7 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.mapToJson;
import static com.bugsnag.android.BugsnagTestUtils.streamableToJson;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand All @@ -16,12 +17,13 @@
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.Map;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppDataSummaryTest {

private AppDataSummary appData;
private Map<String, Object> appData;

/**
* Configures a new AppDataSummary for testing accessors + serialisation
Expand All @@ -30,8 +32,8 @@ public class AppDataSummaryTest {
*/
@Before
public void setUp() throws Exception {
AppDataCollector appDataCollector = new AppDataCollector(generateClient());
appData = appDataCollector.generateAppDataSummary();
AppData appData = new AppData(generateClient());
this.appData = appData.getAppDataSummary();
}

@After
Expand All @@ -41,47 +43,32 @@ public void tearDown() throws Exception {

@Test
public void testVersionCode() {
assertEquals(Integer.valueOf(1), appData.getVersionCode());
int expected = 15;
appData.setVersionCode(expected);
assertEquals(Integer.valueOf(expected), appData.getVersionCode());
assertEquals(1, appData.get("versionCode"));
}

@Test
public void testVersionName() {
assertEquals("1.0", appData.getVersionName());
String expected = "1.2.3";
appData.setVersionName(expected);
assertEquals(expected, appData.getVersionName());
assertEquals("1.0", appData.get("version"));
}

@Test
public void testReleaseStage() {
assertEquals("development", appData.getReleaseStage());
String expected = "beta";
appData.setReleaseStage(expected);
assertEquals(expected, appData.getReleaseStage());
assertEquals("development", appData.get("releaseStage"));
}

@Test
public void testNotifierType() {
assertEquals("android", appData.getNotifierType());
String expected = "custom";
appData.setNotifierType(expected);
assertEquals(expected, appData.getNotifierType());
assertEquals("android", appData.get("type"));
}

@Test
public void testCodeBundleId() {
assertNull(appData.getCodeBundleId());
String expected = "123";
appData.setCodeBundleId(expected);
assertEquals(expected, appData.getCodeBundleId());
assertNull(appData.get("codeBundleId"));
}

@Test
public void testJsonSerialisation() throws IOException, JSONException {
JSONObject appDataJson = streamableToJson(appData);
public void testJsonSerialisation() throws JSONException {
JSONObject appDataJson = mapToJson(appData);
assertEquals(1, appDataJson.getInt("versionCode"));
assertEquals("1.0", appDataJson.get("version"));
assertEquals("development", appDataJson.get("releaseStage"));
Expand Down
54 changes: 18 additions & 36 deletions sdk/src/androidTest/java/com/bugsnag/android/AppDataTest.java
@@ -1,15 +1,13 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.generateSessionTracker;
import static com.bugsnag.android.BugsnagTestUtils.mapToJson;
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 android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
Expand All @@ -22,14 +20,15 @@
import org.junit.runner.RunWith;

import java.io.IOException;
import java.util.Map;

@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppDataTest {

private Configuration config;
private AppData appData;
private AppDataCollector appDataCollector;
private Map<String, Object> appData;
private Client client;

/**
* Configures a new AppData for testing accessors + serialisation
Expand All @@ -39,9 +38,8 @@ public class AppDataTest {
@Before
public void setUp() throws Exception {
config = new Configuration("some-api-key");
Client client = new Client(InstrumentationRegistry.getContext(), config);
appDataCollector = new AppDataCollector(client);
appData = appDataCollector.generateAppData();
client = new Client(InstrumentationRegistry.getContext(), config);
appData = new AppData(client).getAppData();
}

@After
Expand All @@ -51,47 +49,33 @@ public void tearDown() throws Exception {

@Test
public void testPackageName() {
assertEquals("com.bugsnag.android.test", appData.getPackageName());
String expected = "com.example.foo";
appData.setPackageName(expected);
assertEquals(expected, appData.getPackageName());
assertEquals("com.bugsnag.android.test", appData.get("packageName"));
}

@Test
public void testBuildUuid() {
assertNull(appData.getBuildUuid());
String expected = "fad4902f";
appData.setBuildUuid(expected);
assertEquals(expected, appData.getBuildUuid());
assertNull(appData.get("buildUUID"));
}

@Test
public void testDuration() {
assertTrue(appData.getDuration() > 0);
long expected = 1500;
appData.setDuration(expected);
assertEquals(expected, appData.getDuration());
assertTrue(((Long) appData.get("duration")) > 0);
}

@Test
public void testDurationInForeground() {
assertEquals(0, appData.getDurationInForeground());
long expected = 1500;
appData.setDurationInForeground(expected);
assertEquals(expected, appData.getDurationInForeground());
assertEquals(0L, appData.get("durationInForeground"));
}

@Test
public void testInForeground() {
assertFalse(appData.isInForeground());
appData.setInForeground(true);
assertTrue(appData.isInForeground());
assertFalse((Boolean) appData.get("inForeground"));
}

@Test
public void testJsonSerialisation() throws JSONException, IOException {
appData.setBuildUuid("fa54de");
JSONObject appDataJson = streamableToJson(appData);
public void testJsonSerialisation() throws JSONException {
appData.put("buildUUID", "fa54de");
JSONObject appDataJson = mapToJson(appData);

assertEquals(1, appDataJson.getInt("versionCode"));
assertEquals("1.0", appDataJson.get("version"));
Expand All @@ -105,22 +89,20 @@ public void testJsonSerialisation() throws JSONException, IOException {
}

@Test
public void testAppVersionOverride() throws JSONException, IOException {
public void testAppVersionOverride() throws JSONException {
String appVersion = "1.2.3";
config.setAppVersion(appVersion);
appData = appDataCollector.generateAppData();

JSONObject appDataJson = streamableToJson(appData);
JSONObject appDataJson = mapToJson(client.appData.getAppData());
assertEquals(appVersion, appDataJson.get("version"));
}

@Test
public void testReleaseStageOverride() throws JSONException, IOException {
public void testReleaseStageOverride() throws JSONException {
String releaseStage = "test-stage";
config.setReleaseStage(releaseStage);
appData = appDataCollector.generateAppData();

JSONObject appDataJson = streamableToJson(appData);
JSONObject appDataJson = mapToJson(client.appData.getAppData());
assertEquals(releaseStage, appDataJson.get("releaseStage"));
}

Expand Down
Expand Up @@ -26,6 +26,10 @@ private static String streamableToString(JsonStream.Streamable streamable) throw
return writer.toString();
}

static JSONObject mapToJson(Map<String, Object> map) {
return new JSONObject(map);
}

static JSONObject streamableToJson(JsonStream.Streamable streamable)
throws JSONException, IOException {
return new JSONObject(streamableToString(streamable));
Expand Down
75 changes: 24 additions & 51 deletions sdk/src/androidTest/java/com/bugsnag/android/ClientTest.java
Expand Up @@ -303,78 +303,51 @@ public void testBreadcrumbStoreNotModified() {
}

@Test
public void testAppData() {
public void testAppDataCollection() {
Client client = generateClient();
AppData appData = client.getAppData();
assertNotNull(appData);
assertNotEquals(client.appData, appData);
assertNotEquals(client.getAppData(), appData);
}

@Test
public void testAppDataSummary() {
Client client = generateClient();
AppDataSummary appData = client.getAppDataSummary();
assertNotNull(appData);
assertNotEquals(client.getAppDataSummary(), appData);
assertEquals(client.getAppData(), appData);
}

@Test
public void testAppDataMetaData() {
Client client = generateClient();
MetaData metaData = new MetaData();
Map<String, Object> app = metaData.getTab("app");
assertEquals(0, app.size());

client.populateAppMetaData(metaData);
assertEquals(5, app.size());
Map<String, Object> app = client.getAppData().getAppDataMetaData();
assertEquals(6, app.size());
assertEquals("Bugsnag Android Tests", app.get("name"));
assertEquals("com.bugsnag.android.test", app.get("packageName"));
assertEquals("1.0", app.get("versionName"));
assertNotNull(app.get("memoryUsage"));
assertTrue(app.containsKey("activeScreen"));
assertNotNull(app.get("lowMemory"));
}

@Test
public void testDeviceData() {
public void testDeviceDataCollection() {
Client client = generateClient();
DeviceData deviceData = client.getDeviceData();
assertNotNull(deviceData);
assertNotEquals(client.deviceData, deviceData);
assertNotEquals(client.getDeviceData(), deviceData);
}

@Test
public void testDeviceDataSummary() {
Client client = generateClient();
DeviceDataSummary deviceData = client.getDeviceDataSummary();
assertNotNull(deviceData);
assertNotEquals(client.getDeviceDataSummary(), deviceData);
assertEquals(client.getDeviceData(), deviceData);
}

@Test
public void testPopulateDeviceMetadata() {
Client client = generateClient();
MetaData metaData = new MetaData();
Map<String, Object> app = metaData.getTab("device");
assertEquals(0, app.size());

client.populateDeviceMetaData(metaData);
assertEquals(14, app.size());

assertNotNull(app.get("batteryLevel"));
assertNotNull(app.get("charging"));
assertNotNull(app.get("locationStatus"));
assertNotNull(app.get("networkAccess"));
assertNotNull(app.get("time"));
assertNotNull(app.get("brand"));
assertNotNull(app.get("apiLevel"));
assertNotNull(app.get("osBuild"));
assertNotNull(app.get("locale"));
assertNotNull(app.get("screenDensity"));
assertNotNull(app.get("dpi"));
assertNotNull(app.get("emulator"));
assertNotNull(app.get("screenResolution"));
assertNotNull(app.get("cpuAbi"));
Map<String, Object> metaData = client.getDeviceData().getDeviceMetaData();

assertEquals(14, metaData.size());
assertNotNull(metaData.get("batteryLevel"));
assertNotNull(metaData.get("charging"));
assertNotNull(metaData.get("locationStatus"));
assertNotNull(metaData.get("networkAccess"));
assertNotNull(metaData.get("time"));
assertNotNull(metaData.get("brand"));
assertNotNull(metaData.get("apiLevel"));
assertNotNull(metaData.get("osBuild"));
assertNotNull(metaData.get("locale"));
assertNotNull(metaData.get("screenDensity"));
assertNotNull(metaData.get("dpi"));
assertNotNull(metaData.get("emulator"));
assertNotNull(metaData.get("screenResolution"));
assertNotNull(metaData.get("cpuAbi"));
}
}

0 comments on commit cd0b549

Please sign in to comment.