🚚 Move Kotlin files to correct source path
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 7 Apr 2020 08:43:51 +0000 (10:43 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 7 Apr 2020 08:43:51 +0000 (10:43 +0200)
src/main/java/net/pterodactylus/sone/web/page/PageToadlet.kt [deleted file]
src/main/kotlin/net/pterodactylus/sone/web/page/PageToadlet.kt [new file with mode: 0644]
src/test/java/net/pterodactylus/sone/core/SoneUriCreatorTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/core/SoneUriCreatorTest.kt [new file with mode: 0644]

diff --git a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.kt b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.kt
deleted file mode 100644 (file)
index a1cddfe..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Sone - PageToadlet.kt - Copyright Â© 2010–2020 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.web.page
-
-import freenet.client.HighLevelSimpleClient
-import freenet.clients.http.LinkEnabledCallback
-import freenet.clients.http.LinkFilterExceptedToadlet
-import freenet.clients.http.SessionManager
-import freenet.clients.http.Toadlet
-import freenet.clients.http.ToadletContext
-import freenet.support.MultiValueTable
-import freenet.support.api.HTTPRequest
-import net.pterodactylus.sone.utils.use
-import net.pterodactylus.util.web.Method
-import net.pterodactylus.util.web.Page
-import net.pterodactylus.util.web.Response
-import java.net.URI
-
-/**
- * [Toadlet] implementation that is wrapped around a [Page].
- */
-class PageToadlet(
-               highLevelSimpleClient: HighLevelSimpleClient,
-               private val sessionManager: SessionManager,
-               val menuName: String?,
-               private val page: Page<FreenetRequest>,
-               private val pathPrefix: String
-) : Toadlet(highLevelSimpleClient), LinkEnabledCallback, LinkFilterExceptedToadlet {
-
-       override fun path() = pathPrefix + page.path
-
-       override fun handleMethodGET(uri: URI, httpRequest: HTTPRequest, toadletContext: ToadletContext) =
-                       handleRequest(FreenetRequest(uri, Method.GET, httpRequest, toadletContext, sessionManager))
-
-       fun handleMethodPOST(uri: URI?, httpRequest: HTTPRequest?, toadletContext: ToadletContext?) =
-                       handleRequest(FreenetRequest(uri!!, Method.POST, httpRequest!!, toadletContext!!, sessionManager))
-
-       private fun handleRequest(pageRequest: FreenetRequest) {
-               pageRequest.toadletContext.bucketFactory.makeBucket(-1).use { pageBucket ->
-                       pageBucket.outputStream.use { pageBucketOutputStream ->
-                               val pageResponse = page.handleRequest(pageRequest, Response(pageBucketOutputStream))
-                               // according to the javadoc, headers is allowed to return null but that’s stupid and it doesn’t do that.
-                               val headers = pageResponse.headers.fold(MultiValueTable<String, String>()) { headers, header ->
-                                       headers.apply {
-                                               header.forEach { put(header.name, it) }
-                                       }
-                               }
-                               with(pageResponse) {
-                                       writeReply(pageRequest.toadletContext, statusCode, contentType, statusText, headers, pageBucket)
-                               }
-                       }
-               }
-       }
-
-       override fun isEnabled(toadletContext: ToadletContext) =
-                       if (page is LinkEnabledCallback) {
-                               page.isEnabled(toadletContext)
-                       } else
-                               true
-
-       override fun isLinkExcepted(link: URI) =
-                       page is FreenetPage && page.isLinkExcepted(link)
-
-       override fun toString() = "${javaClass.name}[path=${path()},page=$page]"
-
-}
diff --git a/src/main/kotlin/net/pterodactylus/sone/web/page/PageToadlet.kt b/src/main/kotlin/net/pterodactylus/sone/web/page/PageToadlet.kt
new file mode 100644 (file)
index 0000000..a1cddfe
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Sone - PageToadlet.kt - Copyright Â© 2010–2020 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.page
+
+import freenet.client.HighLevelSimpleClient
+import freenet.clients.http.LinkEnabledCallback
+import freenet.clients.http.LinkFilterExceptedToadlet
+import freenet.clients.http.SessionManager
+import freenet.clients.http.Toadlet
+import freenet.clients.http.ToadletContext
+import freenet.support.MultiValueTable
+import freenet.support.api.HTTPRequest
+import net.pterodactylus.sone.utils.use
+import net.pterodactylus.util.web.Method
+import net.pterodactylus.util.web.Page
+import net.pterodactylus.util.web.Response
+import java.net.URI
+
+/**
+ * [Toadlet] implementation that is wrapped around a [Page].
+ */
+class PageToadlet(
+               highLevelSimpleClient: HighLevelSimpleClient,
+               private val sessionManager: SessionManager,
+               val menuName: String?,
+               private val page: Page<FreenetRequest>,
+               private val pathPrefix: String
+) : Toadlet(highLevelSimpleClient), LinkEnabledCallback, LinkFilterExceptedToadlet {
+
+       override fun path() = pathPrefix + page.path
+
+       override fun handleMethodGET(uri: URI, httpRequest: HTTPRequest, toadletContext: ToadletContext) =
+                       handleRequest(FreenetRequest(uri, Method.GET, httpRequest, toadletContext, sessionManager))
+
+       fun handleMethodPOST(uri: URI?, httpRequest: HTTPRequest?, toadletContext: ToadletContext?) =
+                       handleRequest(FreenetRequest(uri!!, Method.POST, httpRequest!!, toadletContext!!, sessionManager))
+
+       private fun handleRequest(pageRequest: FreenetRequest) {
+               pageRequest.toadletContext.bucketFactory.makeBucket(-1).use { pageBucket ->
+                       pageBucket.outputStream.use { pageBucketOutputStream ->
+                               val pageResponse = page.handleRequest(pageRequest, Response(pageBucketOutputStream))
+                               // according to the javadoc, headers is allowed to return null but that’s stupid and it doesn’t do that.
+                               val headers = pageResponse.headers.fold(MultiValueTable<String, String>()) { headers, header ->
+                                       headers.apply {
+                                               header.forEach { put(header.name, it) }
+                                       }
+                               }
+                               with(pageResponse) {
+                                       writeReply(pageRequest.toadletContext, statusCode, contentType, statusText, headers, pageBucket)
+                               }
+                       }
+               }
+       }
+
+       override fun isEnabled(toadletContext: ToadletContext) =
+                       if (page is LinkEnabledCallback) {
+                               page.isEnabled(toadletContext)
+                       } else
+                               true
+
+       override fun isLinkExcepted(link: URI) =
+                       page is FreenetPage && page.isLinkExcepted(link)
+
+       override fun toString() = "${javaClass.name}[path=${path()},page=$page]"
+
+}
diff --git a/src/test/java/net/pterodactylus/sone/core/SoneUriCreatorTest.kt b/src/test/java/net/pterodactylus/sone/core/SoneUriCreatorTest.kt
deleted file mode 100644 (file)
index ae8f25b..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-package net.pterodactylus.sone.core
-
-import com.google.inject.Guice
-import net.pterodactylus.sone.data.impl.IdOnlySone
-import net.pterodactylus.sone.freenet.wot.DefaultIdentity
-import net.pterodactylus.sone.freenet.wot.DefaultOwnIdentity
-import net.pterodactylus.sone.test.createInsertUri
-import net.pterodactylus.sone.test.createRequestUri
-import net.pterodactylus.sone.test.getInstance
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.emptyArray
-import org.hamcrest.Matchers.equalTo
-import org.hamcrest.Matchers.notNullValue
-import org.hamcrest.Matchers.nullValue
-import kotlin.test.Test
-
-/**
- * Unit test for [SoneUriCreator].
- */
-class SoneUriCreatorTest {
-
-       private val soneUriCreator = SoneUriCreator()
-
-       private val requestUri = soneUriCreator.getRequestUri(sone)
-       private val insertUri = soneUriCreator.getInsertUri(sone)
-
-       @Test
-       fun `generated request URI is a USK`() {
-               assertThat(requestUri.keyType, equalTo("USK"))
-       }
-
-       @Test
-       fun `generated request URI has correct doc name`() {
-               assertThat(requestUri.docName, equalTo("Sone"))
-       }
-
-       @Test
-       fun `generated request URI has no meta strings`() {
-               assertThat(requestUri.allMetaStrings, emptyArray())
-       }
-
-       @Test
-       fun `generated request URI has correct edition`() {
-               assertThat(requestUri.suggestedEdition, equalTo(123L))
-       }
-
-       @Test
-       fun `insert URI is null if sone’s identity is not an own identity`() {
-               val remoteSone = object : IdOnlySone("id") {
-                       override fun getIdentity() = DefaultIdentity("id", "name", createRequestUri.toString())
-               }
-               assertThat(soneUriCreator.getInsertUri(remoteSone), nullValue())
-       }
-
-       @Test
-       fun `generated insert URI is a USK`() {
-               assertThat(insertUri!!.keyType, equalTo("USK"))
-       }
-
-       @Test
-       fun `generated insert URI has correct doc name`() {
-               assertThat(insertUri!!.docName, equalTo("Sone"))
-       }
-
-       @Test
-       fun `generated insert URI has no meta strings`() {
-               assertThat(insertUri!!.allMetaStrings, emptyArray())
-       }
-
-       @Test
-       fun `generated insert URI has correct edition`() {
-               assertThat(insertUri!!.suggestedEdition, equalTo(123L))
-       }
-
-       @Test
-       fun `creator can be created by guice`() {
-               val injector = Guice.createInjector()
-               assertThat(injector.getInstance<SoneUriCreator>(), notNullValue())
-       }
-
-}
-
-private val sone = object : IdOnlySone("id") {
-       override fun getIdentity() =
-                       DefaultOwnIdentity("id", "name", createRequestUri.toString(), createInsertUri.toString())
-
-       override fun getLatestEdition() = 123L
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/core/SoneUriCreatorTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/SoneUriCreatorTest.kt
new file mode 100644 (file)
index 0000000..ae8f25b
--- /dev/null
@@ -0,0 +1,88 @@
+package net.pterodactylus.sone.core
+
+import com.google.inject.Guice
+import net.pterodactylus.sone.data.impl.IdOnlySone
+import net.pterodactylus.sone.freenet.wot.DefaultIdentity
+import net.pterodactylus.sone.freenet.wot.DefaultOwnIdentity
+import net.pterodactylus.sone.test.createInsertUri
+import net.pterodactylus.sone.test.createRequestUri
+import net.pterodactylus.sone.test.getInstance
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.emptyArray
+import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
+import org.hamcrest.Matchers.nullValue
+import kotlin.test.Test
+
+/**
+ * Unit test for [SoneUriCreator].
+ */
+class SoneUriCreatorTest {
+
+       private val soneUriCreator = SoneUriCreator()
+
+       private val requestUri = soneUriCreator.getRequestUri(sone)
+       private val insertUri = soneUriCreator.getInsertUri(sone)
+
+       @Test
+       fun `generated request URI is a USK`() {
+               assertThat(requestUri.keyType, equalTo("USK"))
+       }
+
+       @Test
+       fun `generated request URI has correct doc name`() {
+               assertThat(requestUri.docName, equalTo("Sone"))
+       }
+
+       @Test
+       fun `generated request URI has no meta strings`() {
+               assertThat(requestUri.allMetaStrings, emptyArray())
+       }
+
+       @Test
+       fun `generated request URI has correct edition`() {
+               assertThat(requestUri.suggestedEdition, equalTo(123L))
+       }
+
+       @Test
+       fun `insert URI is null if sone’s identity is not an own identity`() {
+               val remoteSone = object : IdOnlySone("id") {
+                       override fun getIdentity() = DefaultIdentity("id", "name", createRequestUri.toString())
+               }
+               assertThat(soneUriCreator.getInsertUri(remoteSone), nullValue())
+       }
+
+       @Test
+       fun `generated insert URI is a USK`() {
+               assertThat(insertUri!!.keyType, equalTo("USK"))
+       }
+
+       @Test
+       fun `generated insert URI has correct doc name`() {
+               assertThat(insertUri!!.docName, equalTo("Sone"))
+       }
+
+       @Test
+       fun `generated insert URI has no meta strings`() {
+               assertThat(insertUri!!.allMetaStrings, emptyArray())
+       }
+
+       @Test
+       fun `generated insert URI has correct edition`() {
+               assertThat(insertUri!!.suggestedEdition, equalTo(123L))
+       }
+
+       @Test
+       fun `creator can be created by guice`() {
+               val injector = Guice.createInjector()
+               assertThat(injector.getInstance<SoneUriCreator>(), notNullValue())
+       }
+
+}
+
+private val sone = object : IdOnlySone("id") {
+       override fun getIdentity() =
+                       DefaultOwnIdentity("id", "name", createRequestUri.toString(), createInsertUri.toString())
+
+       override fun getLatestEdition() = 123L
+}