From 56e7ffa19450e9cba8492bc859dfcfe81b20d356 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 21 Sep 2020 20:58:32 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20AlwaysTrigger?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../kotlin/net/pterodactylus/rhynodge/Testing.kt | 15 ++++++ .../rhynodge/triggers/AlwaysTriggerTest.kt | 53 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/rhynodge/Testing.kt create mode 100644 src/test/kotlin/net/pterodactylus/rhynodge/triggers/AlwaysTriggerTest.kt 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() + +} -- 2.7.4