Context.java

1
package com.github.dakusui.actionunit.core;
2
3
import java.util.HashMap;
4
import java.util.Map;
5
import java.util.NoSuchElementException;
6
7
import static com.github.dakusui.actionunit.core.Context.Impl.ONGOING_EXCEPTION;
8
import static java.util.Objects.requireNonNull;
9
10
public interface Context {
11
12
  Context createChild();
13
14
  boolean defined(String variableName);
15
16
  <V> V valueOf(String variableName);
17
18
  Context assignTo(String variableName, Object value);
19
20
  void unassign(String variableName);
21
22
  <T extends Throwable> T thrownException();
23
24
  default boolean wasExceptionThrown() {
25 2 1. wasExceptionThrown : replaced boolean return with true for com/github/dakusui/actionunit/core/Context::wasExceptionThrown → SURVIVED
2. wasExceptionThrown : replaced boolean return with false for com/github/dakusui/actionunit/core/Context::wasExceptionThrown → KILLED
    return defined(ONGOING_EXCEPTION);
26
  }
27
28
  class Impl implements Context {
29
    public static final String              ONGOING_EXCEPTION = "ONGOING_EXCEPTION";
30
    private final       Map<String, Object> variables         = new HashMap<>();
31
    private final       Context             parent;
32
33
    public Impl() {
34
      this(null);
35
    }
36
37
    public Impl(Context parent) {
38
      this.parent = parent;
39
    }
40
41
    @Override
42
    public Context createChild() {
43 1 1. createChild : replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::createChild → KILLED
      return new Impl(this);
44
    }
45
46
    @Override
47
    public boolean defined(String variableName) {
48 1 1. defined : negated conditional → KILLED
      if (this.variables.containsKey(variableName))
49 1 1. defined : replaced boolean return with false for com/github/dakusui/actionunit/core/Context$Impl::defined → TIMED_OUT
        return true;
50 1 1. defined : negated conditional → KILLED
      if (this.parent == null)
51 1 1. defined : replaced boolean return with true for com/github/dakusui/actionunit/core/Context$Impl::defined → KILLED
        return false;
52 2 1. defined : replaced boolean return with false for com/github/dakusui/actionunit/core/Context$Impl::defined → NO_COVERAGE
2. defined : replaced boolean return with true for com/github/dakusui/actionunit/core/Context$Impl::defined → NO_COVERAGE
      return parent.defined(variableName);
53
    }
54
55
    @SuppressWarnings("unchecked")
56
    @Override
57
    public <V> V valueOf(String variableName) {
58 1 1. valueOf : negated conditional → KILLED
      if (this.variables.containsKey(requireNonNull(variableName)))
59 1 1. valueOf : replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::valueOf → KILLED
        return (V) this.variables.get(variableName);
60 1 1. valueOf : negated conditional → KILLED
      if (parent == null)
61
        throw new NoSuchElementException(String.format("Variable '%s' is not defined.", variableName));
62 1 1. valueOf : replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::valueOf → KILLED
      return parent.valueOf(variableName);
63
    }
64
65
    @Override
66
    public Context assignTo(String variableName, Object value) {
67
      this.variables.put(variableName, value);
68 1 1. assignTo : replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::assignTo → KILLED
      return this;
69
    }
70
71
    @Override
72
    public void unassign(String variableName) {
73
      this.variables.remove(variableName);
74
    }
75
76
    @SuppressWarnings("unchecked")
77
    @Override
78
    public <T extends Throwable> T thrownException() {
79 1 1. thrownException : replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::thrownException → KILLED
      return (T) this.variables.get(ONGOING_EXCEPTION);
80
    }
81
82
    @Override
83
    public String toString() {
84 1 1. toString : replaced return value with "" for com/github/dakusui/actionunit/core/Context$Impl::toString → SURVIVED
      return String.format("Context:(%s; parent=%s)", variables, parent);
85
    }
86
  }
87
88
  static Context create() {
89 1 1. create : replaced return value with null for com/github/dakusui/actionunit/core/Context::create → KILLED
    return new Impl();
90
  }
91
}

Mutations

25

1.1
Location : wasExceptionThrown
Killed by : com.github.dakusui.actionunit.scenarios.Compat2ActionSupportTest$AttemptTest.attemptTest2(com.github.dakusui.actionunit.scenarios.Compat2ActionSupportTest$AttemptTest)
replaced boolean return with false for com/github/dakusui/actionunit/core/Context::wasExceptionThrown → KILLED

2.2
Location : wasExceptionThrown
Killed by : none
replaced boolean return with true for com/github/dakusui/actionunit/core/Context::wasExceptionThrown → SURVIVED

43

1.1
Location : createChild
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/Context$Impl::createChild → KILLED

48

1.1
Location : defined
Killed by : com.github.dakusui.actionunit.ut.actions.WhileTest.givenWhileActionWithConditionNeverMet_whenPerform_thenNothingHappens(com.github.dakusui.actionunit.ut.actions.WhileTest)
negated conditional → KILLED

49

1.1
Location : defined
Killed by : none
replaced boolean return with false for com/github/dakusui/actionunit/core/Context$Impl::defined → TIMED_OUT

50

1.1
Location : defined
Killed by : com.github.dakusui.actionunit.ut.actions.WhileTest.givenWhileActionWithConditionNeverMet_whenPerform_thenNothingHappens(com.github.dakusui.actionunit.ut.actions.WhileTest)
negated conditional → KILLED

51

1.1
Location : defined
Killed by : com.github.dakusui.actionunit.ut.actions.WhileTest.givenWhileActionWithConditionNeverMet_whenPerform_thenNothingHappens(com.github.dakusui.actionunit.ut.actions.WhileTest)
replaced boolean return with true for com/github/dakusui/actionunit/core/Context$Impl::defined → KILLED

52

1.1
Location : defined
Killed by : none
replaced boolean return with false for com/github/dakusui/actionunit/core/Context$Impl::defined → NO_COVERAGE

2.2
Location : defined
Killed by : none
replaced boolean return with true for com/github/dakusui/actionunit/core/Context$Impl::defined → NO_COVERAGE

58

1.1
Location : valueOf
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.givenRetryWithPassingAction$whenPerform$thenNoRetry(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
negated conditional → KILLED

59

1.1
Location : valueOf
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.givenRetryWithPassingAction$whenPerform$thenNoRetry(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::valueOf → KILLED

60

1.1
Location : valueOf
Killed by : com.github.dakusui.actionunit.ut.actions.AttemptTest.givenAttemptAction$whenPerform$thenWorksFine(com.github.dakusui.actionunit.ut.actions.AttemptTest)
negated conditional → KILLED

62

1.1
Location : valueOf
Killed by : com.github.dakusui.actionunit.ut.actions.AttemptTest.givenAttemptAction$whenPerform$thenWorksFine(com.github.dakusui.actionunit.ut.actions.AttemptTest)
replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::valueOf → KILLED

68

1.1
Location : assignTo
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test2(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::assignTo → KILLED

79

1.1
Location : thrownException
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.giveExampleScenarioThatThrowsError$whenPerform$thenExceptionThrown(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/core/Context$Impl::thrownException → KILLED

84

1.1
Location : toString
Killed by : none
replaced return value with "" for com/github/dakusui/actionunit/core/Context$Impl::toString → SURVIVED

89

1.1
Location : create
Killed by : com.github.dakusui.actionunit.scenarios.CompatActionSupportTest.unsupportedActionType$composite(com.github.dakusui.actionunit.scenarios.CompatActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/core/Context::create → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3