|
|
|
@ -17,12 +17,28 @@
|
|
|
|
|
|
|
|
|
|
package cn.hippo4j.common.toolkit;
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.common.function.NoArgsConsumer;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
|
|
public class ConditionUtilTest {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void assertCondition() {
|
|
|
|
|
|
|
|
|
|
// init consumer
|
|
|
|
|
AtomicBoolean checkValue = new AtomicBoolean(false);
|
|
|
|
|
NoArgsConsumer trueConsumer = () -> checkValue.set(true);
|
|
|
|
|
NoArgsConsumer falseConsumer = () -> checkValue.set(false);
|
|
|
|
|
|
|
|
|
|
// test trueConsumer run
|
|
|
|
|
ConditionUtil.condition(true, trueConsumer, falseConsumer);
|
|
|
|
|
Assert.isTrue(checkValue.get());
|
|
|
|
|
|
|
|
|
|
// test falseConsumer run
|
|
|
|
|
ConditionUtil.condition(false, trueConsumer, falseConsumer);
|
|
|
|
|
Assert.isTrue(!checkValue.get());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|