| 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 |
|
| 34 |
1.1 |
|
| 38 |
1.1 |
|
| 42 |
1.1 2.2 |
|
| 51 |
1.1 2.2 3.3 |
|
| 52 |
1.1 2.2 3.3 |
|
| 55 |
1.1 2.2 |
|
| 60 |
1.1 |
|
| 63 |
1.1 |
|
| 69 |
1.1 |
|
| 87 |
1.1 |
|
| 89 |
1.1 |
|
| 93 |
1.1 |
|
| 101 |
1.1 |
|
| 108 |
1.1 2.2 3.3 4.4 |
|
| 109 |
1.1 |
|
| 111 |
1.1 |
|
| 112 |
1.1 |
|
| 114 |
1.1 |