1 | package com.github.dakusui.actionunit.core; | |
2 | ||
3 | import com.github.dakusui.actionunit.actions.*; | |
4 | import com.github.dakusui.actionunit.actions.cmd.CommanderConfig; | |
5 | import com.github.dakusui.actionunit.actions.cmd.UnixCommanderFactory; | |
6 | import com.github.dakusui.actionunit.actions.cmd.unix.Cmd; | |
7 | ||
8 | import java.util.List; | |
9 | import java.util.function.Consumer; | |
10 | import java.util.function.Function; | |
11 | import java.util.function.Predicate; | |
12 | import java.util.stream.Stream; | |
13 | ||
14 | import static com.github.dakusui.actionunit.core.context.ContextConsumer.NOP_CONSUMER; | |
15 | import static com.github.dakusui.actionunit.utils.InternalUtils.toStringIfOverriddenOrNoname; | |
16 | import static com.github.dakusui.printables.PrintableFunctionals.printableConsumer; | |
17 | import static java.util.Arrays.asList; | |
18 | import static java.util.Objects.requireNonNull; | |
19 | ||
20 | public enum ActionSupport { | |
21 | ; | |
22 | ||
23 | public static Action nop() { | |
24 | // Needs to be instantiated each time this method is called. | |
25 | // Otherwise, multiple nops cannot be identified in an action tree. | |
26 |
1
1. nop : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::nop → KILLED |
return Leaf.of(NOP_CONSUMER); |
27 | } | |
28 | ||
29 | public static Action leaf(Consumer<Context> consumer) { | |
30 |
1
1. leaf : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::leaf → KILLED |
return Leaf.of(consumer); |
31 | } | |
32 | ||
33 | public static Action named(String name, Action action) { | |
34 |
1
1. named : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::named → KILLED |
return Named.of(name, action); |
35 | } | |
36 | ||
37 | public static Attempt.Builder attempt(Action action) { | |
38 |
1
1. attempt : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::attempt → KILLED |
return new Attempt.Builder(action); |
39 | } | |
40 | ||
41 | public static <E> ForEach.Builder<E> forEach(Function<Context, Stream<E>> streamGenerator) { | |
42 |
1
1. forEach : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::forEach → KILLED |
return forEach("i", streamGenerator); |
43 | } | |
44 | ||
45 | /** | |
46 | * Note that the `variableName` is only used for printing the variable in an action tree. | |
47 | * Not used for identifying a corresponding entry in the context. | |
48 | * | |
49 | * @param variableName A name of variable. | |
50 | * @param streamGenerator A function to return stream. | |
51 | * @param <E> The type of the loop variable. | |
52 | * @return A builder for `ForEach2` action | |
53 | */ | |
54 | public static <E> ForEach.Builder<E> forEach(String variableName, Function<Context, Stream<E>> streamGenerator) { | |
55 |
1
1. forEach : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::forEach → KILLED |
return new ForEach.Builder<>(variableName, streamGenerator); |
56 | } | |
57 | ||
58 | public static While.Builder repeatWhile(Predicate<Context> condition) { | |
59 |
1
1. repeatWhile : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::repeatWhile → KILLED |
return new While.Builder(condition); |
60 | } | |
61 | ||
62 | public static When.Builder when(Predicate<Context> cond) { | |
63 |
1
1. when : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::when → KILLED |
return new When.Builder(cond); |
64 | } | |
65 | ||
66 | public static <T> With.Builder<T> with(Function<Context, T> value) { | |
67 |
1
1. with : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::with → KILLED |
return with("i", value); |
68 | } | |
69 | ||
70 | /** | |
71 | * Note that `variableName` won't be used to resolve a value of a variable, it is | |
72 | * merely intended to be printed in an action-tree or logs. | |
73 | * | |
74 | * @param variableName human-readable variable name. | |
75 | * @param value A function to give a value to be used a context under the returned action. | |
76 | * @param <T> The type of the variable | |
77 | * @return A builder for a `with` action. | |
78 | */ | |
79 | public static <T> With.Builder<T> with(String variableName, Function<Context, T> value) { | |
80 |
1
1. with : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::with → KILLED |
return new With.Builder<>(variableName, value); |
81 | } | |
82 | ||
83 | public static Retry.Builder retry(Action action) { | |
84 |
1
1. retry : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::retry → KILLED |
return new Retry.Builder(action); |
85 | } | |
86 | ||
87 | public static TimeOut.Builder timeout(Action action) { | |
88 |
1
1. timeout : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::timeout → KILLED |
return new TimeOut.Builder(action); |
89 | } | |
90 | ||
91 | public static Action sequential(List<Action> actions) { | |
92 |
1
1. sequential : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::sequential → KILLED |
return new Composite.Builder(actions).build(); |
93 | } | |
94 | ||
95 | public static Action parallel(List<Action> actions) { | |
96 |
1
1. parallel : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::parallel → KILLED |
return new Composite.Builder(actions).parallel().build(); |
97 | } | |
98 | ||
99 | public static Cmd cmd(String program, ContextVariable... knownVariables) { | |
100 |
1
1. cmd : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::cmd → KILLED |
return cmd(program, CommanderConfig.DEFAULT, knownVariables); |
101 | } | |
102 | ||
103 | public static Cmd cmd(String program, CommanderConfig config, ContextVariable... knownVariables) { | |
104 | Cmd ret = new Cmd(config).commandName(requireNonNull(program).trim()); | |
105 | for (ContextVariable each : knownVariables) | |
106 | ret = ret.declareVariable(each); | |
107 |
1
1. cmd : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::cmd → KILLED |
return ret.append(" "); |
108 | } | |
109 | ||
110 | public static UnixCommanderFactory unix() { | |
111 |
1
1. unix : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::unix → KILLED |
return unix(CommanderConfig.DEFAULT); |
112 | } | |
113 | ||
114 | public static UnixCommanderFactory unix(CommanderConfig config) { | |
115 |
1
1. unix : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::unix → KILLED |
return UnixCommanderFactory.create(config); |
116 | } | |
117 | ||
118 | public static Action simple(String name, Consumer<Context> consumer) { | |
119 |
1
1. simple : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::simple → KILLED |
return leaf(printableConsumer(consumer).describe(name + ":" + toStringIfOverriddenOrNoname(consumer))); |
120 | } | |
121 | ||
122 | public static Action sequential(Action... actions) { | |
123 |
1
1. sequential : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::sequential → KILLED |
return sequential(asList(actions)); |
124 | } | |
125 | ||
126 | public static Action parallel(Action... actions) { | |
127 |
1
1. parallel : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::parallel → KILLED |
return parallel(asList(actions)); |
128 | } | |
129 | } | |
130 | ||
Mutations | ||
26 |
1.1 |
|
30 |
1.1 |
|
34 |
1.1 |
|
38 |
1.1 |
|
42 |
1.1 |
|
55 |
1.1 |
|
59 |
1.1 |
|
63 |
1.1 |
|
67 |
1.1 |
|
80 |
1.1 |
|
84 |
1.1 |
|
88 |
1.1 |
|
92 |
1.1 |
|
96 |
1.1 |
|
100 |
1.1 |
|
107 |
1.1 |
|
111 |
1.1 |
|
115 |
1.1 |
|
119 |
1.1 |
|
123 |
1.1 |
|
127 |
1.1 |