Contextful.java

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
Location : valueSource
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenForEachAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Base::valueSource → KILLED

61

1.1
Location : action
Killed by : com.github.dakusui.actionunit.ut.VariationTest.forEachAndPipedAction(com.github.dakusui.actionunit.ut.VariationTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Base::action → KILLED

66

1.1
Location : variableName
Killed by : com.github.dakusui.actionunit.ut.ReportingActionPerformerTest$CompatForEachAction.givenFailingConcurrentAction$whenPerformed$thenWorksFine(com.github.dakusui.actionunit.ut.ReportingActionPerformerTest$CompatForEachAction)
replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Base::variableName → KILLED

71

1.1
Location : internalVariableName
Killed by : com.github.dakusui.actionunit.ut.VariationTest.doubleLoop(com.github.dakusui.actionunit.ut.VariationTest)
replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Base::internalVariableName → KILLED

98

1.1
Location : action
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenForEachAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::action → KILLED

103

1.1
Location : action
Killed by : com.github.dakusui.actionunit.ut.VariationTest.doubleLoop(com.github.dakusui.actionunit.ut.VariationTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::action → KILLED

107

1.1
Location : perform
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenForEachAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::perform → KILLED

111

1.1
Location : perform
Killed by : com.github.dakusui.actionunit.ut.VariationTest.doubleLoop(com.github.dakusui.actionunit.ut.VariationTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::perform → KILLED

116

1.1
Location : action
Killed by : com.github.dakusui.actionunit.ut.VariationTest.forEachAndPipedAction(com.github.dakusui.actionunit.ut.VariationTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::action → KILLED

120

1.1
Location : variableName
Killed by : com.github.dakusui.actionunit.ut.ReportingActionPerformerTest$CompatForEachAction.givenFailingConcurrentAction$whenPerformed$thenWorksFine(com.github.dakusui.actionunit.ut.ReportingActionPerformerTest$CompatForEachAction)
replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::variableName → KILLED

124

1.1
Location : internalVariableName
Killed by : com.github.dakusui.actionunit.ut.VariationTest.doubleLoop(com.github.dakusui.actionunit.ut.VariationTest)
replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::internalVariableName → KILLED

128

1.1
Location : valueSource
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenForEachAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::valueSource → KILLED

138

1.1
Location : toAction
Killed by : com.github.dakusui.actionunit.ut.actions.ForEachTest.givenForEach2Action$whenPerformWithReporting$worksCorrectly(com.github.dakusui.actionunit.ut.actions.ForEachTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::toAction → KILLED

139

1.1
Location : lambda$toAction$0
Killed by : com.github.dakusui.actionunit.ut.actions.ForEachTest.givenForEach2Action$whenPerformWithReporting$worksCorrectly(com.github.dakusui.actionunit.ut.actions.ForEachTest)
removed call to java/util/function/Consumer::accept → KILLED

143

1.1
Location : function
Killed by : com.github.dakusui.actionunit.ut.actions.WithTest.printActionTree_4(com.github.dakusui.actionunit.ut.actions.WithTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::function → KILLED

148

1.1
Location : consumer
Killed by : com.github.dakusui.actionunit.ut.actions.WithTest.printActionTree_2(com.github.dakusui.actionunit.ut.actions.WithTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::consumer → KILLED

152

1.1
Location : predicate
Killed by : com.github.dakusui.actionunit.ut.actions.WithTest.printActionTree_2(com.github.dakusui.actionunit.ut.actions.WithTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::predicate → KILLED

156

1.1
Location : resolveValue
Killed by : com.github.dakusui.actionunit.ut.VariationTest.doubleLoop(com.github.dakusui.actionunit.ut.VariationTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::resolveValue → KILLED

160

1.1
Location : toString
Killed by : none
replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::toString → SURVIVED

164

1.1
Location : composeInternalVariableName
Killed by : com.github.dakusui.actionunit.ut.VariationTest.doubleLoop(com.github.dakusui.actionunit.ut.VariationTest)
replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::composeInternalVariableName → KILLED

168

1.1
Location : lambda$variableReferenceConsumer$1
Killed by : com.github.dakusui.actionunit.ut.actions.ForEachTest.givenForEach2Action$whenPerformWithReporting$worksCorrectly(com.github.dakusui.actionunit.ut.actions.ForEachTest)
removed call to java/util/function/Consumer::accept → KILLED

2.2
Location : variableReferenceConsumer
Killed by : com.github.dakusui.actionunit.ut.actions.ForEachTest.givenForEach2Action$whenPerformWithReporting$worksCorrectly(com.github.dakusui.actionunit.ut.actions.ForEachTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::variableReferenceConsumer → KILLED

172

1.1
Location : lambda$toContextFunction$2
Killed by : none
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::lambda$toContextFunction$2 → NO_COVERAGE

2.2
Location : toContextFunction
Killed by : com.github.dakusui.actionunit.ut.actions.WithTest.printActionTree_4(com.github.dakusui.actionunit.ut.actions.WithTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::toContextFunction → KILLED

177

1.1
Location : lambda$toContextConsumer$3
Killed by : com.github.dakusui.actionunit.ut.actions.WithTest.givenWithAction_whenPerform2(com.github.dakusui.actionunit.ut.actions.WithTest)
removed call to java/util/function/Consumer::accept → KILLED

2.2
Location : toContextConsumer
Killed by : com.github.dakusui.actionunit.ut.actions.WithTest.printActionTree_2(com.github.dakusui.actionunit.ut.actions.WithTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::toContextConsumer → KILLED

182

1.1
Location : toContextPredicate
Killed by : com.github.dakusui.actionunit.ut.actions.WithTest.printActionTree_2(com.github.dakusui.actionunit.ut.actions.WithTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Contextful$Builder::toContextPredicate → KILLED

183

1.1
Location : lambda$toContextPredicate$4
Killed by : com.github.dakusui.actionunit.ut.actions.WithTest.givenWithAction_whenPerform3(com.github.dakusui.actionunit.ut.actions.WithTest)
replaced boolean return with false for com/github/dakusui/actionunit/actions/Contextful$Builder::lambda$toContextPredicate$4 → KILLED

2.2
Location : lambda$toContextPredicate$4
Killed by : none
replaced boolean return with true for com/github/dakusui/actionunit/actions/Contextful$Builder::lambda$toContextPredicate$4 → TIMED_OUT

184

1.1
Location : lambda$toContextPredicate$5
Killed by : none
replaced return value with "" for com/github/dakusui/actionunit/actions/Contextful$Builder::lambda$toContextPredicate$5 → SURVIVED

Active mutators

Tests examined


Report generated by PIT 1.7.3