Skip to content

Commit

Permalink
Merge 9f0658b into 7cc8a23
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Jun 28, 2018
2 parents 7cc8a23 + 9f0658b commit 72718d1
Show file tree
Hide file tree
Showing 24 changed files with 1,787 additions and 653 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.streamableToJson;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

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

private AppDataSummary appData;

/**
* Configures a new AppDataSummary for testing accessors + serialisation
*
* @throws Exception if setup failed
*/
@Before
public void setUp() throws Exception {
AppDataCollector appDataCollector = new AppDataCollector(generateClient());
appData = appDataCollector.generateAppDataSummary();
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

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

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

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

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

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

@Test
public void testJsonSerialisation() throws IOException, JSONException {
JSONObject appDataJson = streamableToJson(appData);
assertEquals(1, appDataJson.getInt("versionCode"));
assertEquals("1.0", appDataJson.get("version"));
assertEquals("development", appDataJson.get("releaseStage"));
assertEquals("android", appDataJson.get("type"));
}

}
93 changes: 71 additions & 22 deletions sdk/src/androidTest/java/com/bugsnag/android/AppDataTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.bugsnag.android;

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
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 android.support.annotation.NonNull;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -24,55 +28,100 @@
public class AppDataTest {

private Configuration config;

private AppData appData;
private AppDataCollector appDataCollector;

/**
* Configures a new AppData for testing accessors + serialisation
*
* @throws Exception if setup failed
*/
@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();
}

@After
public void tearDown() throws Exception {
Async.cancelTasks();
}

@Test
public void testManifestData() throws JSONException, IOException {
AppData appData = generateAppData();
public void testPackageName() {
assertEquals("com.bugsnag.android.test", appData.getPackageName());
String expected = "com.example.foo";
appData.setPackageName(expected);
assertEquals(expected, appData.getPackageName());
}

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

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

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

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

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

assertEquals("com.bugsnag.android.test", appDataJson.get("id"));
assertEquals("com.bugsnag.android.test", appDataJson.get("packageName"));
assertEquals("Bugsnag Android Tests", appDataJson.get("name"));
assertEquals(1, appDataJson.get("versionCode"));
assertEquals("1.0", appDataJson.get("versionName"));
assertEquals(1, appDataJson.getInt("versionCode"));
assertEquals("1.0", appDataJson.get("version"));
assertEquals("development", appDataJson.get("releaseStage"));

assertTrue(appDataJson.getLong("memoryUsage") > 0);
assertNotNull(appDataJson.getBoolean("lowMemory"));
assertTrue(appDataJson.getLong("duration") >= 0);
assertEquals("android", appDataJson.get("type"));
assertEquals("com.bugsnag.android.test", appDataJson.get("id"));
assertNotNull(appDataJson.get("buildUUID"));
assertNotNull(appDataJson.get("duration"));
assertNotNull(appDataJson.get("durationInForeground"));
assertFalse(appDataJson.getBoolean("inForeground"));
}

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

AppData appData = generateAppData();
JSONObject appDataJson = streamableToJson(appData);

assertEquals(appVersion, appDataJson.get("version"));
}

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

AppData appData = generateAppData();
JSONObject appDataJson = streamableToJson(appData);

assertEquals(releaseStage, appDataJson.get("releaseStage"));
}

@NonNull
private AppData generateAppData() {
return new AppData(InstrumentationRegistry.getContext(), config, generateSessionTracker());
}

}
107 changes: 107 additions & 0 deletions sdk/src/androidTest/java/com/bugsnag/android/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.getSharedPrefs;
import static com.bugsnag.android.BugsnagTestUtils.streamableToJson;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
Expand All @@ -19,6 +22,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Collection;
import java.util.Map;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -270,4 +274,107 @@ public void testApiClientNullValidation() {
generateClient().setSessionTrackingApiClient(null);
}

@Test
public void testClientUser() {
Client client = generateClient();
assertNotNull(client.getUser());
assertNotNull(client.getUser().getId());
}

@Test
public void testBreadcrumbGetter() {
Client client = generateClient();
Collection<Breadcrumb> breadcrumbs = client.getBreadcrumbs();

int breadcrumbCount = breadcrumbs.size();
client.leaveBreadcrumb("Foo");
assertEquals(breadcrumbCount, breadcrumbs.size()); // should not pick up new breadcrumbs
}

@Test
public void testBreadcrumbStoreNotModified() {
Client client = generateClient();
Collection<Breadcrumb> breadcrumbs = client.getBreadcrumbs();
int breadcrumbCount = client.breadcrumbs.store.size();

breadcrumbs.clear(); // only the copy should be cleared
assertTrue(breadcrumbs.isEmpty());
assertEquals(breadcrumbCount, client.breadcrumbs.store.size());
}

@Test
public void testAppData() {
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);
}

@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());
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"));
assertNotNull(app.get("lowMemory"));
}

@Test
public void testDeviceData() {
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);
}

@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"));
}
}

0 comments on commit 72718d1

Please sign in to comment.