Skip to content

Commit cbf9b68

Browse files
committed
feat(58): Added the 'error()' assertion and its tests
1 parent 82afdaf commit cbf9b68

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/main/kotlin/in/rcard/assertj/arrowcore/AbstractRaiseAssert.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

137142
sealed interface RaiseResult<out ERROR : Any, out VALUE : Any> {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)