ValueHolder.java

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

Mutations

22

1.1
Location : clone
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::clone → KILLED

29

1.1
Location : state
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::state → KILLED

33

1.1
Location : returnedValue
Killed by : com.github.valid8j.entrypoints.EnsuresTest.givenValidArgument_whenEnsure_thenValueReturned(com.github.valid8j.entrypoints.EnsuresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::returnedValue → KILLED

37

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

41

1.1
Location : value
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
negated conditional → KILLED

42

1.1
Location : value
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::value → KILLED

43

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

44

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

45

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

46

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

51

1.1
Location : forValue
Killed by : com.github.valid8j.entrypoints.EnsuresTest.givenValidArgument_whenEnsure_thenValueReturned(com.github.valid8j.entrypoints.EnsuresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::forValue → KILLED

56

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

57

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

58

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

59

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

60

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

64

1.1
Location : isValueReturned
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
negated conditional → KILLED

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

68

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

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

72

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

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

76

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

81

1.1
Location : valueReturned
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::valueReturned → KILLED

86

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

91

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

95

1.1
Location : creatorFormType
Killed by : com.github.valid8j.entrypoints.RequiresTest.testRequireWithCustomStringTransformingPredicateAndSatisfyingValue(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::creatorFormType → KILLED

99

1.1
Location : create
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::create → KILLED

103

1.1
Location : create
Killed by : com.github.valid8j.entrypoints.RequiresTest.givenValidState$whenRequireState$thenPass(com.github.valid8j.entrypoints.RequiresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder::create → KILLED

111

1.1
Location : value
Killed by : com.github.valid8j.entrypoints.EnsuresTest.givenValidArgument_whenEnsure_thenValueReturned(com.github.valid8j.entrypoints.EnsuresTest)
replaced return value with null for com/github/valid8j/pcond/core/ValueHolder$State$2::value → KILLED

116

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

Active mutators

Tests examined


Report generated by PIT 1.7.3