1
1
package no.nav.personbruker.dittnav.common.util.config
2
2
3
+ import io.kotest.assertions.throwables.shouldThrow
4
+ import io.kotest.matchers.shouldBe
3
5
import io.mockk.every
4
6
import io.mockk.mockkObject
5
7
import io.mockk.unmockkObject
6
8
import no.nav.personbruker.dittnav.common.util.config.TypedEnvVar.getEnvVarAsType
7
9
import no.nav.personbruker.dittnav.common.util.config.TypedEnvVar.getEnvVarAsTypedList
8
10
import no.nav.personbruker.dittnav.common.util.config.TypedEnvVar.getOptionalEnvVarAsType
9
11
import no.nav.personbruker.dittnav.common.util.config.TypedEnvVar.getOptionalEnvVarAsTypedList
10
- import org.amshove.kluent.`should be equal to`
11
- import org.amshove.kluent.`should throw`
12
- import org.amshove.kluent.invoking
13
12
import org.junit.jupiter.api.AfterEach
14
13
import org.junit.jupiter.api.BeforeEach
15
14
import org.junit.jupiter.api.Test
16
- import java.lang .IllegalArgumentException
17
- import java.lang .IllegalStateException
15
+ import kotlin .IllegalArgumentException
16
+ import kotlin .IllegalStateException
18
17
19
18
internal class EnvVarAsTypeKtTest {
20
19
@@ -43,7 +42,7 @@ internal class EnvVarAsTypeKtTest {
43
42
44
43
val result = getEnvVarAsType(envName, default, String ::toInt)
45
44
46
- result `should be equal to` envVal
45
+ result shouldBe envVal
47
46
}
48
47
49
48
@Test
@@ -54,21 +53,25 @@ internal class EnvVarAsTypeKtTest {
54
53
55
54
val result = getEnvVarAsType(envName, default, String ::toInt)
56
55
57
- result `should be equal to` default
56
+ result shouldBe default
58
57
}
59
58
60
59
@Test
61
60
fun `Function getEnvVarAsType should throw exception if variable was not found and no default was specified` () {
62
61
every { SystemWrapper .getEnvVar(envName) } returns null
63
62
64
- invoking { getEnvVarAsType(envName, mapper = String ::toInt) } `should throw ` IllegalStateException ::class
63
+ shouldThrow<IllegalStateException > {
64
+ getEnvVarAsType(envName, mapper = String ::toInt)
65
+ }
65
66
}
66
67
67
68
@Test
68
69
fun `Function getEnvVarAsType should throw exception if variable could not be mapped` () {
69
70
every { SystemWrapper .getEnvVar(envName) } returns " onetwothree"
70
71
71
- invoking { getEnvVarAsType(envName, mapper = String ::toInt) } `should throw ` IllegalArgumentException ::class
72
+ shouldThrow<IllegalArgumentException > {
73
+ getEnvVarAsType(envName, mapper = String ::toInt)
74
+ }
72
75
}
73
76
74
77
@Test
@@ -79,7 +82,7 @@ internal class EnvVarAsTypeKtTest {
79
82
80
83
val result = getOptionalEnvVarAsType(envName, default, String ::toInt)
81
84
82
- result `should be equal to` envVal
85
+ result shouldBe envVal
83
86
}
84
87
85
88
@Test
@@ -90,7 +93,7 @@ internal class EnvVarAsTypeKtTest {
90
93
91
94
val result = getOptionalEnvVarAsType(envName, default, String ::toInt)
92
95
93
- result `should be equal to` default
96
+ result shouldBe default
94
97
}
95
98
96
99
@Test
@@ -99,14 +102,14 @@ internal class EnvVarAsTypeKtTest {
99
102
100
103
val result = getOptionalEnvVarAsType(envName, mapper = String ::toInt)
101
104
102
- result `should be equal to` null
105
+ result shouldBe null
103
106
}
104
107
105
108
@Test
106
109
fun `Function getOptionalEnvVarAsType should throw exception if variable could not be mapped` () {
107
110
every { SystemWrapper .getEnvVar(envName) } returns " onetwo"
108
111
109
- invoking { getEnvVarAsType(envName, mapper = String ::toInt) } `should throw ` IllegalArgumentException :: class
112
+ shouldThrow< IllegalArgumentException > { getEnvVarAsType(envName, mapper = String ::toInt) }
110
113
}
111
114
112
115
@Test
@@ -117,7 +120,7 @@ internal class EnvVarAsTypeKtTest {
117
120
118
121
val result = getEnvVarAsTypedList(envName, default, mapper = String ::toInt)
119
122
120
- result `should be equal to` listEnvVal
123
+ result shouldBe listEnvVal
121
124
}
122
125
123
126
@Test
@@ -128,21 +131,25 @@ internal class EnvVarAsTypeKtTest {
128
131
129
132
val result = getEnvVarAsTypedList(envName, default, mapper = String ::toInt)
130
133
131
- result `should be equal to` default
134
+ result shouldBe default
132
135
}
133
136
134
137
@Test
135
138
fun `Function getEnvVarAsTypedList should throw exception if variable was not found and no default was specified` () {
136
139
every { SystemWrapper .getEnvVar(envName) } returns null
137
140
138
- invoking { getEnvVarAsTypedList(envName, mapper = String ::toInt) } `should throw ` IllegalStateException ::class
141
+ shouldThrow<IllegalStateException > {
142
+ getEnvVarAsTypedList(envName, mapper = String ::toInt)
143
+ }
139
144
}
140
145
141
146
@Test
142
147
fun `Function getEnvVarAsTypedList should throw exception if variable could not be mapped` () {
143
148
every { SystemWrapper .getEnvVar(envName) } returns " one,two"
144
149
145
- invoking { getEnvVarAsTypedList(envName, mapper = String ::toInt) } `should throw ` IllegalArgumentException ::class
150
+ shouldThrow<IllegalArgumentException > {
151
+ getEnvVarAsTypedList(envName, mapper = String ::toInt)
152
+ }
146
153
}
147
154
148
155
@Test
@@ -153,7 +160,7 @@ internal class EnvVarAsTypeKtTest {
153
160
154
161
val expected = listOf (4 , 5 , 6 )
155
162
156
- getEnvVarAsTypedList(envName, separator = " |" , mapper = String ::toInt) `should be equal to` expected
163
+ getEnvVarAsTypedList(envName, separator = " |" , mapper = String ::toInt) shouldBe expected
157
164
}
158
165
159
166
@Test
@@ -164,7 +171,7 @@ internal class EnvVarAsTypeKtTest {
164
171
165
172
val result = getOptionalEnvVarAsTypedList(envName, default, mapper = String ::toInt)
166
173
167
- result `should be equal to` listEnvVal
174
+ result shouldBe listEnvVal
168
175
}
169
176
170
177
@Test
@@ -175,7 +182,7 @@ internal class EnvVarAsTypeKtTest {
175
182
176
183
val result = getOptionalEnvVarAsTypedList(envName, default, mapper = String ::toInt)
177
184
178
- result `should be equal to` default
185
+ result shouldBe default
179
186
}
180
187
181
188
@Test
@@ -184,14 +191,16 @@ internal class EnvVarAsTypeKtTest {
184
191
185
192
val result = getOptionalEnvVarAsTypedList(envName, mapper = String ::toInt)
186
193
187
- result `should be equal to` emptyList()
194
+ result shouldBe emptyList()
188
195
}
189
196
190
197
@Test
191
198
fun `Function getOptionalEnvVarAsTypedList should throw exception if variable could not be mapped` () {
192
199
every { SystemWrapper .getEnvVar(envName) } returns " one,two"
193
200
194
- invoking { getOptionalEnvVarAsTypedList(envName, mapper = String ::toInt) } `should throw ` IllegalArgumentException ::class
201
+ shouldThrow<IllegalArgumentException > {
202
+ getOptionalEnvVarAsTypedList(envName, mapper = String ::toInt)
203
+ }
195
204
}
196
205
197
206
@Test
@@ -202,6 +211,6 @@ internal class EnvVarAsTypeKtTest {
202
211
203
212
val expected = listOf (7 , 8 , 9 )
204
213
205
- getOptionalEnvVarAsTypedList(envName, separator = " |" , mapper = String ::toInt) `should be equal to` expected
214
+ getOptionalEnvVarAsTypedList(envName, separator = " |" , mapper = String ::toInt) shouldBe expected
206
215
}
207
- }
216
+ }
0 commit comments