Skip to content

Commit

Permalink
feat($𝛌): support all true check function requireAllTrue
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Sep 29, 2021
1 parent 7497cdb commit 394af7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private BooleanCheck() {
* @return the throw exception function
* @see com.jmsoftware.maf.springcloudstarter.FunctionalInterfaceTests#testRequireTrue()
*/
public static OrElseThrowExceptionFunction requireTrue(Boolean aBoolean, Consumer<Boolean> after) {
public static OrElseThrowExceptionFunction requireTrue(boolean aBoolean, Consumer<Boolean> after) {
if (nonNull(after)) {
after.accept(aBoolean);
}
Expand All @@ -34,4 +34,21 @@ public static OrElseThrowExceptionFunction requireTrue(Boolean aBoolean, Consume
}
};
}

/**
* Require all true or else throw exception function.
*
* @param booleans the booleans
* @return the or else throw exception function
* @see com.jmsoftware.maf.springcloudstarter.FunctionalInterfaceTests#testRequireTrue()
*/
public static OrElseThrowExceptionFunction requireAllTrue(boolean... booleans) {
return exceptionSupplier -> {
for (boolean aBoolean : booleans) {
if (BooleanUtil.isFalse(aBoolean)) {
throw exceptionSupplier.get();
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;

import static com.jmsoftware.maf.springcloudstarter.function.BooleanCheck.requireAllTrue;
import static com.jmsoftware.maf.springcloudstarter.function.BooleanCheck.requireTrue;
import static com.jmsoftware.maf.springcloudstarter.function.Cache.cacheFunction;
import static com.jmsoftware.maf.springcloudstarter.function.ExceptionHandling.computeAndHandleException;
Expand Down Expand Up @@ -44,6 +45,13 @@ void testRequireTrue() {
.orElseThrow(() -> new IllegalArgumentException("aBoolean is expected to be true")),
"requireTrue doesn't throws exception"
);

Assertions.assertThrows(
IllegalArgumentException.class,
() -> requireAllTrue(1 != 1, 2 == 2, 3 == 3)
.orElseThrow(() -> new IllegalArgumentException("Boolean array is expected to be all true")),
"requireTrue doesn't throws exception"
);
}

/**
Expand Down

0 comments on commit 394af7a

Please sign in to comment.