| 1 | package com.github.dakusui.actionunit.visitors; | |
| 2 | ||
| 3 | import java.util.*; | |
| 4 | import java.util.regex.Matcher; | |
| 5 | import java.util.regex.Pattern; | |
| 6 | ||
| 7 | import static java.util.concurrent.TimeUnit.MILLISECONDS; | |
| 8 | ||
| 9 | public class Record implements Iterable<Record.Run> { | |
| 10 | ||
| 11 | private final List<Run> runs = Collections.synchronizedList(new LinkedList<>()); | |
| 12 | ||
| 13 | public long started() { | |
| 14 |
1
1. started : replaced long return with 0 for com/github/dakusui/actionunit/visitors/Record::started → SURVIVED |
return System.currentTimeMillis(); |
| 15 | } | |
| 16 | ||
| 17 | public void succeeded(long timeSpentInMillis) { | |
| 18 | runs.add(Run.succeeded(timeSpentInMillis)); | |
| 19 | } | |
| 20 | ||
| 21 | public void failed(long timeSpentInMillis, Throwable t) { | |
| 22 | runs.add(Run.failed(timeSpentInMillis, t)); | |
| 23 | } | |
| 24 | ||
| 25 | public long timeSpentInMillis() { | |
| 26 |
1
1. timeSpentInMillis : replaced long return with 0 for com/github/dakusui/actionunit/visitors/Record::timeSpentInMillis → SURVIVED |
return this.runs.stream() |
| 27 | .map(Run::timeSpentInMillis) | |
| 28 | .reduce(Long::sum) | |
| 29 | .orElse((long) 0); | |
| 30 | } | |
| 31 | ||
| 32 | public boolean allFailing() { | |
| 33 |
2
1. allFailing : replaced boolean return with false for com/github/dakusui/actionunit/visitors/Record::allFailing → SURVIVED 2. allFailing : replaced boolean return with true for com/github/dakusui/actionunit/visitors/Record::allFailing → SURVIVED |
return this.runs.stream().noneMatch(Run::succeeded); |
| 34 | } | |
| 35 | ||
| 36 | @Override | |
| 37 | public Iterator<Run> iterator() { | |
| 38 |
1
1. iterator : replaced return value with null for com/github/dakusui/actionunit/visitors/Record::iterator → KILLED |
return runs.iterator(); |
| 39 | } | |
| 40 | ||
| 41 | @Override | |
| 42 | public String toString() { | |
| 43 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/visitors/Record::toString → KILLED |
return formatRecord(this); |
| 44 | } | |
| 45 | ||
| 46 | private static String formatRecord(Record runs) { | |
| 47 | StringBuilder b = new StringBuilder(); | |
| 48 |
1
1. formatRecord : negated conditional → KILLED |
if (runs != null) |
| 49 |
1
1. formatRecord : removed call to com/github/dakusui/actionunit/visitors/Record::forEach → KILLED |
runs.forEach(run -> b.append(run.toString())); |
| 50 | assert runs != null; | |
| 51 |
1
1. formatRecord : replaced return value with "" for com/github/dakusui/actionunit/visitors/Record::formatRecord → KILLED |
return summarize(b.toString()) + ":" + MILLISECONDS.toSeconds(runs.timeSpentInMillis()); |
| 52 | } | |
| 53 | ||
| 54 | private static String summarize(String in) { | |
| 55 | StringBuilder b = new StringBuilder(); | |
| 56 | Matcher matcher = Pattern.compile("((.)\\2{0,})").matcher(in); | |
| 57 | int i = 0; | |
| 58 |
1
1. summarize : negated conditional → KILLED |
while (matcher.find(i)) { |
| 59 | String matched = matcher.group(1); | |
| 60 |
2
1. summarize : changed conditional boundary → KILLED 2. summarize : negated conditional → KILLED |
if (matched.length() > 3) { |
| 61 | b.append(matched.charAt(0)); | |
| 62 | b.append("..."); | |
| 63 | } else | |
| 64 | b.append(matched); | |
| 65 |
1
1. summarize : Replaced integer addition with subtraction → KILLED |
i += matched.length(); |
| 66 | } | |
| 67 |
1
1. summarize : replaced return value with "" for com/github/dakusui/actionunit/visitors/Record::summarize → KILLED |
return b.toString(); |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * {@code o} for Okay, {@code F} for fail, and {@code E} for error. | |
| 72 | * A fail means an assertion error, which is raised when a test fails. | |
| 73 | */ | |
| 74 | public interface Run { | |
| 75 | long timeSpentInMillis(); | |
| 76 | boolean succeeded(); | |
| 77 | ||
| 78 | static Run failed(long timeSpentInMillis, Throwable t) { | |
| 79 | Objects.requireNonNull(t); | |
| 80 |
1
1. failed : replaced return value with null for com/github/dakusui/actionunit/visitors/Record$Run::failed → KILLED |
return new Run() { |
| 81 | @Override | |
| 82 | public long timeSpentInMillis() { | |
| 83 |
1
1. timeSpentInMillis : replaced long return with 0 for com/github/dakusui/actionunit/visitors/Record$Run$1::timeSpentInMillis → SURVIVED |
return timeSpentInMillis; |
| 84 | } | |
| 85 | ||
| 86 | @Override | |
| 87 | public boolean succeeded() { | |
| 88 |
1
1. succeeded : replaced boolean return with true for com/github/dakusui/actionunit/visitors/Record$Run$1::succeeded → SURVIVED |
return false; |
| 89 | } | |
| 90 | ||
| 91 | @Override | |
| 92 | public String toString() { | |
| 93 |
2
1. toString : negated conditional → KILLED 2. toString : replaced return value with "" for com/github/dakusui/actionunit/visitors/Record$Run$1::toString → KILLED |
return t instanceof AssertionError |
| 94 | ? "F" | |
| 95 | : "E"; | |
| 96 | } | |
| 97 | }; | |
| 98 | } | |
| 99 | ||
| 100 | static Run succeeded(long timeSpentInMillis) { | |
| 101 |
1
1. succeeded : replaced return value with null for com/github/dakusui/actionunit/visitors/Record$Run::succeeded → KILLED |
return new Run() { |
| 102 | @Override | |
| 103 | public String toString() { | |
| 104 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/visitors/Record$Run$2::toString → KILLED |
return "o"; |
| 105 | } | |
| 106 | ||
| 107 | @Override | |
| 108 | public long timeSpentInMillis() { | |
| 109 |
1
1. timeSpentInMillis : replaced long return with 0 for com/github/dakusui/actionunit/visitors/Record$Run$2::timeSpentInMillis → SURVIVED |
return timeSpentInMillis; |
| 110 | } | |
| 111 | ||
| 112 | @Override | |
| 113 | public boolean succeeded() { | |
| 114 |
1
1. succeeded : replaced boolean return with false for com/github/dakusui/actionunit/visitors/Record$Run$2::succeeded → SURVIVED |
return true; |
| 115 | } | |
| 116 | }; | |
| 117 | } | |
| 118 | } | |
| 119 | } | |
Mutations | ||
| 14 |
1.1 |
|
| 26 |
1.1 |
|
| 33 |
1.1 2.2 |
|
| 38 |
1.1 |
|
| 43 |
1.1 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 51 |
1.1 |
|
| 58 |
1.1 |
|
| 60 |
1.1 2.2 |
|
| 65 |
1.1 |
|
| 67 |
1.1 |
|
| 80 |
1.1 |
|
| 83 |
1.1 |
|
| 88 |
1.1 |
|
| 93 |
1.1 2.2 |
|
| 101 |
1.1 |
|
| 104 |
1.1 |
|
| 109 |
1.1 |
|
| 114 |
1.1 |