11/*
2- * Copyright (C) 2023-2024 DiffPlug
2+ * Copyright (C) 2023-2025 DiffPlug
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1515 */
1616package com.diffplug.selfie.junit5
1717
18+ import java.util.logging.Level
19+ import java.util.logging.Logger
1820import org.junit.platform.engine.TestExecutionResult
1921import org.junit.platform.engine.support.descriptor.ClassSource
2022import org.junit.platform.engine.support.descriptor.MethodSource
@@ -24,12 +26,14 @@ import org.junit.platform.launcher.TestPlan
2426
2527/* * This is automatically registered at runtime thanks to `META-INF/services`. */
2628class SelfieTestExecutionListener : TestExecutionListener {
29+ private val logger: Logger = Logger .getLogger(SelfieTestExecutionListener ::class .java.name)
2730 private val system = SnapshotSystemJUnit5
2831 override fun executionStarted (testIdentifier : TestIdentifier ) {
2932 try {
3033 system.testListenerRunning.set(true )
3134 if (isRootOrKotest(testIdentifier)) return
32- val (clazz, test) = parseClassTest(testIdentifier)
35+ val parsed = parseClassTest(testIdentifier) ? : return
36+ val (clazz, test) = parsed
3337 val snapshotFile = system.forClass(clazz)
3438 if (test == null ) {
3539 snapshotFile.incrementContainers()
@@ -42,7 +46,8 @@ class SelfieTestExecutionListener : TestExecutionListener {
4246 }
4347 override fun executionSkipped (testIdentifier : TestIdentifier , reason : String ) {
4448 try {
45- val (clazz, test) = parseClassTest(testIdentifier)
49+ val parsed = parseClassTest(testIdentifier) ? : return
50+ val (clazz, test) = parsed
4651 if (test == null ) {
4752 system.forClass(clazz).incrementContainers()
4853 system.forClass(clazz).decrementContainersWithSuccess(false )
@@ -59,7 +64,8 @@ class SelfieTestExecutionListener : TestExecutionListener {
5964 ) {
6065 try {
6166 if (isRootOrKotest(testIdentifier)) return
62- val (clazz, test) = parseClassTest(testIdentifier)
67+ val parsed = parseClassTest(testIdentifier) ? : return
68+ val (clazz, test) = parsed
6369 val isSuccess = testExecutionResult.status == TestExecutionResult .Status .SUCCESSFUL
6470 val snapshotFile = system.forClass(clazz)
6571 if (test == null ) {
@@ -76,13 +82,16 @@ class SelfieTestExecutionListener : TestExecutionListener {
7682 }
7783 private fun isRootOrKotest (testIdentifier : TestIdentifier ) =
7884 testIdentifier.parentId.isEmpty || testIdentifier.uniqueId.startsWith(" [engine:kotest]" )
79- private fun parseClassTest (testIdentifier : TestIdentifier ): Pair <String , String ?> {
85+ private fun parseClassTest (testIdentifier : TestIdentifier ): Pair <String , String ?>? {
8086 return when (val source = testIdentifier.source.get()) {
8187 is ClassSource ->
8288 Pair (source.className, if (testIdentifier.isTest) testIdentifier.displayName else null )
8389 is MethodSource ->
8490 Pair (source.className, if (testIdentifier.isTest) source.methodName else null )
85- else -> throw AssertionError (" Unexpected source $source " )
91+ else -> {
92+ logger.log(Level .FINE , " Skipping unsupported source $source " )
93+ return null
94+ }
8695 }
8796 }
8897}
0 commit comments