From: David ‘Bombe’ Roden Date: Thu, 7 Sep 2017 18:56:46 +0000 (+0200) Subject: Fix some Kotlin compiler warnings X-Git-Tag: 0.9.7^2~84 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fecc40a37c481ea7c8d0aa5d13331834d165de6a;p=Sone.git Fix some Kotlin compiler warnings --- diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt index 3c0e77c..d01aeb4 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt @@ -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 { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt index 9872d1e..853fe26 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt @@ -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 {} diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt index dfed710..aa38f88 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt @@ -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 = fields + .associate { it to get(prefix + it) } protected fun matchesPost(post: Post) = OneByOneMatcher>().apply { expect("ID", post.id) { it["ID"] } diff --git a/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt index 0f8ba83..2fe40d4 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/SoneAccessorTest.kt @@ -58,6 +58,7 @@ class SoneAccessorTest { assertThat(accessor.get(templateContext, sone, member), equalTo(expected)) } + @Suppress("UNCHECKED_CAST") private fun assertAccessorReturnValueMatches(member: String, matcher: Matcher) { assertThat(accessor.get(templateContext, sone, member) as T, matcher) } diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt b/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt index d8a2d32..f5f52b8 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt @@ -5,7 +5,6 @@ import com.google.inject.Module import javax.inject.Provider import kotlin.reflect.KClass -fun KClass.isInstance(instance: T) = Module { it.bind(this.java).toInstance(instance) } fun KClass.isProvidedBy(instance: T) = Module { it.bind(this.java).toProvider { instance } } fun KClass.isProvidedBy(provider: com.google.inject.Provider) = Module { it.bind(this.java).toProvider(provider) } fun KClass.isProvidedBy(provider: KClass>) = Module { it.bind(this.java).toProvider(provider.java) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt index 4dddbe5..58f7823 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt @@ -52,7 +52,7 @@ abstract class JsonPageTest( protected val preferences = Preferences(eventBus) protected val elementLoader = mock() 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() protected val freenetRequest = mock()