ActionSupport.java

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
Location : nop
Killed by : com.github.dakusui.actionunit.ut.actions.TimeoutTest.givenNonPositive$whenCreateTimeoutAction$thenIllegalArgument(com.github.dakusui.actionunit.ut.actions.TimeoutTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::nop → KILLED

30

1.1
Location : leaf
Killed by : com.github.dakusui.actionunit.ut.actions.LeafTest.givenAnonymousLeaf$whenToString$thenNoname(com.github.dakusui.actionunit.ut.actions.LeafTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::leaf → KILLED

34

1.1
Location : named
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenNamesAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::named → KILLED

38

1.1
Location : attempt
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenAttemptAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::attempt → KILLED

42

1.1
Location : forEach
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/core/ActionSupport::forEach → KILLED

55

1.1
Location : forEach
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/core/ActionSupport::forEach → KILLED

59

1.1
Location : repeatWhile
Killed by : com.github.dakusui.actionunit.ut.actions.WhileTest.givenWhileActionWithConditionNeverMet_whenPerform_thenNothingHappens(com.github.dakusui.actionunit.ut.actions.WhileTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::repeatWhile → KILLED

63

1.1
Location : when
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.givenWhenAction$whenNotMet$thenOtherwise(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::when → KILLED

67

1.1
Location : with
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/core/ActionSupport::with → KILLED

80

1.1
Location : with
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/core/ActionSupport::with → KILLED

84

1.1
Location : retry
Killed by : com.github.dakusui.actionunit.scenarios.CompatActionSupportTest.givenRetryAction$whenDescribe$thenLooksNice(com.github.dakusui.actionunit.scenarios.CompatActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::retry → KILLED

88

1.1
Location : timeout
Killed by : com.github.dakusui.actionunit.ut.actions.TimeoutTest.givenNonPositive$whenCreateTimeoutAction$thenIllegalArgument(com.github.dakusui.actionunit.ut.actions.TimeoutTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::timeout → KILLED

92

1.1
Location : sequential
Killed by : com.github.dakusui.actionunit.ut.actions.CompositeTest.givenSequentialActionAndNonCompositeAction$whenEquals$thenFalse(com.github.dakusui.actionunit.ut.actions.CompositeTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::sequential → KILLED

96

1.1
Location : parallel
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.givenParallelAction$whenPerformed$thenWorksFine(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::parallel → KILLED

100

1.1
Location : cmd
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander.givenCommanderObject$whenExerciseGetters$thenNoExceptionThrown(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::cmd → KILLED

107

1.1
Location : cmd
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander.givenCommanderObject$whenExerciseGetters$thenNoExceptionThrown(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsCommander)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::cmd → KILLED

111

1.1
Location : unix
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.UnixTest.test(com.github.dakusui.actionunit.ut.actions.cmd.UnixTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::unix → KILLED

115

1.1
Location : unix
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.UnixTest.test(com.github.dakusui.actionunit.ut.actions.cmd.UnixTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::unix → KILLED

119

1.1
Location : simple
Killed by : com.github.dakusui.actionunit.ut.actions.LeafTest.givenAnonymousLeaf$whenToString$thenNoname(com.github.dakusui.actionunit.ut.actions.LeafTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::simple → KILLED

123

1.1
Location : sequential
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.givenSequentialAction$whenPerformed$thenWorksFine(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::sequential → KILLED

127

1.1
Location : parallel
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.givenParallelAction$whenPerformed$thenWorksFine(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::parallel → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3