🐛 Let last-state merged state always trigger
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 10 Feb 2024 07:33:05 +0000 (08:33 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 10 Feb 2024 07:33:05 +0000 (08:33 +0100)
src/main/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMerger.kt
src/test/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMergerTest.kt

index fe1fb37..95f6e6b 100644 (file)
@@ -8,6 +8,10 @@ import net.pterodactylus.rhynodge.State
  */
 class LastStateMerger : Merger {
 
-       override fun mergeStates(previousState: State, currentState: State) = currentState
+       override fun mergeStates(previousState: State, currentState: State) = AlwaysTriggeringState(currentState)
+
+       class AlwaysTriggeringState(state: State) : State by state {
+               override fun triggered() = true
+       }
 
 }
index 6046bb3..07d2bee 100644 (file)
@@ -3,18 +3,27 @@ package net.pterodactylus.rhynodge.mergers
 import net.pterodactylus.rhynodge.State
 import net.pterodactylus.rhynodge.states.StateManagerTest.TestState
 import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.sameInstance
+import org.hamcrest.Matchers.equalTo
 import org.junit.Test
 
 class LastStateMergerTest {
 
        @Test
        fun `merging states returns the current state`() {
-               assertThat(merger.mergeStates(previousState, successfulState), sameInstance(successfulState))
+               val mergedState = merger.mergeStates(previousState, successfulState)
+               assertThat(mergedState.time(), equalTo(successfulState.time()))
+               assertThat(mergedState.success(), equalTo(successfulState.success()))
+               assertThat(mergedState.failCount(), equalTo(successfulState.failCount()))
+               assertThat(mergedState.exception(), equalTo(successfulState.exception()))
+       }
+
+       @Test
+       fun `returned state is always triggered`() {
+               assertThat(merger.mergeStates(previousState, successfulState).triggered(), equalTo(true))
        }
 
        private val merger = LastStateMerger()
-       private val previousState = TestState()
-       private val successfulState: State = TestState()
+       private val previousState = TestState(false)
+       private val successfulState: State = TestState(true)
 
 }