Fix some Kotlin compiler warnings
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 7 Sep 2017 18:56:46 +0000 (20:56 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Sep 2017 18:40:43 +0000 (20:40 +0200)
src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt
src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt
src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt
src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt
src/test/kotlin/net/pterodactylus/sone/test/Guice.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt

index 3c0e77c..d01aeb4 100644 (file)
@@ -31,8 +31,8 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke
                        return (size > 2097152) || (!mimeType.startsWith("image/") && !mimeType.startsWith("text/html"))
                }
 
-               override fun loaded(uri: FreenetURI, mimeType: String, data: ByteArray) {
-                       MimeType(mimeType).also { mimeType ->
+               override fun loaded(uri: FreenetURI, mimeTypeText: String, data: ByteArray) {
+                       MimeType(mimeTypeText).also { mimeType ->
                                when {
                                        mimeType.primaryType == "image" -> {
                                                ByteArrayInputStream(data).use {
index 9872d1e..853fe26 100644 (file)
@@ -30,7 +30,7 @@ class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: E
        }
 
        override fun createJsonObject(request: FreenetRequest) =
-                       (webInterface.getCurrentSoneWithoutCreatingSession(request.toadletContext) as Sone?).let { currentSone ->
+                       webInterface.getCurrentSoneWithoutCreatingSession(request.toadletContext).let { currentSone ->
                                createSuccessJsonObject().apply {
                                        this["loggedIn"] = currentSone != null
                                        this["options"] = currentSone?.options?.toJsonOptions() ?: jsonObject {}
index dfed710..aa38f88 100644 (file)
@@ -104,9 +104,8 @@ abstract class SoneCommandTest {
                                ("Field." + this["${prefix}Field.$it.Name"]) to this["${prefix}Field.$it.Value"]
                        }
 
-       private fun SimpleFieldSet.parseFromSimpleFieldSet(prefix: String, vararg fields: String) = listOf(*fields)
-                       .map { it to (get(prefix + it) as String?) }
-                       .toMap()
+       private fun SimpleFieldSet.parseFromSimpleFieldSet(prefix: String, vararg fields: String): Map<String, String?> = fields
+                       .associate { it to get(prefix + it) }
 
        protected fun matchesPost(post: Post) = OneByOneMatcher<Map<String, String?>>().apply {
                expect("ID", post.id) { it["ID"] }
index 0f8ba83..2fe40d4 100644 (file)
@@ -58,6 +58,7 @@ class SoneAccessorTest {
                assertThat(accessor.get(templateContext, sone, member), equalTo(expected))
        }
 
+       @Suppress("UNCHECKED_CAST")
        private fun <T : Any> assertAccessorReturnValueMatches(member: String, matcher: Matcher<in T>) {
                assertThat(accessor.get(templateContext, sone, member) as T, matcher)
        }
index d8a2d32..f5f52b8 100644 (file)
@@ -5,7 +5,6 @@ import com.google.inject.Module
 import javax.inject.Provider
 import kotlin.reflect.KClass
 
-fun <T : Any> KClass<T>.isInstance(instance: T) = Module { it.bind(this.java).toInstance(instance) }
 fun <T : Any> KClass<T>.isProvidedBy(instance: T) = Module { it.bind(this.java).toProvider { instance } }
 fun <T : Any> KClass<T>.isProvidedBy(provider: com.google.inject.Provider<T>) = Module { it.bind(this.java).toProvider(provider) }
 fun <T : Any> KClass<T>.isProvidedBy(provider: KClass<out Provider<T>>) = Module { it.bind(this.java).toProvider(provider.java) }
index 4dddbe5..58f7823 100644 (file)
@@ -52,7 +52,7 @@ abstract class JsonPageTest(
        protected val preferences = Preferences(eventBus)
        protected val elementLoader = mock<ElementLoader>()
        protected open val page: JsonPage by lazy { pageSupplier(webInterface) }
-       protected val json by lazy { page.createJsonObject(freenetRequest)!! }
+       protected val json by lazy { page.createJsonObject(freenetRequest) }
 
        protected val toadletContext = mock<ToadletContext>()
        protected val freenetRequest = mock<FreenetRequest>()