forked from getsentry/sentry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackTest.kt
More file actions
93 lines (77 loc) · 2.54 KB
/
StackTest.kt
File metadata and controls
93 lines (77 loc) · 2.54 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
package io.sentry
import com.nhaarman.mockitokotlin2.mock
import io.sentry.Stack.StackItem
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
class StackTest {
private class Fixture {
val options = SentryOptions()
val client = mock<ISentryClient>()
val scope = Scope(options)
lateinit var rootItem: StackItem
fun getSut(rootItem: StackItem = StackItem(options, client, scope)): Stack {
this.rootItem = rootItem
return Stack(options.logger, rootItem)
}
fun createStackItem(scope: Scope = Scope(options)) =
StackItem(this.options, this.client, scope)
}
private val fixture = Fixture()
@Test
fun `stack after creation has single item`() {
val stack = fixture.getSut()
assertEquals(1, stack.size())
}
@Test
fun `pop() on single item stack does not remove item`() {
val stack = fixture.getSut()
stack.pop()
assertEquals(1, stack.size())
}
@Test
fun `push() adds item to stack`() {
val stack = fixture.getSut()
stack.push(mock())
assertEquals(2, stack.size())
}
@Test
fun `peek() returns last added item`() {
val stack = fixture.getSut()
val item = mock<StackItem>()
stack.push(item)
assertEquals(item, stack.peek())
}
@Test
fun `pop() removes last added item`() {
val stack = fixture.getSut()
val item = mock<StackItem>()
stack.push(item)
stack.pop()
assertEquals(fixture.rootItem, stack.peek())
}
@Test
fun `cloning stack clones stack items`() {
val stack = fixture.getSut(fixture.createStackItem(Scope(fixture.options).apply {
this.setTag("rootTag", "value")
}))
stack.push(fixture.createStackItem(Scope(fixture.options).apply {
this.setTag("childTag", "value")
}))
val clone = Stack(stack)
assertEquals(stack.size(), clone.size())
// assert first stack item
assertStackItems(stack.peek(), clone.peek())
stack.pop()
clone.pop()
// assert root item
assertStackItems(stack.peek(), clone.peek())
}
private fun assertStackItems(item1: StackItem, item2: StackItem) {
assertNotEquals(item1, item2)
assertNotEquals(item1.scope, item2.scope)
// assert that scope content is the same
assertEquals(item1.scope.tags, item2.scope.tags)
assertEquals(item1.client, item2.client)
}
}