ValueHolder.java

1
package com.github.dakusui.pcond.core;
2
3
import static com.github.dakusui.pcond.core.Evaluator.Impl.EVALUATION_SKIPPED;
4
import static java.util.Objects.requireNonNull;
5
6
public class ValueHolder<V> implements Cloneable {
7
8
  private final State state;
9
  private final CreatorFormType creatorFormType;
10
  V         value;
11
  Throwable exception;
12
13
  private ValueHolder(State state, V value, Throwable exception, CreatorFormType creatorFormType) {
14
    this.state = state;
15
    this.value = value;
16
    this.exception = exception;
17
    this.creatorFormType = creatorFormType;
18
  }
19
20
  @SuppressWarnings("unchecked")
21
  public ValueHolder<V> clone() {
22
    try {
23 1 1. clone : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::clone → KILLED
      return (ValueHolder<V>) super.clone();
24
    } catch (CloneNotSupportedException e) {
25
      throw new RuntimeException(e);
26
    }
27
  }
28
29
  public State state() {
30 1 1. state : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::state → KILLED
    return this.state;
31
  }
32
33
  public V returnedValue() {
34 1 1. returnedValue : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::returnedValue → KILLED
    return this.state.value(this);
35
  }
36
37
  public Throwable thrownException() {
38 1 1. thrownException : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::thrownException → KILLED
    return this.state.exception(this);
39
  }
40
41
  public Object value() {
42 1 1. value : negated conditional → KILLED
    if (isValueReturned())
43 1 1. value : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::value → KILLED
      return this.returnedValue();
44 1 1. value : negated conditional → KILLED
    if (isEvaluationSkipped())
45 1 1. value : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::value → SURVIVED
      return EVALUATION_SKIPPED;
46 1 1. value : negated conditional → KILLED
    if (isExceptionThrown())
47 1 1. value : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::value → KILLED
      return this.thrownException();
48
    throw new IllegalStateException();
49
  }
50
51
  public static <V> ValueHolder<V> forValue(V value) {
52 1 1. forValue : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::forValue → KILLED
    return new ValueHolder<>(State.VALUE_RETURNED, value, null, CreatorFormType.UNKNOWN);
53
  }
54
55
  @Override
56
  public String toString() {
57 1 1. toString : negated conditional → NO_COVERAGE
    if (isValueReturned())
58 1 1. toString : replaced return value with "" for com/github/dakusui/pcond/core/ValueHolder::toString → NO_COVERAGE
      return String.format("state:%s, value:%s, creator:%s", state, value, creatorFormType);
59 1 1. toString : negated conditional → NO_COVERAGE
    if (isEvaluationSkipped())
60 1 1. toString : replaced return value with "" for com/github/dakusui/pcond/core/ValueHolder::toString → NO_COVERAGE
      return String.format("state:%s, exception:%s, creator:%s", state, exception, creatorFormType);
61 1 1. toString : replaced return value with "" for com/github/dakusui/pcond/core/ValueHolder::toString → NO_COVERAGE
    return String.format("state:%s, creator:%s", state, creatorFormType);
62
  }
63
64
  public boolean isValueReturned() {
65 2 1. isValueReturned : negated conditional → KILLED
2. isValueReturned : replaced boolean return with true for com/github/dakusui/pcond/core/ValueHolder::isValueReturned → KILLED
    return this.state() == State.VALUE_RETURNED;
66
  }
67
68
  public boolean isExceptionThrown() {
69 2 1. isExceptionThrown : replaced boolean return with true for com/github/dakusui/pcond/core/ValueHolder::isExceptionThrown → SURVIVED
2. isExceptionThrown : negated conditional → KILLED
    return this.state() == State.EXCEPTION_THROWN;
70
  }
71
72
  public boolean isEvaluationSkipped() {
73 2 1. isEvaluationSkipped : negated conditional → KILLED
2. isEvaluationSkipped : replaced boolean return with true for com/github/dakusui/pcond/core/ValueHolder::isEvaluationSkipped → KILLED
    return this.state() == State.EVALUATION_SKIPPED;
74
  }
75
76
  public CreatorFormType creatorFormType() {
77 1 1. creatorFormType : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::creatorFormType → KILLED
    return this.creatorFormType;
78
  }
79
80
  public ValueHolder<V> valueReturned(V value) {
81
    //    requireState(this.state, v -> v.equals(State.NOT_YET_EVALUATED), v -> messageNotYetEvaluatedStateIsRequired(v, this));
82 1 1. valueReturned : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::valueReturned → KILLED
    return new ValueHolder<>(State.VALUE_RETURNED, value, null, this.creatorFormType);
83
  }
84
85
  public ValueHolder<V> exceptionThrown(Throwable throwable) {
86
    //    requireState(this.state, v -> v.equals(State.NOT_YET_EVALUATED), v -> messageNotYetEvaluatedStateIsRequired(v, this));
87 1 1. exceptionThrown : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::exceptionThrown → KILLED
    return new ValueHolder<>(State.EXCEPTION_THROWN, null, requireNonNull(throwable), this.creatorFormType);
88
  }
89
90
  public ValueHolder<V> evaluationSkipped() {
91
    //    requireState(this.state, v -> v.equals(State.NOT_YET_EVALUATED), v -> messageNotYetEvaluatedStateIsRequired(v, this));
92 1 1. evaluationSkipped : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::evaluationSkipped → KILLED
    return new ValueHolder<>(State.EVALUATION_SKIPPED, null, null, this.creatorFormType);
93
  }
94
95
  public ValueHolder<V> creatorFormType(CreatorFormType creatorFormType) {
96 1 1. creatorFormType : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::creatorFormType → KILLED
    return new ValueHolder<>(this.state, this.value, this.exception, creatorFormType);
97
  }
98
99
  static <E> ValueHolder<E> create() {
100 1 1. create : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::create → KILLED
    return create(CreatorFormType.UNKNOWN);
101
  }
102
103
  public static <E> ValueHolder<E> create(CreatorFormType creatorFormType) {
104 1 1. create : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::create → KILLED
    return new ValueHolder<>(State.NOT_YET_EVALUATED, null, null, creatorFormType);
105
  }
106
107
  public enum State {
108
    NOT_YET_EVALUATED {
109
    },
110
    VALUE_RETURNED {
111
      <V> V value(ValueHolder<V> valueHolder) {
112 1 1. value : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder$State$2::value → KILLED
        return valueHolder.value;
113
      }
114
    },
115
    EXCEPTION_THROWN {
116
      <V> Throwable exception(ValueHolder<V> vContextVariable) {
117 1 1. exception : replaced return value with null for com/github/dakusui/pcond/core/ValueHolder$State$3::exception → KILLED
        return vContextVariable.exception;
118
      }
119
    },
120
    EVALUATION_SKIPPED {
121
    };
122
123
    <V> V value(ValueHolder<V> valueHolder) {
124
      throw new IllegalStateException("current state=" + valueHolder.state);
125
    }
126
127
    <V> Throwable exception(ValueHolder<V> vContextVariable) {
128
      throw new IllegalStateException();
129
    }
130
  }
131
132
  enum CreatorFormType {
133
    FUNC_HEAD,
134
    FUNC_TAIL,
135
    TRANSFORM,
136
    UNKNOWN
137
  }
138
}

