*/
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
+ }
}
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)
}