From: David ‘Bombe’ Roden Date: Wed, 7 Aug 2019 18:38:24 +0000 (+0200) Subject: 🎨 Replace KeyTest with Kotlin version X-Git-Tag: v81^2~130 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e3da6fa7de3fb34d26ee3ee13f26c9f59d13f9ce;p=Sone.git 🎨 Replace KeyTest with Kotlin version --- 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"