forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentryClientTest.java
More file actions
74 lines (59 loc) · 1.98 KB
/
Copy pathSentryClientTest.java
File metadata and controls
74 lines (59 loc) · 1.98 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
package net.kencochrane.sentry;
import mockit.Mocked;
import mockit.Expectations;
import mockit.Verifications;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class SentryClientTest {
public void triggerRuntimeException() {
try {
triggerNullPointer();
} catch (Exception e) {
throw new RuntimeException("Error triggering null pointer", e);
}
}
public String triggerNullPointer() {
String c = null;
return c.toLowerCase();
}
@Test(expected=RuntimeException.class)
public void testMissingDSN() {
RavenClient client = new RavenClient();
}
@Test
public void testConfigureFromDSN() {
RavenClient client = new RavenClient("http://public:secret@example.com/path/1");
assertEquals(client.getSentryDSN(), "http://public:secret@example.com/path/1");
}
@Test
public void testConfigureFromEnvironment() {
new Expectations()
{
@Mocked("getenv") System mockedSystem;
{
System.getenv("SENTRY_DSN"); returns("http://public:secret@example.com/path/1");
}
};
RavenClient client = new RavenClient();
assertEquals(client.getSentryDSN(), "http://public:secret@example.com/path/1");
}
@Test
public void testCaptureExceptionWithOnlyThrowable() {
RavenClient client = new RavenClient("http://public:secret@example.com/path/1");
new Expectations()
{
@Mocked("getRandomUUID") RavenUtils mockedRavenUtils;
{
RavenUtils.getRandomUUID(); returns("1234567890");
}
// TODO: this should be mocked, somehow
// RavenClient.sendMessage(); minTimes = 1; maxTimes = 1;
};
try {
triggerRuntimeException();
} catch (RuntimeException e) {
String ident = client.captureException(e);
assertEquals(ident, "1234567890");
}
}
}