forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContextTest.java
More file actions
115 lines (87 loc) · 3.55 KB
/
ContextTest.java
File metadata and controls
115 lines (87 loc) · 3.55 KB
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
110
111
112
113
114
115
package io.sentry;
import io.sentry.context.Context;
import io.sentry.event.Breadcrumb;
import io.sentry.event.BreadcrumbBuilder;
import io.sentry.event.User;
import io.sentry.event.UserBuilder;
import org.testng.annotations.Test;
import java.util.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@Test(singleThreaded = true)
public class ContextTest extends BaseTest {
@Test
public void testBreadcrumbs() {
Context context = new Context();
assertThat(context.getBreadcrumbs(), equalTo(Collections.<Breadcrumb>emptyList()));
Breadcrumb breadcrumb = new BreadcrumbBuilder()
.setLevel(Breadcrumb.Level.INFO)
.setCategory("foo")
.setMessage("test")
.build();
context.recordBreadcrumb(breadcrumb);
List<Breadcrumb> breadcrumbMatch = new ArrayList<>();
breadcrumbMatch.add(breadcrumb);
assertThat(context.getBreadcrumbs(), equalTo(breadcrumbMatch));
context.clearBreadcrumbs();
assertThat(context.getBreadcrumbs(), equalTo(Collections.<Breadcrumb>emptyList()));
}
@Test
public void breadcrumbLimit() {
Context context = new Context(1);
Breadcrumb breadcrumb1 = new BreadcrumbBuilder()
.setLevel(Breadcrumb.Level.INFO)
.setCategory("foo")
.setMessage("test1")
.build();
Breadcrumb breadcrumb2 = new BreadcrumbBuilder()
.setLevel(Breadcrumb.Level.INFO)
.setCategory("foo")
.setMessage("test2")
.build();
context.recordBreadcrumb(breadcrumb1);
context.recordBreadcrumb(breadcrumb2);
List<Breadcrumb> breadcrumbMatch = new ArrayList<>();
breadcrumbMatch.add(breadcrumb2);
assertThat(context.getBreadcrumbs(), equalTo(breadcrumbMatch));
}
@Test
public void testUser() {
Context context = new Context();
User user = new UserBuilder()
.setEmail("test@example.com")
.setId("1234")
.setIpAddress("192.168.0.1")
.setUsername("testUser_123").build();
context.setUser(user);
assertThat(context.getUser(), equalTo(user));
context.clearUser();
assertThat(context.getUser(), equalTo(null));
}
@Test
public void testTags() {
Context context = new Context();
assertThat(context.getTags(), equalTo(Collections.<String, String>emptyMap()));
context.removeTag("nonExistant");
assertThat(context.getTags(), equalTo(Collections.<String, String>emptyMap()));
context.addTag("foo", "bar");
Map<String, String> matchingTags = new HashMap<>();
matchingTags.put("foo", "bar");
assertThat(context.getTags(), equalTo(matchingTags));
context.removeTag("foo");
assertThat(context.getTags(), equalTo(Collections.<String, String>emptyMap()));
}
@Test
public void testExtras() {
Context context = new Context();
assertThat(context.getExtra(), equalTo(Collections.<String, Object>emptyMap()));
context.removeExtra("nonExistant");
assertThat(context.getExtra(), equalTo(Collections.<String, Object>emptyMap()));
context.addExtra("foo", "bar");
Map<String, Object> matchingExtras = new HashMap<>();
matchingExtras.put("foo", "bar");
assertThat(context.getExtra(), equalTo(matchingExtras));
context.removeExtra("foo");
assertThat(context.getExtra(), equalTo(Collections.<String, Object>emptyMap()));
}
}