Make test work with Java 8, too
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 Sep 2021 11:03:39 +0000 (13:03 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 Sep 2021 11:29:41 +0000 (13:29 +0200)
Because the Files.writeString method was only added in Java 11 but I
still want Sone to be compilable and runnable with Java 8 because
a) it's what I still use (yes, I'm proper ashamed) and b) it's probably
what many other people still use as long as Freenet doesn't bundle its
own Java (which it really should).

src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt

index 30cdc6b..6470c95 100644 (file)
@@ -44,14 +44,14 @@ class ReloadingPageTest {
 
        @Test
        fun `requesting valid file results in 200 and delivers file`() {
-               val fileContent = listOf("Hello", "World").joinToString("\n", postfix = "\n")
-               Files.writeString(Paths.get(folder.path, "file.txt"), fileContent)
+               val fileContent = listOf("Hello", "World").joinToString("\n", postfix = "\n").toByteArray()
+               Files.write(Paths.get(folder.path, "file.txt"), fileContent)
                webPageTest.request("/prefix/path/file.txt")
                page.handleRequest(freenetRequest, response)
                assertThat(response.statusCode, equalTo(200))
                assertThat(response.statusText, equalTo("OK"))
                assertThat(response.contentType, equalTo("text/plain"))
-               assertThat(responseBytes.toByteArray(), equalTo(fileContent.toByteArray()))
+               assertThat(responseBytes.toByteArray(), equalTo(fileContent))
        }
 
        @Test