Skip to content

Commit d0ee158

Browse files
authored
Merge pull request #1 from metalgold/satisfying
2 parents 54c1fdf + a4783db commit d0ee158

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,14 @@ abstract class AbstractEitherAssert<
8282
return myself
8383
}
8484

85-
fun hasRightValueSatisfying(requirement: Consumer<RIGHT>): SELF {
85+
/**
86+
* Verifies that the actual [Either] contains a right-sided value and gives this value to the given
87+
* consumer for further assertions. Should be used as a way of deeper asserting on the
88+
* containing object, as further requirement(s) for the value.
89+
*/
90+
fun hasRightValueSatisfying(requirement: (RIGHT) -> Unit): SELF {
8691
assertIsRight()
87-
actual.onRight { requirement.accept(it) }
92+
actual.onRight { requirement(it) }
8893
return myself
8994
}
9095

@@ -121,9 +126,14 @@ abstract class AbstractEitherAssert<
121126
return myself
122127
}
123128

124-
fun hasLeftValueSatisfying(requirement: Consumer<LEFT>): SELF {
129+
/**
130+
* Verifies that the actual [Either] contains a left-sided value and gives this value to the given
131+
* consumer for further assertions. Should be used as a way of deeper asserting on the
132+
* containing object, as further requirement(s) for the value.
133+
*/
134+
fun hasLeftValueSatisfying(requirement: (LEFT) -> Unit): SELF {
125135
assertIsLeft()
126-
actual.onLeft { requirement.accept(it) }
136+
actual.onLeft { requirement(it) }
127137
return myself
128138
}
129139

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,17 @@ abstract class AbstractOptionAssert<
8686
return myself
8787
}
8888

89-
fun hasValueSatisfying(requirement: Consumer<VALUE>): SELF {
89+
/**
90+
* Verifies that the actual [Option] contains a value and gives this value to the given
91+
* consumer for further assertions. Should be used as a way of deeper asserting on the
92+
* containing object, as further requirement(s) for the value.
93+
*
94+
* @param requirement to further assert on the object contained inside the [Option].
95+
* @return this assertion object.
96+
*/
97+
fun hasValueSatisfying(requirement: (VALUE) -> Unit): SELF {
9098
assertValueIsPresent()
91-
actual.onSome { requirement.accept(it) }
99+
actual.onSome { requirement(it) }
92100
return myself
93101
}
94102

src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_hasLeftValueSatisfying_Test.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.assertj.core.util.FailureMessages.actualIsNull
88
import org.junit.jupiter.api.Test
99

1010

11-
class EitherAssert_hasLeftValueSatisfying_Test {
11+
internal class EitherAssert_hasLeftValueSatisfying_Test {
1212

1313
@Test
1414
internal fun `should fail when either is null`() {
@@ -35,8 +35,8 @@ class EitherAssert_hasLeftValueSatisfying_Test {
3535
}
3636

3737
@Test
38-
fun should_pass_if_consumer_passes() {
38+
internal fun `should pass if consumer passes`() {
3939
val actual: Either<Int, String> = Either.Left(42)
40-
EitherAssert(actual).hasLeftValueSatisfying { assertThat(it).isEqualTo(42) }
40+
EitherAssert.assertThat(actual).hasLeftValueSatisfying { assertThat(it).isEqualTo(42) }
4141
}
4242
}

src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_hasRightValueSatisfying_Test.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.assertj.core.util.FailureMessages.actualIsNull
88
import org.junit.jupiter.api.Test
99

1010

11-
class EitherAssert_hasRightValueSatisfying_Test {
11+
internal class EitherAssert_hasRightValueSatisfying_Test {
1212

1313
@Test
1414
internal fun `should fail when either is null`() {
@@ -37,6 +37,6 @@ class EitherAssert_hasRightValueSatisfying_Test {
3737
@Test
3838
internal fun `should pass if consumer passes`() {
3939
val actual: Either<Int, String> = Either.Right("something")
40-
EitherAssert(actual).hasRightValueSatisfying { assertThat(it).isEqualTo("something") }
40+
EitherAssert.assertThat(actual).hasRightValueSatisfying { assertThat(it).isEqualTo("something") }
4141
}
4242
}

0 commit comments

Comments
 (0)