Skip to content

Commit 77a0128

Browse files
committed
test: basic tests
1 parent de5b8c2 commit 77a0128

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

.editorconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ insert_final_newline = true
88
[*.md]
99
trim_trailing_whitespace = false
1010

11-
[*.{java,kt,kts}]
11+
[*.java]
12+
indent_size = 2
13+
charset = utf-8
14+
15+
[*.{kt,kts}]
1216
indent_size = 4
1317
charset = utf-8
1418

sentry-core/src/main/java/io/sentry/NoOpSentryClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import java.util.UUID;
44

55
class NoOpSentryClient implements ISentryClient {
6+
7+
private static final UUID emptyId = UUID.fromString("00000000-0000-0000-0000-000000000000");
8+
69
@Override
710
public boolean isEnabled() {
811
return false;
912
}
1013

1114
@Override
1215
public UUID captureEvent(SentryEvent event) {
13-
return UUID.fromString("00000000-0000-0000-0000-000000000000");
16+
return emptyId;
1417
}
1518

1619
@Override
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.sentry
2+
3+
import java.util.UUID
4+
import kotlin.test.Test
5+
import kotlin.test.assertFalse
6+
import kotlin.test.assertEquals
7+
8+
class NoOpSentryClientTest {
9+
private var sut: NoOpSentryClient = NoOpSentryClient()
10+
11+
@Test
12+
fun `client is always disabled`() = assertFalse(sut.isEnabled)
13+
14+
@Test
15+
fun `captureEvent is returns empty UUID`() =
16+
assertEquals(UUID.fromString("00000000-0000-0000-0000-000000000000"), sut.captureEvent(null))
17+
18+
@Test
19+
fun `close does not affect captureEvent`() {
20+
sut.close()
21+
assertEquals(UUID.fromString("00000000-0000-0000-0000-000000000000"), sut.captureEvent(null))
22+
}
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.sentry
2+
3+
// Legacy DSN includes a secret. Sentry 8 and older will require it.
4+
const val dsnStringLegacy: String = "https://d4d82fc1c2c4032a83f3a29aa3a3aff:[email protected]:65535/2147483647"
5+
const val dsnString: String = "https://[email protected]:65535/2147483647"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package io.sentry
2+
3+
import kotlin.test.Test
4+
import kotlin.test.assertFalse
5+
import kotlin.test.Ignore
6+
import kotlin.test.assertTrue
7+
8+
class SentryClientTest {
9+
10+
class Fixture {
11+
var sentryOptions: SentryOptions = SentryOptions().apply {
12+
dsn = dsnString
13+
}
14+
fun getSut() = SentryClient(sentryOptions)
15+
}
16+
17+
private val fixture: Fixture = Fixture()
18+
19+
@Test
20+
fun `when fixture is unchanged, client is enabled`() {
21+
val sut = fixture.getSut()
22+
assertTrue(sut.isEnabled)
23+
}
24+
25+
@Test
26+
@Ignore("Not implemented")
27+
fun `when dsn is an invalid string, client is disabled`() {
28+
fixture.sentryOptions.dsn = "invalid-dsn"
29+
val sut = fixture.getSut()
30+
assertFalse(sut.isEnabled)
31+
}
32+
33+
@Test
34+
@Ignore("Not implemented")
35+
fun `when dsn is null, client is disabled`() {
36+
fixture.sentryOptions.dsn = null
37+
val sut = fixture.getSut()
38+
assertFalse(sut.isEnabled)
39+
}
40+
41+
@Test
42+
fun `when dsn without private key is valid, client is enabled`() {
43+
fixture.sentryOptions.dsn = dsnString
44+
val sut = fixture.getSut()
45+
assertTrue(sut.isEnabled)
46+
}
47+
48+
@Test
49+
fun `when dsn with secret is valid, client is enabled`() {
50+
fixture.sentryOptions.dsn = dsnStringLegacy
51+
val sut = fixture.getSut()
52+
assertTrue(sut.isEnabled)
53+
}
54+
55+
@Test
56+
fun `when client is closed, client gets disabled`() {
57+
val sut = fixture.getSut()
58+
assertTrue(sut.isEnabled)
59+
sut.close()
60+
assertFalse(sut.isEnabled)
61+
}
62+
}

0 commit comments

Comments
 (0)