Transformer.java

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

Mutations

43

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

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

51

1.1
Location : satisfies
Killed by : com.github.valid8j.entrypoints.ExpectationsTest.testPassingThat[187: ENSURE: BOOLEAN_STATEMENT](com.github.valid8j.entrypoints.ExpectationsTest)
replaced return value with null for com/github/valid8j/pcond/core/fluent/Transformer::satisfies → KILLED

59

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

96

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

97

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

106

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

109

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

115

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

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

120

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

125

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

Active mutators

Tests examined


Report generated by PIT 1.7.3