Transformer.java

1
package com.github.dakusui.pcond.core.fluent;
2
3
import com.github.dakusui.pcond.fluent.Statement;
4
import com.github.dakusui.pcond.forms.Functions;
5
6
import java.util.Objects;
7
import java.util.function.BiFunction;
8
import java.util.function.Function;
9
import java.util.function.Predicate;
10
import java.util.function.Supplier;
11
12
import static com.github.dakusui.pcond.internals.InternalChecks.requireState;
13
import static java.lang.String.format;
14
import static java.util.Objects.requireNonNull;
15
16
public interface Transformer<
17
    TX extends Transformer<TX, V, T, R>,  // SELF
18
    V extends Checker<V, T, R>,
19
    T,
20
    R> extends
21
    Matcher<TX, T, R>,
22
    Statement<T> {
23
24
  @SuppressWarnings("unchecked")
25
  default TX checkWithPredicate(Predicate<? super R> predicate) {
26
    requireNonNull(predicate);
27 2 1. checkWithPredicate : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::checkWithPredicate → NO_COVERAGE
2. lambda$checkWithPredicate$0 : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::lambda$checkWithPredicate$0 → NO_COVERAGE
    return addTransformAndCheckClause(tx -> (Predicate<R>) predicate);
28
  }
29
30
  TX addTransformAndCheckClause(Function<Transformer<?, ?, R, R>, Predicate<R>> clause);
31
32
  /**
33
   * Returns a checker object for this object.
34
   * @return A checker object for this object.
35
   */
36
  V then();
37
38
  /**
39
   * A synonym of {@link Transformer#then()} method.
40
   * @return A checker object for this object.
41
   */
42
  default V satisfies() {
43 1 1. satisfies : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::satisfies → KILLED
    return then();
44
  }
45
46
  /**
47
   * A synonym of {@link Transformer#then()} method.
48
   * @return A checker object for this object.
49
   */
50
  default V toBe() {
51 1 1. toBe : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::toBe → KILLED
    return then();
52
  }
53
54
  default Predicate<T> done() {
55 1 1. done : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::done → KILLED
    return this.statementPredicate();
56
  }
57
58
  <TY extends Transformer<TY, W, T, RR>,
59
      W extends Checker<W, T, RR>,
60
      RR>
61
  TY transformValueWith(Function<? super R, RR> func, BiFunction<Supplier<T>, Function<T, RR>, TY> transformerFactory);
62
63
  abstract class Base<
64
      TX extends Transformer<TX, V, T, R>,  // SELF
65
      V extends Checker<V, T, R>,
66
      T,
67
      R> extends
68
      Matcher.Base<
69
          TX,
70
          T,
71
          R> implements
72
      Transformer<
73
          TX,
74
          V,
75
          T,
76
          R> {
77
78
    protected Base(Supplier<T> baseValue, Function<T, R> transformFunction) {
79
      super(baseValue, transformFunction);
80
    }
81
82
    public V then() {
83 1 1. lambda$then$0 : replaced return value with "" for com/github/dakusui/pcond/core/fluent/Transformer$Base::lambda$then$0 → NO_COVERAGE
      requireState(this, Matcher.Base::hasNoChild, v -> format("Predicate is already added. %s", v.childPredicates()));
84 1 1. then : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::then → KILLED
      return toChecker(this.transformFunction());
85
    }
86
87
    public <
88
        TY extends Transformer<TY, W, T, RR>,
89
        W extends Checker<W, T, RR>,
90
        RR>
91
    TY transformValueWith(Function<? super R, RR> func, BiFunction<Supplier<T>, Function<T, RR>, TY> transformerFactory) {
92
      Function<T, R> tf = transformFunction();
93 1 1. transformValueWith : negated conditional → KILLED
      @SuppressWarnings("unchecked") Function<T, RR> transformFunction = Objects.equals(tf, Functions.identity()) ?
94
          (Function<T, RR>) func :
95
          tf.andThen(func);
96 1 1. transformValueWith : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::transformValueWith → KILLED
      return transformerFactory.apply(this::baseValue, transformFunction);
97
    }
98
99
    @SuppressWarnings("unchecked")
100
    @Override
101
    public TX checkWithPredicate(Predicate<? super R> predicate) {
102 2 1. checkWithPredicate : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::checkWithPredicate → NO_COVERAGE
2. lambda$checkWithPredicate$1 : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::lambda$checkWithPredicate$1 → NO_COVERAGE
      return this.addTransformAndCheckClause(tx -> (Predicate<R>) predicate);
103
    }
104
105
    @SuppressWarnings("unchecked")
106
    @Override
107
    public TX addTransformAndCheckClause(Function<Transformer<?, ?, R, R>, Predicate<R>> clause) {
108 2 1. addTransformAndCheckClause : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::addTransformAndCheckClause → KILLED
2. lambda$addTransformAndCheckClause$2 : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::lambda$addTransformAndCheckClause$2 → KILLED
      return this.addPredicate(tx -> clause.apply((Transformer<?, ?, R, R>) tx));
109
    }
110
111
    @Override
112
    public T statementValue() {
113 1 1. statementValue : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::statementValue → KILLED
      return baseValue();
114
    }
115
116
    @Override
117
    public Predicate<T> statementPredicate() {
118 1 1. statementPredicate : replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::statementPredicate → KILLED
      return toPredicate();
119
    }
120
121
    protected abstract V toChecker(Function<T, R> transformFunction);
122
  }
123
}

Mutations

27

1.1
Location : checkWithPredicate
Killed by : none
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::checkWithPredicate → NO_COVERAGE

2.2
Location : lambda$checkWithPredicate$0
Killed by : none
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::lambda$checkWithPredicate$0 → NO_COVERAGE

43

1.1
Location : satisfies
Killed by : com.github.dakusui.pcond.types.FloatTest.floatSatisfiesTest(com.github.dakusui.pcond.types.FloatTest)
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::satisfies → KILLED

51

1.1
Location : toBe
Killed by : com.github.dakusui.ut.thincrest.ut.styles.MoreFluentStringTest.test_endingWith(com.github.dakusui.ut.thincrest.ut.styles.MoreFluentStringTest)
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer::toBe → KILLED

55

1.1
Location : done
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/fluent/Transformer::done → KILLED

83

1.1
Location : lambda$then$0
Killed by : none
replaced return value with "" for com/github/dakusui/pcond/core/fluent/Transformer$Base::lambda$then$0 → NO_COVERAGE

84

1.1
Location : then
Killed by : com.github.dakusui.ut.thincrest.ut.styles.MoreFluentStringTest.test_isEmpty(com.github.dakusui.ut.thincrest.ut.styles.MoreFluentStringTest)
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::then → KILLED

93

1.1
Location : transformValueWith
Killed by : com.github.dakusui.ut.valid8j.ut.styles.FluentStyleDbCTest$ForRequiresTest.requireValue_passing(com.github.dakusui.ut.valid8j.ut.styles.FluentStyleDbCTest$ForRequiresTest)
negated conditional → KILLED

96

1.1
Location : transformValueWith
Killed by : com.github.dakusui.ut.thincrest.ut.styles.MoreFluentListTest.test_size(com.github.dakusui.ut.thincrest.ut.styles.MoreFluentListTest)
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::transformValueWith → KILLED

102

1.1
Location : checkWithPredicate
Killed by : none
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::checkWithPredicate → NO_COVERAGE

2.2
Location : lambda$checkWithPredicate$1
Killed by : none
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::lambda$checkWithPredicate$1 → NO_COVERAGE

108

1.1
Location : addTransformAndCheckClause
Killed by : com.github.dakusui.ut.valid8j.ut.styles.fluent.FluentBooleanTest.givenFalse_whenTransformIsTrue_thenComparisonFailure(com.github.dakusui.ut.valid8j.ut.styles.fluent.FluentBooleanTest)
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::addTransformAndCheckClause → KILLED

2.2
Location : lambda$addTransformAndCheckClause$2
Killed by : com.github.dakusui.ut.valid8j.ut.styles.fluent.FluentBooleanTest.givenFalse_whenTransformIsTrue_thenComparisonFailure(com.github.dakusui.ut.valid8j.ut.styles.fluent.FluentBooleanTest)
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::lambda$addTransformAndCheckClause$2 → KILLED

113

1.1
Location : statementValue
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/fluent/Transformer$Base::statementValue → KILLED

118

1.1
Location : statementPredicate
Killed by : com.github.dakusui.ut.valid8j.ut.styles.fluent.FluentBooleanTest.givenFalse_whenTransformIsTrue_thenComparisonFailure(com.github.dakusui.ut.valid8j.ut.styles.fluent.FluentBooleanTest)
replaced return value with null for com/github/dakusui/pcond/core/fluent/Transformer$Base::statementPredicate → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3