org.requirementsascode.InterruptingFlowStep Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of requirementsascodecore Show documentation
Show all versions of requirementsascodecore Show documentation
Enables you to define and run executable use case specifications, in your code.
package org.requirementsascode;
import java.util.function.Predicate;
import org.requirementsascode.flowposition.FlowPosition;
public class InterruptingFlowStep extends FlowStep {
private static final long serialVersionUID = 7204738737376844201L;
InterruptingFlowStep(String stepName, Flow useCaseFlow, FlowPosition flowPosition, Condition condition) {
super(stepName, useCaseFlow, condition);
setFlowPosition(flowPosition);
}
public Predicate getPredicate() {
Predicate predicate;
Condition reactWhile = getReactWhile();
predicate = isFlowConditionTrueAndRunnerInDifferentFlow();
if (reactWhile != null) {
predicate = predicate.and(toPredicate(reactWhile));
}
return predicate;
}
private Predicate isFlowConditionTrueAndRunnerInDifferentFlow() {
Predicate flowPosition = getFlowPosition();
Condition conditionOrElseTrue = getCondition().orElse(() -> true);
Predicate flowCondition = isRunnerInDifferentFlow().and(flowPosition)
.and(toPredicate(conditionOrElseTrue));
return flowCondition;
}
private Predicate isRunnerInDifferentFlow() {
Predicate isRunnerInDifferentFlow = runner -> runner.getLatestFlow()
.map(runnerFlow -> !runnerFlow.equals(getFlow())).orElse(true);
return isRunnerInDifferentFlow;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy