From: David ‘Bombe’ Roden Date: Fri, 1 Mar 2019 20:07:56 +0000 (+0100) Subject: ♻️ Generalize test methods X-Git-Tag: v79^2~89 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7e43bed09912f401dc53be9b998ebd1072656ffe;p=Sone.git ♻️ Generalize test methods --- diff --git a/src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt index ca58c40..199604b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/PreferencesTest.kt @@ -311,16 +311,18 @@ class PreferencesTest { @Test fun `setting insertion delay to valid value sends change event`() { - preferences.newInsertionDelay = 30 - verify(eventBus, atLeastOnce()).post(eventsCaptor.capture()) - assertThat(eventsCaptor.allValues, hasItem(PreferenceChangedEvent("InsertionDelay", 30))) + testPreferencesChangedEvent("InsertionDelay", { preferences.newInsertionDelay = it }, 30) } @Test fun `setting posts per page to valid value sends change event`() { - preferences.newPostsPerPage = 30 + testPreferencesChangedEvent("PostsPerPage", { preferences.newPostsPerPage = it }, 31) + } + + private fun testPreferencesChangedEvent(name: String, setter: (T) -> Unit, value: T) { + setter(value) verify(eventBus, atLeastOnce()).post(eventsCaptor.capture()) - assertThat(eventsCaptor.allValues, hasItem(PreferenceChangedEvent("PostsPerPage", 30))) + assertThat(eventsCaptor.allValues, hasItem(PreferenceChangedEvent(name, value))) } }