GCX-HCI / ThirtyInch

a MVP library for Android favoring a stateful Presenter
Apache License 2.0
1.03k stars 101 forks source link

Convert LoggingInterceptorTest to Kotlin and MockK #179

Closed lukaszkalnik closed 5 years ago

lukaszkalnik commented 5 years ago

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.