🎨 Replace KeyTest with Kotlin version
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 7 Aug 2019 18:38:24 +0000 (20:38 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 7 Aug 2019 18:38:24 +0000 (20:38 +0200)
src/test/java/net/pterodactylus/sone/freenet/KeyTest.java [deleted file]
src/test/kotlin/net/pterodactylus/sone/freenet/KeyTest.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/freenet/KeyTest.java b/src/test/java/net/pterodactylus/sone/freenet/KeyTest.java
deleted file mode 100644 (file)
index 80e1e45..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-package net.pterodactylus.sone.freenet;
-
-import static freenet.support.Base64.encode;
-import static net.pterodactylus.sone.freenet.Key.from;
-import static net.pterodactylus.sone.freenet.Key.routingKey;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-import java.net.MalformedURLException;
-
-import freenet.keys.FreenetURI;
-
-import org.junit.Test;
-
-/**
- * Unit test for {@link Key}.
- */
-public class KeyTest {
-
-       private final FreenetURI uri;
-       private final Key key;
-
-       public KeyTest() throws MalformedURLException {
-               uri = new FreenetURI(
-                               "SSK@NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs,Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI,AQACAAE/some-site-12/foo/bar.html");
-               key = from(uri);
-       }
-
-       @Test
-       public void keyCanBeCreatedFromFreenetUri() throws MalformedURLException {
-               assertThat(key.getRoutingKey(),
-                               is("NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs"));
-               assertThat(key.getCryptoKey(),
-                               is("Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI"));
-               assertThat(key.getExtra(), is("AQACAAE"));
-       }
-
-       @Test
-       public void keyCanBeConvertedToUsk() throws MalformedURLException {
-               FreenetURI uskUri = key.toUsk("other-site", 15, "some", "path.html");
-               assertThat(uskUri.toString(),
-                               is("USK@NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs,Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI,AQACAAE/other-site/15/some/path.html"));
-       }
-
-       @Test
-       public void keyCanBeConvertedToSskWithoutEdition()
-       throws MalformedURLException {
-               FreenetURI uskUri = key.toSsk("other-site", "some", "path.html");
-               assertThat(uskUri.toString(),
-                               is("SSK@NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs,Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI,AQACAAE/other-site/some/path.html"));
-       }
-
-       @Test
-       public void keyCanBeConvertedToSskWithEdition()
-       throws MalformedURLException {
-               FreenetURI uskUri = key.toSsk("other-site", 15, "some", "path.html");
-               assertThat(uskUri.toString(),
-                               is("SSK@NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs,Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI,AQACAAE/other-site-15/some/path.html"));
-       }
-
-       @Test
-       public void routingKeyIsExtractCorrectly() {
-               assertThat(routingKey(uri),
-                               is("NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs"));
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/KeyTest.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/KeyTest.kt
new file mode 100644 (file)
index 0000000..6e7fda1
--- /dev/null
@@ -0,0 +1,51 @@
+package net.pterodactylus.sone.freenet
+
+import freenet.keys.*
+import net.pterodactylus.sone.freenet.Key.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.*
+
+/**
+ * Unit test for [Key].
+ */
+class KeyTest {
+
+       private val uri = FreenetURI("SSK@$routingKey,$cryptoKey,$extra/some-site-12/foo/bar.html")
+       private val key: Key = from(uri)
+
+       @Test
+       fun keyCanBeCreatedFromFreenetUri() {
+               assertThat(key.routingKey, equalTo(routingKey))
+               assertThat(key.cryptoKey, equalTo(cryptoKey))
+               assertThat(key.extra, equalTo(extra))
+       }
+
+       @Test
+       fun keyCanBeConvertedToUsk() {
+               val uskUri = key.toUsk("other-site", 15, "some", "path.html")
+               assertThat(uskUri.toString(), equalTo("USK@$routingKey,$cryptoKey,$extra/other-site/15/some/path.html"))
+       }
+
+       @Test
+       fun keyCanBeConvertedToSskWithoutEdition() {
+               val uskUri = key.toSsk("other-site", "some", "path.html")
+               assertThat(uskUri.toString(), equalTo("SSK@$routingKey,$cryptoKey,$extra/other-site/some/path.html"))
+       }
+
+       @Test
+       fun keyCanBeConvertedToSskWithEdition() {
+               val uskUri = key.toSsk("other-site", 15, "some", "path.html")
+               assertThat(uskUri.toString(), equalTo("SSK@$routingKey,$cryptoKey,$extra/other-site-15/some/path.html"))
+       }
+
+       @Test
+       fun routingKeyIsExtractCorrectly() {
+               assertThat(routingKey(uri), equalTo(routingKey))
+       }
+
+}
+
+private const val routingKey = "NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs"
+private const val cryptoKey = "Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI"
+private const val extra = "AQACAAE"