1 | package com.github.dakusui.actionunit.actions; | |
2 | ||
3 | import com.github.dakusui.actionunit.core.Action; | |
4 | import com.github.dakusui.actionunit.core.Context; | |
5 | ||
6 | import java.util.function.Consumer; | |
7 | import java.util.function.Function; | |
8 | import java.util.function.Predicate; | |
9 | ||
10 | import static com.github.dakusui.actionunit.core.ActionSupport.simple; | |
11 | import static com.github.dakusui.actionunit.utils.InternalUtils.toStringIfOverriddenOrNoname; | |
12 | import static com.github.dakusui.printables.PrintableFunctionals.*; | |
13 | import static java.util.Objects.requireNonNull; | |
14 | ||
15 | public interface Contextful<S> extends Action, ContextVariable { | |
16 | /** | |
17 | * A function to provide a value referenced from inside an action returned by the | |
18 | * {@link Contextful#action()} method. | |
19 | * | |
20 | * @return A function to provide a value for an action. | |
21 | */ | |
22 | Function<Context, S> valueSource(); | |
23 | ||
24 | /** | |
25 | * Returns a main action. | |
26 | * | |
27 | * @return A main action. | |
28 | */ | |
29 | Action action(); | |
30 | ||
31 | @Override | |
32 | String variableName(); | |
33 | ||
34 | @Override | |
35 | String internalVariableName(); | |
36 | ||
37 | abstract class Base<V, S> implements Contextful<S> { | |
38 | private final String variableName; | |
39 | ||
40 | private final String internalVariableName; | |
41 | ||
42 | private final Function<Context, S> valueSource; | |
43 | ||
44 | private final Action action; | |
45 | ||
46 | ||
47 | public Base(String variableName, final String internalVariableName, Function<Context, S> valueSource, Action action) { | |
48 | this.variableName = variableName; | |
49 | this.internalVariableName = internalVariableName; | |
50 | this.valueSource = valueSource; | |
51 | this.action = action; | |
52 | } | |
53 | ||
54 | @Override | |
55 | public Function<Context, S> valueSource() { | |
56 |
1
1. valueSource : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Base::valueSource → KILLED |
return valueSource; |
57 | } | |
58 | ||
59 | @Override | |
60 | public Action action() { | |
61 |
1
1. action : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Base::action → KILLED |
return action; |
62 | } | |
63 | ||
64 | @Override | |
65 | public String variableName() { | |
66 |
1
1. variableName : replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Base::variableName → KILLED |
return variableName; |
67 | } | |
68 | ||
69 | @Override | |
70 | public String internalVariableName() { | |
71 |
1
1. internalVariableName : replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Base::internalVariableName → KILLED |
return internalVariableName; |
72 | } | |
73 | ||
74 | } | |
75 | ||
76 | abstract class Builder< | |
77 | B extends Builder<B, A, V, S>, | |
78 | A extends Contextful<S>, | |
79 | V, | |
80 | S> | |
81 | extends Action.Builder<A> | |
82 | implements ContextVariable { | |
83 | private final Function<Context, S> valueSource; | |
84 | private final String internalVariableName; | |
85 | private final String variableName; | |
86 | ||
87 | private Action action; | |
88 | ||
89 | protected Builder(String variableName, Function<Context, S> function) { | |
90 | this.variableName = requireNonNull(variableName); | |
91 | this.internalVariableName = composeInternalVariableName(variableName); | |
92 | this.valueSource = requireNonNull(function); | |
93 | } | |
94 | ||
95 | @SuppressWarnings("unchecked") | |
96 | public B action(Action action) { | |
97 | this.action = requireNonNull(action); | |
98 |
1
1. action : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::action → KILLED |
return (B) this; |
99 | } | |
100 | ||
101 | @SuppressWarnings("unchecked") | |
102 | public B action(Function<B, Action> action) { | |
103 |
1
1. action : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::action → KILLED |
return this.action(action.apply((B) this)); |
104 | } | |
105 | ||
106 | public A perform(Action action) { | |
107 |
1
1. perform : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::perform → KILLED |
return action(action).build(); |
108 | } | |
109 | ||
110 | public A perform(Function<B, Action> action) { | |
111 |
1
1. perform : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::perform → KILLED |
return this.action(action).build(); |
112 | } | |
113 | ||
114 | ||
115 | public Action action() { | |
116 |
1
1. action : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::action → KILLED |
return this.action; |
117 | } | |
118 | ||
119 | public String variableName() { | |
120 |
1
1. variableName : replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::variableName → KILLED |
return this.variableName; |
121 | } | |
122 | ||
123 | public String internalVariableName() { | |
124 |
1
1. internalVariableName : replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::internalVariableName → KILLED |
return this.internalVariableName; |
125 | } | |
126 | ||
127 | public Function<Context, S> valueSource() { | |
128 |
1
1. valueSource : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::valueSource → KILLED |
return this.valueSource; |
129 | } | |
130 | ||
131 | /** | |
132 | * Creates an action that consumes the context variable. | |
133 | * | |
134 | * @param consumer A consumer that processes the context variable. | |
135 | * @return A created action. | |
136 | */ | |
137 | public Action toAction(Consumer<V> consumer) { | |
138 |
1
1. toAction : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::toAction → KILLED |
return simple("action:" + variableName(), |
139 |
1
1. lambda$toAction$0 : removed call to java/util/function/Consumer::accept → KILLED |
printableConsumer((Context c) -> variableReferenceConsumer(consumer).accept(c)).describe(toStringIfOverriddenOrNoname(consumer))); |
140 | } | |
141 | ||
142 | public <W> Function<Context, W> function(Function<V, W> function) { | |
143 |
1
1. function : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::function → KILLED |
return toContextFunction(this, function); |
144 | ||
145 | } | |
146 | ||
147 | public Consumer<Context> consumer(Consumer<V> consumer) { | |
148 |
1
1. consumer : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::consumer → KILLED |
return toContextConsumer(this, consumer); |
149 | } | |
150 | ||
151 | public Predicate<Context> predicate(Predicate<V> predicate) { | |
152 |
1
1. predicate : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::predicate → KILLED |
return toContextPredicate(this, predicate); |
153 | } | |
154 | ||
155 | public V resolveValue(Context context) { | |
156 |
1
1. resolveValue : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::resolveValue → KILLED |
return this.resolve(context); |
157 | } | |
158 | ||
159 | public String toString() { | |
160 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::toString → SURVIVED |
return variableName(); |
161 | } | |
162 | ||
163 | protected String composeInternalVariableName(String variableName) { | |
164 |
1
1. composeInternalVariableName : replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::composeInternalVariableName → KILLED |
return this.getClass().getEnclosingClass().getCanonicalName() + ":" + variableName + ":" + System.identityHashCode(this); |
165 | } | |
166 | ||
167 | private Consumer<Context> variableReferenceConsumer(Consumer<V> consumer) { | |
168 |
2
1. lambda$variableReferenceConsumer$1 : removed call to java/util/function/Consumer::accept → KILLED 2. variableReferenceConsumer : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::variableReferenceConsumer → KILLED |
return (Context context) -> consumer.accept(this.resolveValue(context)); |
169 | } | |
170 | ||
171 | private static <V, W> Function<Context, W> toContextFunction(Builder<?, ?, V, ?> builder, Function<V, W> function) { | |
172 |
2
1. lambda$toContextFunction$2 : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::lambda$toContextFunction$2 → NO_COVERAGE 2. toContextFunction : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::toContextFunction → KILLED |
return printableFunction((Context context) -> function.apply(builder.resolveValue(context))) |
173 | .describe(toStringIfOverriddenOrNoname(function)); | |
174 | } | |
175 | ||
176 | private static <V> Consumer<Context> toContextConsumer(Builder<?, ?, V, ?> builder, Consumer<V> consumer) { | |
177 |
2
1. lambda$toContextConsumer$3 : removed call to java/util/function/Consumer::accept → KILLED 2. toContextConsumer : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::toContextConsumer → KILLED |
return printableConsumer((Context context) -> consumer.accept(builder.resolveValue(context))) |
178 | .describe(toStringIfOverriddenOrNoname(consumer)); | |
179 | } | |
180 | ||
181 | private static <V> Predicate<Context> toContextPredicate(Builder<?, ?, V, ?> builder, Predicate<V> predicate) { | |
182 |
1
1. toContextPredicate : replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::toContextPredicate → KILLED |
return printablePredicate( |
183 |
2
1. lambda$toContextPredicate$4 : replaced boolean return with true for com/github/dakusui/actionunit/actions/Contextful$Builder::lambda$toContextPredicate$4 → TIMED_OUT 2. lambda$toContextPredicate$4 : replaced boolean return with false for com/github/dakusui/actionunit/actions/Contextful$Builder::lambda$toContextPredicate$4 → KILLED |
(Context context) -> predicate.test(builder.resolveValue(context))) |
184 |
1
1. lambda$toContextPredicate$5 : replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::lambda$toContextPredicate$5 → SURVIVED |
.describe(() -> builder.variableName() + ":" + toStringIfOverriddenOrNoname(predicate)); |
185 | } | |
186 | ||
187 | } | |
188 | } | |
Mutations | ||
56 |
1.1 |
|
61 |
1.1 |
|
66 |
1.1 |
|
71 |
1.1 |
|
98 |
1.1 |
|
103 |
1.1 |
|
107 |
1.1 |
|
111 |
1.1 |
|
116 |
1.1 |
|
120 |
1.1 |
|
124 |
1.1 |
|
128 |
1.1 |
|
138 |
1.1 |
|
139 |
1.1 |
|
143 |
1.1 |
|
148 |
1.1 |
|
152 |
1.1 |
|
156 |
1.1 |
|
160 |
1.1 |
|
164 |
1.1 |
|
168 |
1.1 2.2 |
|
172 |
1.1 2.2 |
|
177 |
1.1 2.2 |
|
182 |
1.1 |
|
183 |
1.1 2.2 |
|
184 |
1.1 |