| 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 2.2 |
|
| 43 |
1.1 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 51 |
1.1 |
|
| 52 |
1.1 2.2 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 60 |
1.1 |
|
| 62 |
1.1 |
|
| 68 |
1.1 |
|
| 79 |
1.1 |
|
| 84 |
1.1 |
|
| 89 |
1.1 |