File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
main/kotlin/in/rcard/assertj/arrowcore
test/kotlin/in/rcard/assertj/arrowcore Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,11 @@ abstract class AbstractRaiseAssert<
132132 succeeds()
133133 return Assertions .assertThat((actual as RaiseResult .Success <VALUE >).value)
134134 }
135+
136+ fun error (): AbstractObjectAssert <* , ERROR > {
137+ fails()
138+ return Assertions .assertThat((actual as RaiseResult .Failure <ERROR >).error)
139+ }
135140}
136141
137142sealed interface RaiseResult <out ERROR : Any , out VALUE : Any > {
Original file line number Diff line number Diff line change 1+ package `in`.rcard.assertj.arrowcore
2+
3+ import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatRaisesAnError
4+ import `in`.rcard.assertj.arrowcore.Dummy.aFunctionThatThrowsAnException
5+ import `in`.rcard.assertj.arrowcore.Dummy.aFunctionWithContext
6+ import `in`.rcard.assertj.arrowcore.RaiseAssert.Companion.assertThat
7+ import `in`.rcard.assertj.arrowcore.errors.RaiseShouldFailButSucceeds.Companion.shouldFailButSucceedsWith
8+ import org.assertj.core.api.Assertions
9+ import org.junit.jupiter.api.Test
10+
11+ internal class RaiseAssert_error_Test {
12+ @Test
13+ internal fun `should return a valid Object Assert if the Raise raises an error` () {
14+ assertThat { aFunctionThatRaisesAnError() }.error().isEqualTo(" LOGICAL ERROR" )
15+ }
16+
17+ @Test
18+ internal fun `should fails if the Raise returns a value` () {
19+ Assertions
20+ .assertThatThrownBy { assertThat { aFunctionWithContext(42 ) }.error() }
21+ .isInstanceOf(AssertionError ::class .java)
22+ .hasMessage(shouldFailButSucceedsWith(42 ).create())
23+ }
24+
25+ @Test
26+ internal fun `should rethrow the inner exception` () {
27+ Assertions
28+ .assertThatThrownBy { assertThat { aFunctionThatThrowsAnException() }.error() }
29+ .isInstanceOf(RuntimeException ::class .java)
30+ .hasMessage(" AN EXCEPTION" )
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments