package net.pterodactylus.rhynodge.states import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.Test import java.time.Clock import java.time.Instant.now import java.time.ZoneOffset.UTC /** * Unit test for [AbstractState]. */ class AbstractStateTest { @Test fun `equals returns true when everything is the same`() { val first = object : AbstractState(testClock, false) { override fun plainText() = "foo" } val second = object : AbstractState(testClock, false) { override fun plainText() = "foo" } assertThat(first.equals(second), equalTo(true)) } @Test fun `equals returns false for when success is different`() { val first = object : AbstractState(testClock, false) { override fun plainText() = "foo" } val second = object : AbstractState(testClock, true) { override fun plainText() = "foo" } assertThat(first.equals(second), equalTo(false)) } @Test fun `equals return false when empty is different`() { val first = object : AbstractState(testClock, false, false) { override fun plainText() = "foo" } val second = object : AbstractState(testClock, false, true) { override fun plainText() = "foo" } assertThat(first.equals(second), equalTo(false)) } @Test fun `equals returns false when time is different`() { val first = object : AbstractState(testClock, false) { override fun plainText() = "foo" } val second = object : AbstractState(Clock.fixed(now().plusSeconds(1), UTC), false) { override fun plainText() = "foo" } assertThat(first.equals(second), equalTo(false)) } @Test fun `equals returns false when failCount is different`() { val first = object : AbstractState(testClock, false) { override fun plainText() = "foo" }.apply { setFailCount(12) } val second = object : AbstractState(testClock, false) { override fun plainText() = "foo" }.apply { setFailCount(23) } assertThat(first.equals(second), equalTo(false)) } @Test fun `equals returns false when exception is different`() { val first = object : AbstractState(testClock, RuntimeException()) { override fun plainText() = "foo" } val second = object : AbstractState(testClock, IllegalArgumentException()) { override fun plainText() = "foo" } assertThat(first.equals(second), equalTo(false)) } } private val testClock = Clock.fixed(now(), UTC)