♻️ Rename Preferences class to DefaultPreferences
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 4 Apr 2025 14:01:28 +0000 (16:01 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 4 Apr 2025 14:01:28 +0000 (16:01 +0200)
Next up: extract an interface, use that everywhere.

src/main/java/net/pterodactylus/sone/core/Core.java
src/main/kotlin/net/pterodactylus/sone/core/Preferences.kt
src/main/kotlin/net/pterodactylus/sone/core/PreferencesLoader.kt
src/main/kotlin/net/pterodactylus/sone/core/event/StrictFilteringEvents.kt
src/test/kotlin/net/pterodactylus/sone/core/PreferencesLoaderTest.kt
src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt
src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt

index 9354063..d7cc601 100644 (file)
@@ -115,7 +115,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
        private final AtomicBoolean debug = new AtomicBoolean(false);
 
        /** The preferences. */
-       private final Preferences preferences;
+       private final DefaultPreferences preferences;
 
        /** The event bus. */
        private final EventBus eventBus;
@@ -196,7 +196,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                this.database = database;
                this.metricRegistry = metricRegistry;
                this.soneUriCreator = soneUriCreator;
-               preferences = new Preferences(eventBus);
+               preferences = new DefaultPreferences(eventBus);
                this.configurationSaveTimeHistogram = metricRegistry.histogram("configuration.save.duration", () -> new Histogram(new ExponentiallyDecayingReservoir(3000, 0)));
        }
 
@@ -228,7 +228,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         *
         * @return The options of the core
         */
-       public Preferences getPreferences() {
+       public DefaultPreferences getPreferences() {
                return preferences;
        }
 
index fe1e3c3..e573185 100644 (file)
@@ -35,7 +35,7 @@ import java.lang.Integer.MAX_VALUE
  * Convenience interface for external classes that want to access the core’s
  * configuration.
  */
-class Preferences(private val eventBus: EventBus) {
+class DefaultPreferences(private val eventBus: EventBus) {
 
        private val _insertionDelay = DefaultOption(60) { it in 0..MAX_VALUE }
        val insertionDelay: Int get() = _insertionDelay.get()
index 62b60ae..5e8b7e8 100644 (file)
@@ -4,9 +4,9 @@ import net.pterodactylus.sone.fcp.FcpInterface.*
 import net.pterodactylus.util.config.*
 
 /**
- * Loads preferences stored in a [Configuration] into a [Preferences] object.
+ * Loads preferences stored in a [Configuration] into a [DefaultPreferences] object.
  */
-class PreferencesLoader(private val preferences: Preferences) {
+class PreferencesLoader(private val preferences: DefaultPreferences) {
 
        fun loadFrom(configuration: Configuration) {
                loadInsertionDelay(configuration)
index ea12459..22aa578 100644 (file)
@@ -1,13 +1,13 @@
 package net.pterodactylus.sone.core.event
 
 /**
- * Event that signals that the “[strict filtering][net.pterodactylus.sone.core.Preferences.strictFiltering]”
+ * Event that signals that the “[strict filtering][net.pterodactylus.sone.core.DefaultPreferences.strictFiltering]”
  * preference was activated.
  */
 class StrictFilteringActivatedEvent
 
 /**
- * Event that signals that the “[strict filtering][net.pterodactylus.sone.core.Preferences.strictFiltering]”
+ * Event that signals that the “[strict filtering][net.pterodactylus.sone.core.DefaultPreferences.strictFiltering]”
  * preference was deactivated.
  */
 class StrictFilteringDeactivatedEvent
index cb8df38..a90d87c 100644 (file)
@@ -14,7 +14,7 @@ class PreferencesLoaderTest {
 
        @Suppress("UnstableApiUsage")
        private val eventBus = EventBus()
-       private val preferences = Preferences(eventBus)
+       private val preferences = DefaultPreferences(eventBus)
        private val configuration = Configuration(MapConfigurationBackend())
        private val preferencesLoader = PreferencesLoader(preferences)
 
index dafe782..62c5990 100644 (file)
@@ -24,12 +24,12 @@ import org.hamcrest.Matchers.nullValue
 import org.junit.Test
 
 /**
- * Unit test for [Preferences].
+ * Unit test for [DefaultPreferences].
  */
-class PreferencesTest {
+class DefaultPreferencesTest {
 
        private val eventBus = EventBus()
-       private val preferences = Preferences(eventBus)
+       private val preferences = DefaultPreferences(eventBus)
 
        @Test
        fun `preferences retain insertion delay`() {
index bfac084..b0ad51c 100644 (file)
@@ -1,6 +1,6 @@
 package net.pterodactylus.sone.web.ajax
 
-import net.pterodactylus.sone.core.Preferences
+import net.pterodactylus.sone.core.DefaultPreferences
 import net.pterodactylus.sone.test.whenever
 import net.pterodactylus.sone.web.page.FreenetRequest
 import net.pterodactylus.util.web.Response
@@ -39,7 +39,7 @@ class JsonPageBaseTest : TestObjects() {
 
        @Before
        fun setupCore() {
-               whenever(core.preferences).thenReturn(Preferences(eventBus))
+               whenever(core.preferences).thenReturn(DefaultPreferences(eventBus))
        }
 
        @Before
index b3240ee..49c0291 100644 (file)
@@ -8,7 +8,7 @@ import freenet.support.api.HTTPRequest
 import net.pterodactylus.sone.core.Core
 import net.pterodactylus.sone.core.ElementLoader
 import net.pterodactylus.sone.core.LinkedElement
-import net.pterodactylus.sone.core.Preferences
+import net.pterodactylus.sone.core.DefaultPreferences
 import net.pterodactylus.sone.core.UpdateChecker
 import net.pterodactylus.sone.data.Album
 import net.pterodactylus.sone.data.Image
@@ -29,7 +29,6 @@ import net.pterodactylus.sone.web.NewElements
 import net.pterodactylus.sone.web.WebInterface
 import net.pterodactylus.sone.web.page.FreenetRequest
 import net.pterodactylus.util.notify.Notification
-import net.pterodactylus.util.template.TemplateContextFactory
 import net.pterodactylus.util.web.Method.GET
 import net.pterodactylus.util.web.Method.POST
 import org.mockito.ArgumentMatchers
@@ -47,7 +46,7 @@ open class TestObjects {
        var formPassword = "form-password"
        val core = mock<Core>()
        val eventBus = mock<EventBus>()
-       val preferences = Preferences(eventBus)
+       val preferences = DefaultPreferences(eventBus)
        val updateChecker = mock<UpdateChecker>()
        val elementLoader = mock<ElementLoader>()
        val newElements = mock<NewElements>()
index 6bfeeca..98c8156 100644 (file)
@@ -41,7 +41,7 @@ open class WebPageTest(pageSupplier: (WebInterface, Loaders, TemplateRenderer) -
        val webInterface = deepMock<WebInterface>()
        val core = webInterface.core
        val eventBus = mock<EventBus>()
-       val preferences = Preferences(eventBus)
+       val preferences = DefaultPreferences(eventBus)
 
        open val page by lazy { pageSupplier(webInterface, loaders, templateRenderer) }