From 76f50d5fcdd6bf662f5776ee9a13ae014dde92f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 7 Aug 2019 07:35:33 +0200 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Add=20freenet=20client=20in?= =?utf8?q?terface?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/sone/freenet/FreenetClient.kt | 20 +++++++++++++++++++ .../sone/freenet/FreenetClientTest.kt | 23 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/main/kotlin/net/pterodactylus/sone/freenet/FreenetClient.kt create mode 100644 src/test/kotlin/net/pterodactylus/sone/freenet/FreenetClientTest.kt 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)) + } + +} -- 2.7.4