@@ -3,7 +3,7 @@ package dev.hermannm.devlog
3
3
import dev.hermannm.devlog.testutils.Event
4
4
import dev.hermannm.devlog.testutils.EventType
5
5
import dev.hermannm.devlog.testutils.captureLogOutput
6
- import dev.hermannm.devlog.testutils.parameterizedTest
6
+ import dev.hermannm.devlog.testutils.runTestCases
7
7
import io.kotest.assertions.withClue
8
8
import io.kotest.matchers.booleans.shouldBeFalse
9
9
import io.kotest.matchers.booleans.shouldBeTrue
@@ -24,8 +24,8 @@ private val log = getLogger()
24
24
* - The [LogBuilder.field] method, which constructs the field in-place on the log event
25
25
*
26
26
* We want to test both of these, with a variety of different inputs. To do this systematically, we
27
- * make each log field test a parameterized test (see [parameterizedTest ]), so every test runs with
28
- * both ways of creating log fields.
27
+ * make each log field test a parameterized test (see [runTestCases ]), so every test runs with both
28
+ * ways of creating log fields.
29
29
*/
30
30
internal enum class LogFieldTestCase {
31
31
LOGBUILDER_METHOD ,
@@ -86,7 +86,7 @@ internal enum class RawJsonTestCase {
86
86
internal class LogFieldTest {
87
87
@Test
88
88
fun `basic log field test` () {
89
- parameterizedTest (LogFieldTestCase .entries) { test ->
89
+ runTestCases (LogFieldTestCase .entries) { test ->
90
90
val output = captureLogOutput {
91
91
log.info {
92
92
test.addField(this , " key" , " value" )
@@ -104,7 +104,7 @@ internal class LogFieldTest {
104
104
105
105
@Test
106
106
fun `log field with Serializable object` () {
107
- parameterizedTest (LogFieldTestCase .entries) { test ->
107
+ runTestCases (LogFieldTestCase .entries) { test ->
108
108
val event = Event (id = 1000 , type = EventType .ORDER_PLACED )
109
109
110
110
val output = captureLogOutput {
@@ -124,7 +124,7 @@ internal class LogFieldTest {
124
124
125
125
@Test
126
126
fun `multiple log fields` () {
127
- parameterizedTest (LogFieldTestCase .entries) { test ->
127
+ runTestCases (LogFieldTestCase .entries) { test ->
128
128
val output = captureLogOutput {
129
129
log.info {
130
130
test.addField(this , " first" , true )
@@ -144,7 +144,7 @@ internal class LogFieldTest {
144
144
145
145
@Test
146
146
fun `explicit serializer` () {
147
- parameterizedTest (LogFieldTestCase .entries) { test ->
147
+ runTestCases (LogFieldTestCase .entries) { test ->
148
148
val prefixSerializer =
149
149
object : SerializationStrategy <String > {
150
150
override val descriptor = String .serializer().descriptor
@@ -177,7 +177,7 @@ internal class LogFieldTest {
177
177
*/
178
178
@Test
179
179
fun `explicit serializer with nullable value` () {
180
- parameterizedTest (LogFieldTestCase .entries) { test ->
180
+ runTestCases (LogFieldTestCase .entries) { test ->
181
181
val event: Event ? = null
182
182
183
183
val output = captureLogOutput {
@@ -197,7 +197,7 @@ internal class LogFieldTest {
197
197
198
198
@Test
199
199
fun `explicit serializer falls back to toString on exception` () {
200
- parameterizedTest (LogFieldTestCase .entries) { test ->
200
+ runTestCases (LogFieldTestCase .entries) { test ->
201
201
val alwaysFailingSerializer =
202
202
object : SerializationStrategy <Event > {
203
203
override val descriptor = Event .serializer().descriptor
@@ -231,7 +231,7 @@ internal class LogFieldTest {
231
231
*/
232
232
@Test
233
233
fun `explicit serializer with nullable value does not call serializer` () {
234
- parameterizedTest (LogFieldTestCase .entries) { test ->
234
+ runTestCases (LogFieldTestCase .entries) { test ->
235
235
val alwaysFailingSerializer =
236
236
object : SerializationStrategy <String > {
237
237
override val descriptor = String .serializer().descriptor
@@ -269,7 +269,7 @@ internal class LogFieldTest {
269
269
*/
270
270
@Test
271
271
fun `custom serializer without reified type parameter` () {
272
- parameterizedTest (LogFieldTestCase .entries) { test ->
272
+ runTestCases (LogFieldTestCase .entries) { test ->
273
273
fun <T > genericLogFunction (obj : T , serializer : SerializationStrategy <T >) {
274
274
log.info {
275
275
test.addFieldWithSerializer(this , " object" , obj, serializer)
@@ -291,7 +291,7 @@ internal class LogFieldTest {
291
291
292
292
@Test
293
293
fun `non-serializable object falls back to toString` () {
294
- parameterizedTest (LogFieldTestCase .entries) { test ->
294
+ runTestCases (LogFieldTestCase .entries) { test ->
295
295
data class NonSerializableEvent (val id : Long , val type : String )
296
296
297
297
val event = NonSerializableEvent (id = 1000 , type = " ORDER_UPDATED" )
@@ -313,7 +313,7 @@ internal class LogFieldTest {
313
313
314
314
@Test
315
315
fun `duplicate field keys only includes the first field` () {
316
- parameterizedTest (LogFieldTestCase .entries) { test ->
316
+ runTestCases (LogFieldTestCase .entries) { test ->
317
317
val output = captureLogOutput {
318
318
log.info {
319
319
test.addField(this , " duplicateKey" , " value1" )
@@ -333,7 +333,7 @@ internal class LogFieldTest {
333
333
334
334
@Test
335
335
fun `null field value is allowed` () {
336
- parameterizedTest (LogFieldTestCase .entries) { test ->
336
+ runTestCases (LogFieldTestCase .entries) { test ->
337
337
val nullValue: String? = null
338
338
339
339
val output = captureLogOutput {
@@ -353,7 +353,7 @@ internal class LogFieldTest {
353
353
354
354
@Test
355
355
fun `raw JSON field works for valid JSON` () {
356
- parameterizedTest (RawJsonTestCase .entries) { test ->
356
+ runTestCases (RawJsonTestCase .entries) { test ->
357
357
val eventJson = """ {"id":1000,"type":"ORDER_UPDATED"}"""
358
358
359
359
// The above JSON should work both for validJson = true and validJson = false
@@ -378,7 +378,7 @@ internal class LogFieldTest {
378
378
379
379
@Test
380
380
fun `raw JSON field escapes invalid JSON by default` () {
381
- parameterizedTest (RawJsonTestCase .entries) { test ->
381
+ runTestCases (RawJsonTestCase .entries) { test ->
382
382
val invalidJson = """ {"id":1"""
383
383
384
384
val output = captureLogOutput {
@@ -403,7 +403,7 @@ internal class LogFieldTest {
403
403
*/
404
404
@Test
405
405
fun `raw JSON field does not escape invalid JSON when validJson is set to true` () {
406
- parameterizedTest (RawJsonTestCase .entries) { test ->
406
+ runTestCases (RawJsonTestCase .entries) { test ->
407
407
val invalidJson = """ {"id":1"""
408
408
409
409
val output = captureLogOutput {
@@ -423,7 +423,7 @@ internal class LogFieldTest {
423
423
424
424
@Test
425
425
fun `raw JSON field re-encodes JSON when it contains newlines` () {
426
- parameterizedTest (RawJsonTestCase .entries) { test ->
426
+ runTestCases (RawJsonTestCase .entries) { test ->
427
427
val jsonWithNewlines =
428
428
"""
429
429
{
@@ -486,7 +486,7 @@ internal class LogFieldTest {
486
486
487
487
@Test
488
488
fun `validateRawJson accepts valid JSON` () {
489
- parameterizedTest (validJsonTestCases) { validJson ->
489
+ runTestCases (validJsonTestCases) { validJson ->
490
490
val isValid: Boolean =
491
491
validateRawJson(
492
492
validJson,
@@ -514,7 +514,7 @@ internal class LogFieldTest {
514
514
515
515
@Test
516
516
fun `validateRawJson rejects invalid JSON` () {
517
- parameterizedTest (invalidJsonTestCases) { invalidJson ->
517
+ runTestCases (invalidJsonTestCases) { invalidJson ->
518
518
val isValid: Boolean =
519
519
validateRawJson(
520
520
invalidJson,
0 commit comments