Mutations

23

1.1
Location : clone
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::clone → KILLED

30

1.1
Location : state
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::state → KILLED

34

1.1
Location : returnedValue
Killed by : com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest.withEvaluator_nativePredicate(com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::returnedValue → KILLED

38

1.1
Location : thrownException
Killed by : com.github.dakusui.pcond.CallTest.methodNotFound(com.github.dakusui.pcond.CallTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::thrownException → KILLED

42

1.1
Location : value
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
negated conditional → KILLED

43

1.1
Location : value
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::value → KILLED

44

1.1
Location : value
Killed by : com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest.expectingDifferentException_testFailing(com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest)
negated conditional → KILLED

45

1.1
Location : value
Killed by : none
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::value → SURVIVED

46

1.1
Location : value
Killed by : com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest.expectingDifferentException_testFailing(com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest)
negated conditional → KILLED

47

1.1
Location : value
Killed by : com.github.dakusui.pcond.ut.fluent4.SmokeTest.givenBook_whenCheckTitleAndAbstract_thenTheyAreNotNullAndAppropriateLength_2(com.github.dakusui.pcond.ut.fluent4.SmokeTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::value → KILLED

52

1.1
Location : forValue
Killed by : com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest.withEvaluator_nativePredicate(com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::forValue → KILLED

57

1.1
Location : toString
Killed by : none
negated conditional → NO_COVERAGE

58

1.1
Location : toString
Killed by : none
replaced return value with "" for com/github/dakusui/pcond/core/ValueHolder::toString → NO_COVERAGE

59

1.1
Location : toString
Killed by : none
negated conditional → NO_COVERAGE

60

1.1
Location : toString
Killed by : none
replaced return value with "" for com/github/dakusui/pcond/core/ValueHolder::toString → NO_COVERAGE

61

1.1
Location : toString
Killed by : none
replaced return value with "" for com/github/dakusui/pcond/core/ValueHolder::toString → NO_COVERAGE

65

1.1
Location : isValueReturned
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
negated conditional → KILLED

2.2
Location : isValueReturned
Killed by : com.github.dakusui.pcond.CallTest.methodNotFound(com.github.dakusui.pcond.CallTest)
replaced boolean return with true for com/github/dakusui/pcond/core/ValueHolder::isValueReturned → KILLED

69

1.1
Location : isExceptionThrown
Killed by : com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest.expectingDifferentException_testFailing(com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest)
negated conditional → KILLED

2.2
Location : isExceptionThrown
Killed by : none
replaced boolean return with true for com/github/dakusui/pcond/core/ValueHolder::isExceptionThrown → SURVIVED

73

1.1
Location : isEvaluationSkipped
Killed by : com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest.whenIsInstanceOfUsedInComposite_thenNoExplicitTypeParameterIsNeeded(com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest)
negated conditional → KILLED

2.2
Location : isEvaluationSkipped
Killed by : com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest.whenIsInstanceOfUsedInComposite_thenNoExplicitTypeParameterIsNeeded(com.github.dakusui.ut.thincrest.ut.PredicatesTest$IsInstanceOfTest)
replaced boolean return with true for com/github/dakusui/pcond/core/ValueHolder::isEvaluationSkipped → KILLED

77

1.1
Location : creatorFormType
Killed by : com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest.givenString$hello$_whenTransformToContextAndCheckContextValueIsNull_thenPreconditionViolationWithCorrectMessageThrown(com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::creatorFormType → KILLED

82

1.1
Location : valueReturned
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::valueReturned → KILLED

87

1.1
Location : exceptionThrown
Killed by : com.github.dakusui.pcond.CallTest.methodNotFound(com.github.dakusui.pcond.CallTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::exceptionThrown → KILLED

92

1.1
Location : evaluationSkipped
Killed by : com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest.expectingDifferentException_testFailing(com.github.dakusui.ut.thincrest.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::evaluationSkipped → KILLED

96

1.1
Location : creatorFormType
Killed by : com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest.hello_b3(com.github.dakusui.pcond.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::creatorFormType → KILLED

100

1.1
Location : create
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::create → KILLED

104

1.1
Location : create
Killed by : com.github.dakusui.ut.valid8j.ut.ValidatesTest.test_validateState_pass(com.github.dakusui.ut.valid8j.ut.ValidatesTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder::create → KILLED

112

1.1
Location : value
Killed by : com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest.withEvaluator_nativePredicate(com.github.dakusui.pcond.ut.valuechecker.DefaultValidatorTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder$State$2::value → KILLED

117

1.1
Location : exception
Killed by : com.github.dakusui.pcond.CallTest.methodNotFound(com.github.dakusui.pcond.CallTest)
replaced return value with null for com/github/dakusui/pcond/core/ValueHolder$State$3::exception → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3