From: David ‘Bombe’ Roden Date: Mon, 21 Sep 2020 18:58:32 +0000 (+0200) Subject: ✅ Add test for AlwaysTrigger X-Git-Tag: v2~76 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=56e7ffa19450e9cba8492bc859dfcfe81b20d356;p=rhynodge.git ✅ Add test for AlwaysTrigger --- diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/Testing.kt b/src/test/kotlin/net/pterodactylus/rhynodge/Testing.kt new file mode 100644 index 0000000..87a618a --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/rhynodge/Testing.kt @@ -0,0 +1,15 @@ +package net.pterodactylus.rhynodge + +import net.pterodactylus.rhynodge.output.Output +import net.pterodactylus.rhynodge.states.StateManagerTest.TestState + +fun testQuery(state: State = TestState()): Query = TestQuery(state) +fun testAction(): Action = TestAction() + +class TestQuery(private val state: State) : Query { + override fun state(): State = state +} + +class TestAction : Action { + override fun execute(output: Output?) = Unit +} diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/triggers/AlwaysTriggerTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/triggers/AlwaysTriggerTest.kt new file mode 100644 index 0000000..0a85bea --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/rhynodge/triggers/AlwaysTriggerTest.kt @@ -0,0 +1,53 @@ +package net.pterodactylus.rhynodge.triggers + +import net.pterodactylus.rhynodge.Reaction +import net.pterodactylus.rhynodge.State +import net.pterodactylus.rhynodge.states.FailedState +import net.pterodactylus.rhynodge.states.StateManagerTest.TestState +import net.pterodactylus.rhynodge.testAction +import net.pterodactylus.rhynodge.testQuery +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.sameInstance +import org.junit.Test + +class AlwaysTriggerTest { + + @Test + fun `merging states returns the current state`() { + assertThat(trigger.mergeStates(previousState, successfulState), sameInstance(successfulState)) + } + + @Test + fun `successful state triggers`() { + trigger.mergeStates(previousState, successfulState) + assertThat(trigger.triggers(), equalTo(true)) + } + + @Test + fun `failed state also triggers`() { + trigger.mergeStates(previousState, failedState) + assertThat(trigger.triggers(), equalTo(true)) + } + + @Test + @Suppress("NonAsciiCharacters") + fun `output returns “true” for plain text`() { + trigger.mergeStates(previousState, successfulState) + val output = trigger.output(Reaction("Test", testQuery(), trigger, testAction())) + assertThat(output.text("text/plain"), equalTo("true")) + } + + @Test + fun `output returns true in a div for html`() { + trigger.mergeStates(previousState, successfulState) + val output = trigger.output(Reaction("Test", testQuery(), trigger, testAction())) + assertThat(output.text("text/html"), equalTo("
true
")) + } + + private val trigger = AlwaysTrigger() + private val previousState = TestState() + private val successfulState: State = TestState() + private val failedState: State = FailedState() + +}