From 8b8e9d3b5321d67712e557da7b222a58538869d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 18 Jun 2020 23:17:52 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=9A=9A=20Move=20test=20identity=20creation?= =?utf8?q?=20to=20Mocks.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/freenet/wot/IdentityLoaderTest.kt | 14 ++-------- .../kotlin/net/pterodactylus/sone/test/Mocks.kt | 32 ++++++++++++++++++++-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityLoaderTest.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityLoaderTest.kt index 0426814..4188adf 100644 --- a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityLoaderTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityLoaderTest.kt @@ -17,6 +17,8 @@ package net.pterodactylus.sone.freenet.wot +import net.pterodactylus.sone.test.createIdentity +import net.pterodactylus.sone.test.createOwnIdentity import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.containsInAnyOrder import org.hamcrest.Matchers.equalTo @@ -125,18 +127,6 @@ private fun createTrustedIdentitiesForThirdOwnIdentity() = setOf( private fun createTrustedIdentitiesForFourthOwnIdentity(): Set = emptySet() -private fun createOwnIdentity(id: String = "", nickname: String = "", requestUri: String = "", insertUri: String = "", contexts: Set = setOf(), properties: Map = mapOf()): OwnIdentity = - DefaultOwnIdentity(id, nickname, requestUri, insertUri).apply { - setContexts(contexts) - this.properties = properties - } - -private fun createIdentity(id: String = "", nickname: String = "", requestUri: String = "", contexts: Set = setOf(), properties: Map = mapOf()): Identity = - DefaultIdentity(id, nickname, requestUri).apply { - setContexts(contexts) - this.properties = properties - } - private open class TestWebOfTrustConnector : WebOfTrustConnector { override fun loadAllOwnIdentities() = emptySet() diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt b/src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt index 16e9b8d..6db8846 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Mocks.kt @@ -28,7 +28,12 @@ import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.data.SoneOptions.DefaultSoneOptions import net.pterodactylus.sone.data.impl.IdOnlySone import net.pterodactylus.sone.data.impl.ImageImpl +import net.pterodactylus.sone.freenet.wot.DefaultIdentity +import net.pterodactylus.sone.freenet.wot.DefaultOwnIdentity +import net.pterodactylus.sone.freenet.wot.Identity +import net.pterodactylus.sone.freenet.wot.OwnIdentity import net.pterodactylus.sone.utils.asFreenetBase64 +import net.pterodactylus.sone.utils.asOptional val remoteSone1 = createRemoteSone() val remoteSone2 = createRemoteSone() @@ -40,20 +45,41 @@ val createRequestUri: FreenetURI get() = InsertableClientSSK.createRandom(DummyR val createInsertUri: FreenetURI get() = InsertableClientSSK.createRandom(DummyRandomSource(), "").insertURI fun createId() = InsertableClientSSK.createRandom(DummyRandomSource(), "").uri.routingKey.asFreenetBase64 -fun createLocalSone(id: String? = createId()): Sone = object : IdOnlySone(id) { +fun createOwnIdentity(id: String = "", nickname: String = "", requestUri: String = "", insertUri: String = "", contexts: Set = setOf(), properties: Map = mapOf()): OwnIdentity = + DefaultOwnIdentity(id, nickname, requestUri, insertUri).apply { + setContexts(contexts) + this.properties = properties + } + +fun createIdentity(id: String = "", nickname: String = "", requestUri: String = "", contexts: Set = setOf(), properties: Map = mapOf()): Identity = + DefaultIdentity(id, nickname, requestUri).apply { + setContexts(contexts) + this.properties = properties + } + +fun createLocalSone(id: String = createId(), identity: Identity = createOwnIdentity(id)): Sone = object : IdOnlySone(id) { private val options = DefaultSoneOptions() + private val friends = mutableListOf() + override fun getIdentity(): Identity = identity override fun getOptions() = options override fun isLocal() = true + override fun getFriends() = friends + override fun hasFriend(friendSoneId: String) = friendSoneId in friends } -fun createRemoteSone(id: String? = createId()): Sone = IdOnlySone(id) +fun createRemoteSone(id: String = createId(), identity: Identity = createIdentity(id)): Sone = object : IdOnlySone(id) { + override fun getIdentity(): Identity = identity +} -fun createPost(text: String = "", sone: Sone = remoteSone1, known: Boolean = false, time: Long = 1): Post { +fun createPost(text: String = "", sone: Sone? = remoteSone1, known: Boolean = false, time: Long = 1, loaded: Boolean = true, recipient: Sone? = null): Post { return object : Post.EmptyPost("post-id") { + override fun getRecipientId() = recipient?.id.asOptional() + override fun getRecipient() = recipient.asOptional() override fun getSone() = sone override fun getText() = text override fun isKnown() = known override fun getTime() = time + override fun isLoaded() = loaded } } -- 2.7.4