From e3da6fa7de3fb34d26ee3ee13f26c9f59d13f9ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 7 Aug 2019 20:38:24 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=8E=A8=20Replace=20KeyTest=20with=20Kotlin?= =?utf8?q?=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/freenet/KeyTest.java | 67 ---------------------- .../net/pterodactylus/sone/freenet/KeyTest.kt | 51 ++++++++++++++++ 2 files changed, 51 insertions(+), 67 deletions(-) delete mode 100644 src/test/java/net/pterodactylus/sone/freenet/KeyTest.java create mode 100644 src/test/kotlin/net/pterodactylus/sone/freenet/KeyTest.kt 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 index 80e1e45..0000000 --- a/src/test/java/net/pterodactylus/sone/freenet/KeyTest.java +++ /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 index 0000000..6e7fda1 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/freenet/KeyTest.kt @@ -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" -- 2.7.4