Skip to content
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

Merged
merged 2 commits into from
Aug 14, 2018

Conversation

gregturn
Copy link
Contributor

  • 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) {
Copy link
Member

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)

Copy link
Contributor Author

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 {
Copy link
Member

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>?

Copy link
Contributor Author

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.

Copy link
Member

@simonbasle simonbasle Aug 13, 2018

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
Copy link
Member

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
Copy link
Member

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());
Copy link
Member

@simonbasle simonbasle Aug 13, 2018

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());

Copy link
Member

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a .verifyComplete()

@simonbasle
Copy link
Member

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)
@gregturn
Copy link
Contributor Author

IntelliJ!!!!

Fixed.

@simonbasle simonbasle added this to the 3.2.0.M2 milestone Aug 14, 2018
@simonbasle simonbasle merged commit 7d37d5e into reactor:master Aug 14, 2018
@gregturn gregturn deleted the bool branch August 14, 2018 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants