1 package net.pterodactylus.sone.core
3 import com.google.common.eventbus.*
4 import net.pterodactylus.sone.fcp.FcpInterface.*
5 import net.pterodactylus.util.config.*
6 import org.hamcrest.MatcherAssert.*
7 import org.hamcrest.Matchers.*
11 * Unit test for [PreferencesLoader].
13 class PreferencesLoaderTest {
15 @Suppress("UnstableApiUsage")
16 private val eventBus = EventBus()
17 private val preferences = Preferences(eventBus)
18 private val configuration = Configuration(MapConfigurationBackend())
19 private val preferencesLoader = PreferencesLoader(preferences)
22 fun setupConfiguration() {
23 setupIntValue("InsertionDelay", 15)
24 setupIntValue("PostsPerPage", 25)
25 setupIntValue("ImagesPerPage", 12)
26 setupIntValue("CharactersPerPost", 150)
27 setupIntValue("PostCutOffLength", 300)
28 setupBooleanValue("RequireFullAccess", true)
29 setupBooleanValue("ActivateFcpInterface", true)
30 setupIntValue("FcpFullAccessRequired", 1)
33 private fun setupIntValue(optionName: String, value: Int) {
34 configuration.getIntValue("Option/$optionName").value = value
37 private fun setupBooleanValue(optionName: String, value: Boolean) {
38 configuration.getBooleanValue("Option/$optionName").value = value
42 fun `configuration is loaded correctly`() {
43 preferencesLoader.loadFrom(configuration)
44 assertThat(preferences.insertionDelay, equalTo(15))
45 assertThat(preferences.postsPerPage, equalTo(25))
46 assertThat(preferences.imagesPerPage, equalTo(12))
47 assertThat(preferences.charactersPerPost, equalTo(150))
48 assertThat(preferences.postCutOffLength, equalTo(300))
49 assertThat(preferences.requireFullAccess, equalTo(true))
50 assertThat(preferences.fcpInterfaceActive, equalTo(true))
51 assertThat(preferences.fcpFullAccessRequired, equalTo(FullAccessRequired.WRITING))
55 fun `configuration is loaded correctly with cut off length minus one`() {
56 setupIntValue("PostCutOffLength", -1)
57 preferencesLoader.loadFrom(configuration)
58 assertThat(preferences.postCutOffLength, not(equalTo(-1)))