Explanation.java

1
package com.github.valid8j.pcond.validator;
2
3
import com.github.valid8j.pcond.internals.InternalUtils;
4
5
import java.util.LinkedList;
6
import java.util.List;
7
import java.util.Objects;
8
import java.util.stream.IntStream;
9
10
import static java.lang.String.format;
11
import static java.util.Objects.requireNonNull;
12
import static java.util.stream.Collectors.joining;
13
14
public class Explanation {
15
  private final String                message;
16
  private final ReportComposer.Report expected;
17
  private final ReportComposer.Report actual;
18
19
  public Explanation(String message) {
20
    this(message, ReportComposer.Utils.composeReport("", null), ReportComposer.Utils.composeReport("", null));
21
  }
22
23
  public Explanation(String message, ReportComposer.Report expected, ReportComposer.Report actual) {
24
    this.message = message;
25
    this.expected = requireNonNull(expected);
26
    this.actual = requireNonNull(actual);
27
  }
28
29
  public String message() {
30 1 1. message : replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::message → KILLED
    return this.message;
31
  }
32
33
  public ReportComposer.Report expected() {
34 1 1. expected : replaced return value with null for com/github/valid8j/pcond/validator/Explanation::expected → KILLED
    return this.expected;
35
  }
36
37
  public ReportComposer.Report actual() {
38 1 1. actual : replaced return value with null for com/github/valid8j/pcond/validator/Explanation::actual → KILLED
    return this.actual;
39
  }
40
41
  public String toString() {
42 2 1. toString : negated conditional → KILLED
2. toString : replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::toString → KILLED
    return actual != null ?
43
        format("%s%n%s", message, composeDiff(expected, actual)) :
44
        message;
45
  }
46
47
  private static String composeDiff(ReportComposer.Report expected, ReportComposer.Report actual) {
48
    String[] e = splitAndTrim(expected.summary());
49
    String[] a = splitAndTrim(actual.summary());
50
    List<String> b = new LinkedList<>();
51 3 1. composeDiff : changed conditional boundary → SURVIVED
2. composeDiff : negated conditional → TIMED_OUT
3. composeDiff : Changed increment from 1 to -1 → KILLED
    for (int i = 0; i < Math.max(a.length, e.length); i++) {
52 3 1. composeDiff : changed conditional boundary → SURVIVED
2. composeDiff : negated conditional → KILLED
3. composeDiff : negated conditional → KILLED
      if (i < Math.min(e.length, a.length) && Objects.equals(e[i], a[i])) {
53
        b.add(format("          %s", a[i]));
54
      } else {
55 2 1. composeDiff : changed conditional boundary → SURVIVED
2. composeDiff : negated conditional → KILLED
        b.add(format("Mismatch>:%s", i < a.length ? a[i] : ""));
56
      }
57
    }
58
    b.add(InternalUtils.newLine());
59
    assert expected.details().size() == actual.details().size();
60 1 1. composeDiff : negated conditional → KILLED
    return !expected.details().isEmpty() ?
61
        b.stream().collect(joining(InternalUtils.newLine()))
62
            + IntStream.range(0, expected.details().size())
63 1 1. lambda$composeDiff$0 : replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::lambda$composeDiff$0 → KILLED
            .mapToObj(i -> formatDetailItemPair(i, expected.details().get(i), actual.details().get(i)))
64
            .collect(joining(InternalUtils.newLine())) :
65
        "";
66
  }
67
68
  private static String formatDetailItemPair(int i, String detailItemForExpectation, String detailItemForActual) {
69 1 1. formatDetailItemPair : replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::formatDetailItemPair → KILLED
    return format(".Detail of failure [%s] (expectation)%n", i)
70
        + format("----%n")
71
        + detailItemForExpectation
72
        + InternalUtils.newLine()
73
        + format("----%n")
74
        + InternalUtils.newLine()
75
        + format(".Detail of failure [%s] (actual value)%n", i)
76
        + format("----%n")
77
        + detailItemForActual
78
        + InternalUtils.newLine()
79
        + "----";
80
  }
81
82
  public static String reportToString(ReportComposer.Report report) {
83
    String ret = report.summary();
84
    ret += InternalUtils.newLine();
85
    ret += InternalUtils.newLine();
86
    ret += IntStream.range(0, report.details().size())
87 1 1. lambda$reportToString$1 : replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::lambda$reportToString$1 → KILLED
        .mapToObj(i -> formatDetailItem(i, report.details().get(i)))
88
        .collect(joining(InternalUtils.newLine()));
89 1 1. reportToString : replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::reportToString → KILLED
    return ret;
90
  }
91
92
  private static String formatDetailItem(int i, String detailItem) {
93 1 1. formatDetailItem : replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::formatDetailItem → KILLED
    return format(".Detail of failure [%s]%n", i)
94
        + format("----%n")
95
        + detailItem
96
        + InternalUtils.newLine()
97
        + format("----%n");
98
  }
99
100
  public static Explanation fromMessage(String msg) {
101 1 1. fromMessage : replaced return value with null for com/github/valid8j/pcond/validator/Explanation::fromMessage → KILLED
    return new Explanation(msg);
102
  }
103
104
  private static String[] splitAndTrim(String expected) {
105
    String[] in = expected.split(InternalUtils.newLine());
106
    List<String> out = new LinkedList<>();
107
    boolean nonEmptyFound = false;
108 4 1. splitAndTrim : changed conditional boundary → KILLED
2. splitAndTrim : Changed increment from -1 to 1 → KILLED
3. splitAndTrim : Replaced integer subtraction with addition → KILLED
4. splitAndTrim : negated conditional → KILLED
    for (int i = in.length - 1; i >= 0; i--) {
109 1 1. splitAndTrim : negated conditional → KILLED
      if (!"".equals(in[i]))
110
        nonEmptyFound = true;
111 1 1. splitAndTrim : negated conditional → KILLED
      if (nonEmptyFound)
112 1 1. splitAndTrim : removed call to java/util/List::add → KILLED
        out.add(0, in[i]);
113
    }
114 1 1. splitAndTrim : replaced return value with null for com/github/valid8j/pcond/validator/Explanation::splitAndTrim → KILLED
    return out.toArray(new String[0]);
115
  }
116
}

