package net.pterodactylus.sone.freenet.wot
-import com.google.common.eventbus.*
-import net.pterodactylus.sone.freenet.plugin.*
-import net.pterodactylus.sone.test.*
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.Matchers.*
-import org.junit.*
-import org.mockito.Mockito.*
+import com.google.common.eventbus.EventBus
+import net.pterodactylus.sone.freenet.plugin.PluginException
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
/**
* Unit test for [IdentityManagerImpl].
*/
class IdentityManagerTest {
- private val eventBus = mock<EventBus>()
- private val webOfTrustConnector = mock<WebOfTrustConnector>()
- private val identityManager = IdentityManagerImpl(eventBus, webOfTrustConnector, IdentityLoader(webOfTrustConnector, Context("Test")))
+ private val eventBus = EventBus()
@Test
fun identityManagerPingsWotConnector() {
+ var pingCalled = false
+ val webOfTrustConnector = dummyWebOfTrustConnector.overridePing { Unit.also { pingCalled = true } }
+ val identityManager = IdentityManagerImpl(eventBus, webOfTrustConnector, IdentityLoader(webOfTrustConnector, Context("Test")))
assertThat(identityManager.isConnected, equalTo(true))
- verify(webOfTrustConnector).ping()
+ assertThat(pingCalled, equalTo(true))
}
@Test
fun disconnectedWotConnectorIsRecognized() {
- doThrow(PluginException::class.java).whenever(webOfTrustConnector).ping()
+ val webOfTrustConnector = dummyWebOfTrustConnector.overridePing { throw PluginException() }
+ val identityManager = IdentityManagerImpl(eventBus, webOfTrustConnector, IdentityLoader(webOfTrustConnector, Context("Test")))
assertThat(identityManager.isConnected, equalTo(false))
- verify(webOfTrustConnector).ping()
}
}
--- /dev/null
+package net.pterodactylus.sone.freenet.wot
+
+val dummyWebOfTrustConnector = object : WebOfTrustConnector {
+ override fun loadAllOwnIdentities(): Set<OwnIdentity> = emptySet()
+ override fun loadTrustedIdentities(ownIdentity: OwnIdentity, context: String?): Set<Identity> = emptySet()
+ override fun loadAllIdentities(ownIdentity: OwnIdentity, context: String?): Set<Identity> = emptySet()
+ override fun addContext(ownIdentity: OwnIdentity, context: String) = Unit
+ override fun removeContext(ownIdentity: OwnIdentity, context: String) = Unit
+ override fun setProperty(ownIdentity: OwnIdentity, name: String, value: String) = Unit
+ override fun removeProperty(ownIdentity: OwnIdentity, name: String) = Unit
+ override fun ping() = Unit
+}
+
+open class DelegatingWebOfTrustConnector(private val delegate: WebOfTrustConnector) : WebOfTrustConnector by delegate
+
+fun WebOfTrustConnector.overridePing(override: () -> Unit): WebOfTrustConnector = object : DelegatingWebOfTrustConnector(this) {
+ override fun ping() = override()
+}