@@ -5,54 +5,55 @@ import arrow.core.left
55import arrow.core.right
66import `in`.rcard.assertj.arrowcore.EitherAssert.Companion.assertThat
77import `in`.rcard.assertj.arrowcore.errors.EitherShouldBeRight.Companion.shouldBeRight
8+ import `in`.rcard.assertj.arrowcore.errors.EitherShouldContainInstanceOf.Companion.shouldContainOnRightInstanceOf
89import org.assertj.core.api.Assertions
910import org.assertj.core.util.FailureMessages
1011import org.junit.jupiter.api.Test
1112
1213class EitherAssert_containsOnRightInstanceOf_Test {
1314
14- @Test
15- fun `should fail if either is null` () {
16- val actual: Either <Nothing , Nothing >? = null
17- Assertions .assertThatThrownBy {
18- assertThat(actual).containsRightInstanceOf(
19- Any ::class .java
20- )
21- }
22- .isInstanceOf(AssertionError ::class .java)
23- .hasMessage(FailureMessages .actualIsNull())
24- }
25-
26- @Test
27- fun `should fail if either is left` () {
28- val actual: Either <String , Nothing > = " some" .left()
29- Assertions .assertThatThrownBy {
30- assertThat(actual).containsRightInstanceOf(
31- Any ::class .java
32- )
33- }
34- .isInstanceOf(AssertionError ::class .java)
35- .hasMessage(shouldBeRight(actual).create())
36- }
37-
38- @Test
39- fun should_fail_if_either_contains_other_type_on_right_than_required () {
40- val actual: Either <Any , Int > = 42 .right()
41- Assertions .assertThatThrownBy {
42- assertThat(actual).containsRightInstanceOf(String ::class .java)
43- }
44- .isInstanceOf(AssertionError ::class .java)
45- .hasMessage(
46- shouldContainOnRightInstanceOf(
15+ @Test
16+ fun `should fail if either is null` () {
17+ val actual: Either <Nothing , Nothing >? = null
18+ Assertions .assertThatThrownBy { assertThat(actual).containsRightInstanceOf(Any ::class .java) }
19+ .isInstanceOf(AssertionError ::class .java)
20+ .hasMessage(FailureMessages .actualIsNull())
21+ }
22+
23+ @Test
24+ fun `should fail if either is left` () {
25+ val actual: Either <String , Nothing > = " some" .left()
26+ Assertions .assertThatThrownBy { assertThat(actual).containsRightInstanceOf(Any ::class .java) }
27+ .isInstanceOf(AssertionError ::class .java)
28+ .hasMessage(shouldBeRight(actual).create())
29+ }
30+
31+ @Test
32+ fun should_fail_if_either_contains_other_type_on_right_than_required () {
33+ val actual: Either <Any , Int > = 42 .right()
34+ Assertions .assertThatThrownBy { assertThat(actual).containsRightInstanceOf(String ::class .java) }
35+ .isInstanceOf(AssertionError ::class .java)
36+ .hasMessage(
37+ shouldContainOnRightInstanceOf(
4738 actual,
48- Int ::class .java,
49- ).create()
50- )
51- }
52-
53- @Test
54- fun `should pass if either contains required type on right` () {
55- val actual: Either <Nothing , String > = " something" .right()
56- assertThat(actual).containsRightInstanceOf(String ::class .java)
57- }
58- }
39+ String ::class .java,
40+ )
41+ .create())
42+ }
43+
44+ @Test
45+ fun `should pass if either contains required type subclass on right` () {
46+ val actual = Child ().right()
47+ assertThat(actual).containsRightInstanceOf(Parent ::class .java)
48+ }
49+
50+ @Test
51+ fun `should pass if either contains required type on right` () {
52+ val actual: Either <Nothing , String > = " something" .right()
53+ assertThat(actual).containsRightInstanceOf(String ::class .java)
54+ }
55+ }
56+
57+ private open class Parent
58+
59+ private class Child : Parent ()
0 commit comments