1 package net.pterodactylus.rhynodge.states
3 import org.hamcrest.MatcherAssert.assertThat
4 import org.hamcrest.Matchers.equalTo
7 import java.time.Instant.now
8 import java.time.ZoneOffset.UTC
11 * Unit test for [AbstractState].
13 class AbstractStateTest {
16 fun `equals returns true when everything is the same`() {
17 val first = object : AbstractState(testClock, false) {
18 override fun plainText() = "foo"
20 val second = object : AbstractState(testClock, false) {
21 override fun plainText() = "foo"
23 assertThat(first.equals(second), equalTo(true))
27 fun `equals returns false for when success is different`() {
28 val first = object : AbstractState(testClock, false) {
29 override fun plainText() = "foo"
31 val second = object : AbstractState(testClock, true) {
32 override fun plainText() = "foo"
34 assertThat(first.equals(second), equalTo(false))
38 fun `equals return false when empty is different`() {
39 val first = object : AbstractState(testClock, false, false) {
40 override fun plainText() = "foo"
42 val second = object : AbstractState(testClock, false, true) {
43 override fun plainText() = "foo"
45 assertThat(first.equals(second), equalTo(false))
49 fun `equals returns false when time is different`() {
50 val first = object : AbstractState(testClock, false) {
51 override fun plainText() = "foo"
53 val second = object : AbstractState(Clock.fixed(now().plusSeconds(1), UTC), false) {
54 override fun plainText() = "foo"
56 assertThat(first.equals(second), equalTo(false))
60 fun `equals returns false when failCount is different`() {
61 val first = object : AbstractState(testClock, false) {
62 override fun plainText() = "foo"
63 }.apply { setFailCount(12) }
64 val second = object : AbstractState(testClock, false) {
65 override fun plainText() = "foo"
66 }.apply { setFailCount(23) }
67 assertThat(first.equals(second), equalTo(false))
71 fun `equals returns false when exception is different`() {
72 val first = object : AbstractState(testClock, RuntimeException()) {
73 override fun plainText() = "foo"
75 val second = object : AbstractState(testClock, IllegalArgumentException()) {
76 override fun plainText() = "foo"
78 assertThat(first.equals(second), equalTo(false))
83 private val testClock = Clock.fixed(now(), UTC)