From: David ‘Bombe’ Roden Date: Wed, 7 Aug 2019 05:35:33 +0000 (+0200) Subject: ♻️ Add freenet client interface X-Git-Tag: v81^2~135 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=76f50d5fcdd6bf662f5776ee9a13ae014dde92f1;p=Sone.git ♻️ Add freenet client interface --- diff --git a/src/main/kotlin/net/pterodactylus/sone/freenet/FreenetClient.kt b/src/main/kotlin/net/pterodactylus/sone/freenet/FreenetClient.kt new file mode 100644 index 0000000..8fbbe57 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/freenet/FreenetClient.kt @@ -0,0 +1,20 @@ +package net.pterodactylus.sone.freenet + +import freenet.client.* +import freenet.keys.* + +/** + * Facade for Freenet’s [freenet.client.HighLevelSimpleClient] to allow testing. + */ +interface FreenetClient { + + fun fetch(freenetKey: FreenetURI): FetchResult + +} + +class DefaultFreenetClient(private val highLevelSimpleClient: HighLevelSimpleClient) : FreenetClient { + + override fun fetch(freenetKey: FreenetURI): FetchResult = + highLevelSimpleClient.fetch(freenetKey) + +} diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/FreenetClientTest.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/FreenetClientTest.kt new file mode 100644 index 0000000..f6d5883 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/freenet/FreenetClientTest.kt @@ -0,0 +1,23 @@ +package net.pterodactylus.sone.freenet + +import freenet.client.* +import freenet.keys.* +import freenet.support.io.* +import net.pterodactylus.sone.test.* +import org.hamcrest.MatcherAssert.* +import org.hamcrest.Matchers.* +import kotlin.test.* + +class FreenetClientTest { + + private val highLevelSimpleClient = mock() + private val freenetClient = DefaultFreenetClient(highLevelSimpleClient) + + @Test + fun `fetch method calls method on hlsc`() { + val fetchResult = FetchResult(ClientMetadata(), NullBucket()) + whenever(highLevelSimpleClient.fetch(FreenetURI("KSK@GPL.txt"))).thenReturn(fetchResult) + assertThat(freenetClient.fetch(FreenetURI("KSK@GPL.txt")), equalTo(fetchResult)) + } + +}