com.github.dakusui.actionunit.actions.Leaf Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of actionunit Show documentation
Show all versions of actionunit Show documentation
A library to build 'action' structure for testing
package com.github.dakusui.actionunit.actions;
import com.github.dakusui.actionunit.core.Action;
import com.github.dakusui.actionunit.core.Context;
import com.github.dakusui.actionunit.core.ContextConsumer;
import java.util.Formatter;
import java.util.function.Function;
import static java.util.Objects.requireNonNull;
public interface Leaf extends Action, Function {
Runnable runnable(Context context);
default Runnable apply(Context context) {
return runnable(context);
}
default void accept(Visitor visitor) {
visitor.visit(this);
}
static Leaf of(ContextConsumer consumer) {
requireNonNull(consumer);
return new Leaf() {
@Override
public Runnable runnable(Context context) {
return () -> consumer.accept(context);
}
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision) {
formatter.format("%s", consumer);
}
};
}
}