From: David ‘Bombe’ Roden Date: Sat, 10 Feb 2024 07:33:05 +0000 (+0100) Subject: 🐛 Let last-state merged state always trigger X-Git-Tag: v2~39 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9416428be83fdfefee8f303f2d8c1e1cb9d09a0b;p=rhynodge.git 🐛 Let last-state merged state always trigger --- diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMerger.kt b/src/main/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMerger.kt index fe1fb37..95f6e6b 100644 --- a/src/main/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMerger.kt +++ b/src/main/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMerger.kt @@ -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 + } } diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMergerTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMergerTest.kt index 6046bb3..07d2bee 100644 --- a/src/test/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMergerTest.kt +++ b/src/test/kotlin/net/pterodactylus/rhynodge/mergers/LastStateMergerTest.kt @@ -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) }