Converts LoggingInterceptorTest in module thirtyinch-logginginterceptor to Kotlin and MockK.
There is a difference in behavior between Java and Kotlin regarding varargs.
Given a variadic (=varargs) method:
void variadicMethod(Object... args)
in Java you can pass a null array reference to such method as a single argument like this:
variadicMethod((Object[]) null).
However, Kotlin doesn't allow passing a null array reference to a variadic function.
Even with a variadic method signature (in Kotlin) allowing nullable types like this
fun variadicMethod(vararg args: Any?)
it gets compiled to the following equivalent Java code:
void variadicMethod(@NotNull Object... args)
So if you pass a null argument from Kotlin it always gets wrapped into a non-null Object[].
The test where the output differs between Java and Kotlin is in this case test log null varargs.
~Because of that and possible future changes to thirtyinch which might break Java compatibility somehow, I have decided to leave Java tests parallel with Kotlin tests. This way we can always ensure that the library works correctly both for Java and Kotlin consumers.~
Because of that I have left the differing test also in Java version in the LoggingInterceptorTestJava class in the java sourceSet. On second thought I don't think the effort of keeping duplicate test classes containing all tests both in Kotlin and Java is worthwhile. It should be enough to just add tests for differing cases.
Note: this PR doesn't depend on any previous test conversion PRs. It can be merged directly as a standalone PR, after it has been approved.
Converts
LoggingInterceptorTest
in modulethirtyinch-logginginterceptor
to Kotlin and MockK.There is a difference in behavior between Java and Kotlin regarding varargs.
Given a variadic (=varargs) method:
void variadicMethod(Object... args)
in Java you can pass anull
array reference to such method as a single argument like this:variadicMethod((Object[]) null)
. However, Kotlin doesn't allow passing anull
array reference to a variadic function. Even with a variadic method signature (in Kotlin) allowing nullable types like thisfun variadicMethod(vararg args: Any?)
it gets compiled to the following equivalent Java code:void variadicMethod(@NotNull Object... args)
So if you pass a null argument from Kotlin it always gets wrapped into a non-nullObject[]
. The test where the output differs between Java and Kotlin is in this casetest log null varargs
.~Because of that and possible future changes to
thirtyinch
which might break Java compatibility somehow, I have decided to leave Java tests parallel with Kotlin tests. This way we can always ensure that the library works correctly both for Java and Kotlin consumers.~Because of that I have left the differing test also in Java version in the
LoggingInterceptorTestJava
class in thejava
sourceSet. On second thought I don't think the effort of keeping duplicate test classes containing all tests both in Kotlin and Java is worthwhile. It should be enough to just add tests for differing cases.Note: this PR doesn't depend on any previous test conversion PRs. It can be merged directly as a standalone PR, after it has been approved.