-
Notifications
You must be signed in to change notification settings - Fork 205
/
AppDataTest.java
109 lines (89 loc) · 3.23 KB
/
AppDataTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.bugsnag.android;
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.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;
import java.io.IOException;
import java.util.Map;
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppDataTest {
private Configuration config;
private Map<String, Object> appData;
private Client client;
/**
* 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 = new Client(InstrumentationRegistry.getContext(), config);
appData = new AppData(client).getAppData();
}
@After
public void tearDown() throws Exception {
Async.cancelTasks();
}
@Test
public void testPackageName() {
assertEquals("com.bugsnag.android.test", appData.get("packageName"));
}
@Test
public void testBuildUuid() {
assertNull(appData.get("buildUUID"));
}
@Test
public void testDuration() {
assertTrue(((Long) appData.get("duration")) > 0);
}
@Test
public void testDurationInForeground() {
assertEquals(0L, appData.get("durationInForeground"));
}
@Test
public void testInForeground() {
assertFalse((Boolean) appData.get("inForeground"));
}
@Test
public void testJsonSerialisation() throws JSONException {
appData.put("buildUUID", "fa54de");
JSONObject appDataJson = mapToJson(appData);
assertEquals(1, appDataJson.getInt("versionCode"));
assertEquals("1.0", appDataJson.get("version"));
assertEquals("development", appDataJson.get("releaseStage"));
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 {
String appVersion = "1.2.3";
config.setAppVersion(appVersion);
JSONObject appDataJson = mapToJson(client.appData.getAppData());
assertEquals(appVersion, appDataJson.get("version"));
}
@Test
public void testReleaseStageOverride() throws JSONException {
String releaseStage = "test-stage";
config.setReleaseStage(releaseStage);
JSONObject appDataJson = mapToJson(client.appData.getAppData());
assertEquals(releaseStage, appDataJson.get("releaseStage"));
}
}