Skip to content

Commit b30f58f

Browse files
committed
Resolve most Kotlin compiler warnings
1 parent 32c7275 commit b30f58f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

junit-jupiter-api/src/main/kotlin/org/junit/jupiter/api/Assertions.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import org.apiguardian.api.API.Status.STABLE
1717
import org.junit.jupiter.api.function.Executable
1818
import org.junit.jupiter.api.function.ThrowingSupplier
1919
import java.time.Duration
20-
import java.util.function.Supplier
2120
import java.util.stream.Stream
2221
import kotlin.contracts.ExperimentalContracts
2322
import kotlin.contracts.InvocationKind.AT_MOST_ONCE
@@ -43,7 +42,7 @@ fun fail(message: () -> String): Nothing {
4342
callsInPlace(message, EXACTLY_ONCE)
4443
}
4544

46-
return Assertions.fail(message)
45+
return Assertions.fail(message())
4746
}
4847

4948
/**
@@ -334,7 +333,7 @@ inline fun <reified T : Throwable> assertThrows(
334333
throw throwable
335334
}
336335
},
337-
Supplier(message)
336+
message
338337
)
339338
}
340339

@@ -404,18 +403,24 @@ inline fun <R> assertDoesNotThrow(
404403

405404
return Assertions.assertDoesNotThrow(
406405
evaluateAndWrap(executable),
407-
Supplier(message)
406+
message
408407
)
409408
}
410409

410+
@OptIn(ExperimentalContracts::class)
411411
@PublishedApi
412-
internal inline fun <R> evaluateAndWrap(executable: () -> R): ThrowingSupplier<R> =
413-
try {
412+
internal inline fun <R> evaluateAndWrap(executable: () -> R): ThrowingSupplier<R> {
413+
contract {
414+
callsInPlace(executable, EXACTLY_ONCE)
415+
}
416+
417+
return try {
414418
val result = executable()
415419
ThrowingSupplier { result }
416420
} catch (throwable: Throwable) {
417421
ThrowingSupplier { throw throwable }
418422
}
423+
}
419424

420425
/**
421426
* Example usage:

jupiter-tests/src/test/kotlin/org/junit/jupiter/params/aggregator/DisplayNameTests.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ object DisplayNameTests {
2121
@JvmStatic
2222
fun data() =
2323
arrayOf(
24-
arrayOf("A", 1),
25-
arrayOf("B", 2),
26-
arrayOf("C", 3),
27-
arrayOf("", 4), // empty is okay
28-
arrayOf(null, 5) // null was the problem
24+
arrayOf<Any>("A", 1),
25+
arrayOf<Any>("B", 2),
26+
arrayOf<Any>("C", 3),
27+
arrayOf<Any>("", 4), // empty is okay
28+
arrayOf<Any?>(null, 5) // null was the problem
2929
)
3030

3131
@ParameterizedTest

0 commit comments

Comments
 (0)