🐛 Fix NPE during Sone removal
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / freenet / wot / IdentityManagerTest.kt
1 package net.pterodactylus.sone.freenet.wot
2
3 import com.google.common.eventbus.EventBus
4 import net.pterodactylus.sone.freenet.plugin.PluginException
5 import org.hamcrest.MatcherAssert.assertThat
6 import org.hamcrest.Matchers.equalTo
7 import org.junit.Test
8
9 /**
10  * Unit test for [IdentityManagerImpl].
11  */
12 class IdentityManagerTest {
13
14         private val eventBus = EventBus()
15
16         @Test
17         fun identityManagerPingsWotConnector() {
18                 var pingCalled = false
19                 val webOfTrustConnector = dummyWebOfTrustConnector.overridePing { Unit.also { pingCalled = true } }
20                 val identityManager = IdentityManagerImpl(eventBus, webOfTrustConnector, IdentityLoader(webOfTrustConnector, Context("Test")))
21                 assertThat(identityManager.isConnected, equalTo(true))
22                 assertThat(pingCalled, equalTo(true))
23         }
24
25         @Test
26         fun disconnectedWotConnectorIsRecognized() {
27                 val webOfTrustConnector = dummyWebOfTrustConnector.overridePing { throw PluginException() }
28                 val identityManager = IdentityManagerImpl(eventBus, webOfTrustConnector, IdentityLoader(webOfTrustConnector, Context("Test")))
29                 assertThat(identityManager.isConnected, equalTo(false))
30         }
31
32 }