Mutations

30

1.1
Location : message
Killed by : com.github.valid8j.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest.string_assertThatTest_failed(com.github.valid8j.ut.styles.FluentStyleTestAssertionTest$ForTestAssertionsTest)
replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::message → KILLED

34

1.1
Location : expected
Killed by : com.github.valid8j.ut.valuechecker.Opentest4jTest.test_testFailedException(com.github.valid8j.ut.valuechecker.Opentest4jTest)
replaced return value with null for com/github/valid8j/pcond/validator/Explanation::expected → KILLED

38

1.1
Location : actual
Killed by : com.github.valid8j.ut.valuechecker.Opentest4jTest.test_testFailedException(com.github.valid8j.ut.valuechecker.Opentest4jTest)
replaced return value with null for com/github/valid8j/pcond/validator/Explanation::actual → KILLED

42

1.1
Location : toString
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
negated conditional → KILLED

2.2
Location : toString
Killed by : com.github.valid8j.ut.internal.InternalUtilsTest$FormatObjectTest.testCreateInstanceFromClassName$thenNotFound(com.github.valid8j.ut.internal.InternalUtilsTest$FormatObjectTest)
replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::toString → KILLED

51

1.1
Location : composeDiff
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : composeDiff
Killed by : com.github.valid8j.entrypoints.EnsuresTest.testEnsureState(com.github.valid8j.entrypoints.EnsuresTest)
Changed increment from 1 to -1 → KILLED

3.3
Location : composeDiff
Killed by : none
negated conditional → TIMED_OUT

52

