-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathFingerprinterTest.java
More file actions
91 lines (79 loc) · 2.84 KB
/
FingerprinterTest.java
File metadata and controls
91 lines (79 loc) · 2.84 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
package com.datadog.debugger.exception;
import static java.util.Collections.emptySet;
import static org.junit.jupiter.api.Assertions.*;
import com.datadog.debugger.util.ClassNameFiltering;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class FingerprinterTest {
final Throwable TEST_THROWABLE = new RuntimeException("test");
{
TEST_THROWABLE.setStackTrace(
new StackTraceElement[] {
new StackTraceElement(
"com.datadog.debugger.exception.FingerprinterTest",
"<init>",
"FingerprinterTest.java",
10),
new StackTraceElement(
"org.junit.platform.commons.util.ReflectionUtils",
"newInstance",
"ReflectionUtils.java",
552),
new StackTraceElement(
"org.junit.jupiter.engine.execution.ConstructorInvocation",
"proceed",
"ConstructorInvocation.java",
56),
new StackTraceElement(
"org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation",
"proceed",
"InvocationInterceptorChain.java",
131),
});
}
final String TEST_FINGERPRINT = "2ec0db28f254ffa383cbb26a32269bf739ba937b9dd8f111d22294e6a494855";
final ClassNameFiltering classNameFiltering = new ClassNameFiltering(emptySet());
@Test
void basic() {
String fingerprint = Fingerprinter.fingerprint(TEST_THROWABLE, classNameFiltering);
assertEquals(TEST_FINGERPRINT, fingerprint);
}
@Test
void inner() {
Throwable t = new RuntimeException("outer", TEST_THROWABLE);
String fingerprint = Fingerprinter.fingerprint(t, classNameFiltering);
assertEquals(TEST_FINGERPRINT, fingerprint);
}
@Test
void innerInfiniteLoop() {
Exception outer = new RuntimeException("outer");
Exception innerCause1 = new RuntimeException("cause1", outer);
Exception innerCause2 = new RuntimeException("cause2", innerCause1);
outer.initCause(innerCause2);
Assertions.assertNull(Fingerprinter.fingerprint(outer, classNameFiltering));
}
@Test
void emptyStacktrace() {
assertEquals(
"843ff84fcbdc76707588c035f63b0e69b6f9b2c53f9a019ef4e5d1a2243778",
Fingerprinter.fingerprint(new EmptyException("test"), classNameFiltering));
}
@Test
void nullStacktrace() {
assertEquals(
"35ae5d9aa4d7179a7d36838ca6266ea459a7cbb6ebc92afc24098bc85cad586",
Fingerprinter.fingerprint(
new RuntimeException("test") {
@Override
public StackTraceElement[] getStackTrace() {
return null;
}
},
classNameFiltering));
}
static class EmptyException extends Exception {
public EmptyException(String message) {
super(message, null, false, false);
}
}
}