From: David ‘Bombe’ Roden Date: Thu, 18 Jun 2020 21:17:52 +0000 (+0200) Subject: 🚚 Move test identity creation to Mocks.kt X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8b8e9d3b5321d67712e557da7b222a58538869d0;p=Sone.git 🚚 Move test identity creation to Mocks.kt --- 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 } }