1.1
Location : composeDiff
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : composeDiff
Killed by : com.github.valid8j.ut.valuechecker.DefaultValidatorTest.withEvaluator_columns100$whenShorterThan10(com.github.valid8j.ut.valuechecker.DefaultValidatorTest)
negated conditional → KILLED

3.3
Location : composeDiff
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
negated conditional → KILLED

55

1.1
Location : composeDiff
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : composeDiff
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
negated conditional → KILLED

60

1.1
Location : composeDiff
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
negated conditional → KILLED

63

1.1
Location : lambda$composeDiff$0
Killed by : com.github.valid8j.ut.internal.CallTest.methodNotFound(com.github.valid8j.ut.internal.CallTest)
replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::lambda$composeDiff$0 → KILLED

69

1.1
Location : formatDetailItemPair
Killed by : com.github.valid8j.ut.internal.CallTest.methodNotFound(com.github.valid8j.ut.internal.CallTest)
replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::formatDetailItemPair → KILLED

87

1.1
Location : lambda$reportToString$1
Killed by : com.github.valid8j.ut.utilstest.ReportDetailTest.givenLongString_whenCheckEqualnessUsingCustomPredicateWithSlightlyDifferentString_thenFailWithDetailsArePrinted(com.github.valid8j.ut.utilstest.ReportDetailTest)
replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::lambda$reportToString$1 → KILLED

89

1.1
Location : reportToString
Killed by : com.github.valid8j.ut.utilstest.ReportDetailTest.givenLongString_whenCheckEqualnessUsingCustomPredicateWithSlightlyDifferentString_thenFailWithDetailsArePrinted(com.github.valid8j.ut.utilstest.ReportDetailTest)
replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::reportToString → KILLED

93

1.1
Location : formatDetailItem
Killed by : com.github.valid8j.ut.utilstest.ReportDetailTest.givenLongString_whenCheckEqualnessUsingCustomPredicateWithSlightlyDifferentString_thenFailWithDetailsArePrinted(com.github.valid8j.ut.utilstest.ReportDetailTest)
replaced return value with "" for com/github/valid8j/pcond/validator/Explanation::formatDetailItem → KILLED

101

1.1
Location : fromMessage
Killed by : com.github.valid8j.ut.valuechecker.Opentest4jTest.test_testSkippedException$String(com.github.valid8j.ut.valuechecker.Opentest4jTest)
replaced return value with null for com/github/valid8j/pcond/validator/Explanation::fromMessage → KILLED

108

1.1
Location : splitAndTrim
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
changed conditional boundary → KILLED

2.2
Location : splitAndTrim
Killed by : com.github.valid8j.ut.internal.exceptionhandling.ExceptionsTest.testWrapIfNecessaryWithCheckedException(com.github.valid8j.ut.internal.exceptionhandling.ExceptionsTest)
Changed increment from -1 to 1 → KILLED

3.3
Location : splitAndTrim
Killed by : com.github.valid8j.ut.internal.exceptionhandling.ExceptionsTest.testWrapIfNecessaryWithCheckedException(com.github.valid8j.ut.internal.exceptionhandling.ExceptionsTest)
Replaced integer subtraction with addition → KILLED

4.4
Location : splitAndTrim
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
negated conditional → KILLED

109

1.1
Location : splitAndTrim
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
negated conditional → KILLED

111

1.1
Location : splitAndTrim
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
negated conditional → KILLED

112

1.1
Location : splitAndTrim
Killed by : com.github.valid8j.ut.internal.NegateTest.whenInvertedTrasformingPredicateFails_thenPrintDesignedMessage$notMergedWhenMismatch(com.github.valid8j.ut.internal.NegateTest)
removed call to java/util/List::add → KILLED

114

1.1
Location : splitAndTrim
Killed by : com.github.valid8j.ut.internal.exceptionhandling.ExceptionsTest.testWrapIfNecessaryWithCheckedException(com.github.valid8j.ut.internal.exceptionhandling.ExceptionsTest)
replaced return value with null for com/github/valid8j/pcond/validator/Explanation::splitAndTrim → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3