-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce boolean functions to simplify combining Mono<Boolean> inputs #161
Conversation
gregturn
commented
Aug 13, 2018
- not(value)
- and(value1, value2)
- or(value1, value2)
- nand(value1, value2)
- nor(value1, value2)
- xor(value1, value2)
* @param value2 second boolean | ||
* @return {@literal value1 && value2} wrapped in a {@link Mono} | ||
*/ | ||
public static Mono<Boolean> and(Mono<Boolean> value1, Mono<Boolean> value2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use Mono.zip(value1, value2, (a, b) -> a && b)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh! I love that.
* | ||
* @author Greg Turnquist | ||
*/ | ||
public final class BoolUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rename to BooleanUtils
for consistency with Mono<Boolean>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I was going for that, but discovered that reactor.boolean
wasn't a valid package name due to boolean
being a reserved word.
Either way, I can go for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool
in the package is fine by me, the class name feels weird though, so I would just change that
*/ | ||
public static Mono<Boolean> or(Mono<Boolean> value1, Mono<Boolean> value2) { | ||
return value1 | ||
.flatMap(bool1 -> value2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same pattern as above
*/ | ||
public static Mono<Boolean> xor(Mono<Boolean> value1, Mono<Boolean> value2) { | ||
return value1 | ||
.flatMap(bool1 -> value2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same pattern as above
@Test | ||
public void testNot() { | ||
StepVerifier.create(not(TRUE)) | ||
.assertNext(bool -> assertThat(bool).isFalse()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking or tip? in all these tests I'd tend to use assertThat(...).as("xxx")
, otherwise any failure would look like "org.junit.ComparisonFailure: Expected :false Actual :true"
.
eg.
StepVerifier.create(not(TRUE))
.assertNext(bool -> assertThat(bool).as("not(TRUE)").isFalse())
.verifyComplete();
would now look like:
org.junit.ComparisonFailure: [not(TRUE)]
Expected :false
Actual :true
public void testNot() { | ||
StepVerifier.create(not(TRUE)) | ||
.assertNext(bool -> assertThat(bool).isFalse()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a .verifyComplete();
.assertNext(bool -> assertThat(bool).isFalse()); | ||
|
||
StepVerifier.create(not(FALSE)) | ||
.assertNext(bool -> assertThat(bool).isTrue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a .verifyComplete()
ah @gregturn another issue: the test uses TestNG annotations not JUnit ;) |
* not(value) * and(value1, value2) * or(value1, value2) * nand(value1, value2) * nor(value1, value2) * xor(value1, value2)
IntelliJ!!!! Fixed. |