1 | package com.github.dakusui.actionunit.visitors; | |
2 | ||
3 | import com.github.dakusui.actionunit.core.Action; | |
4 | import com.github.dakusui.actionunit.core.Context; | |
5 | import com.github.dakusui.actionunit.io.Writer; | |
6 | import org.slf4j.Logger; | |
7 | import org.slf4j.LoggerFactory; | |
8 | ||
9 | import java.util.LinkedHashMap; | |
10 | import java.util.Map; | |
11 | import java.util.function.Predicate; | |
12 | ||
13 | import static java.util.Objects.requireNonNull; | |
14 | ||
15 | public class ReportingActionPerformer extends ActionPerformer { | |
16 | private static final Logger LOGGER = LoggerFactory.getLogger(ReportingActionPerformer.class); | |
17 | private final Map<Action, Record> report; | |
18 | ||
19 | public ReportingActionPerformer() { | |
20 | this(Context.create(), new LinkedHashMap<>()); | |
21 | } | |
22 | ||
23 | public ReportingActionPerformer(Context context, Map<Action, Record> report) { | |
24 | super(context); | |
25 | this.report = report; | |
26 | } | |
27 | ||
28 | @Override | |
29 | protected Action.Visitor newInstance(Context context) { | |
30 |
1
1. newInstance : replaced return value with null for com/github/dakusui/actionunit/visitors/ReportingActionPerformer::newInstance → KILLED |
return new ReportingActionPerformer(context, this.report); |
31 | } | |
32 | ||
33 | @Override | |
34 | protected void callAccept(Action action, Action.Visitor visitor) { | |
35 | Record record; | |
36 | synchronized (report) { | |
37 |
1
1. lambda$callAccept$0 : replaced return value with null for com/github/dakusui/actionunit/visitors/ReportingActionPerformer::lambda$callAccept$0 → KILLED |
record = report.computeIfAbsent(action, a -> createRecord()); |
38 | } | |
39 |
1
1. callAccept : negated conditional → KILLED |
if (record == null) { |
40 | LOGGER.error("record became null for action:{}({})", action, action.getClass()); | |
41 | assert false; | |
42 | } | |
43 | long timeStartedInMillis = record.started(); | |
44 | try { | |
45 |
1
1. callAccept : removed call to com/github/dakusui/actionunit/core/Action::accept → KILLED |
action.accept(visitor); |
46 |
2
1. callAccept : Replaced long subtraction with addition → SURVIVED 2. callAccept : removed call to com/github/dakusui/actionunit/visitors/Record::succeeded → KILLED |
record.succeeded(System.currentTimeMillis() - timeStartedInMillis); |
47 | } catch (Throwable t) { | |
48 |
2
1. callAccept : Replaced long subtraction with addition → SURVIVED 2. callAccept : removed call to com/github/dakusui/actionunit/visitors/Record::failed → KILLED |
record.failed(System.currentTimeMillis() - timeStartedInMillis, t); |
49 | throw t; | |
50 | } | |
51 | } | |
52 | ||
53 | public void perform(Action action) { | |
54 |
1
1. perform : removed call to com/github/dakusui/actionunit/visitors/ReportingActionPerformer::callAccept → KILLED |
callAccept(requireNonNull(action), this); |
55 | } | |
56 | ||
57 | public void performAndReport(Action action, Writer writer) { | |
58 | try { | |
59 |
1
1. performAndReport : removed call to com/github/dakusui/actionunit/visitors/ReportingActionPerformer::perform → KILLED |
perform(action); |
60 | } finally { | |
61 |
1
1. performAndReport : removed call to com/github/dakusui/actionunit/visitors/ActionReporter::report → KILLED |
new ActionReporter(writer, this.getReport()).report(action); |
62 | } | |
63 | } | |
64 | ||
65 | public void performAndReport(Predicate<Action> conditionToSquashAction, Action action, Writer warnWriter, Writer infoWriter, Writer debugWriter, Writer traceWriter, int forcePrintLevelForUnexercisedActions) { | |
66 | try { | |
67 |
1
1. performAndReport : removed call to com/github/dakusui/actionunit/visitors/ReportingActionPerformer::perform → NO_COVERAGE |
perform(action); |
68 | } finally { | |
69 |
1
1. performAndReport : removed call to com/github/dakusui/actionunit/visitors/ActionReporter::report → NO_COVERAGE |
new ActionReporter(conditionToSquashAction, warnWriter, infoWriter, debugWriter, traceWriter, this.getReport(), forcePrintLevelForUnexercisedActions).report(action); |
70 | } | |
71 | } | |
72 | ||
73 | public void performAndReport(Action action, Writer warnWriter, Writer infoWriter, Writer debugWriter, Writer traceWriter, int forcePrintLevelForUnexercisedActions) { | |
74 |
1
1. performAndReport : removed call to com/github/dakusui/actionunit/visitors/ReportingActionPerformer::performAndReport → NO_COVERAGE |
performAndReport(ActionReporter.DEFAULT_CONDITION_TO_SQUASH_ACTION, action, warnWriter, infoWriter, debugWriter, traceWriter, forcePrintLevelForUnexercisedActions); |
75 | } | |
76 | ||
77 | public Map<Action, Record> getReport() { | |
78 |
1
1. getReport : replaced return value with Collections.emptyMap for com/github/dakusui/actionunit/visitors/ReportingActionPerformer::getReport → KILLED |
return this.report; |
79 | } | |
80 | ||
81 | protected Record createRecord() { | |
82 |
1
1. createRecord : replaced return value with null for com/github/dakusui/actionunit/visitors/ReportingActionPerformer::createRecord → KILLED |
return new Record(); |
83 | } | |
84 | ||
85 | public static ReportingActionPerformer create() { | |
86 |
1
1. create : replaced return value with null for com/github/dakusui/actionunit/visitors/ReportingActionPerformer::create → KILLED |
return new ReportingActionPerformer(); |
87 | } | |
88 | } | |
Mutations | ||
30 |
1.1 |
|
37 |
1.1 |
|
39 |
1.1 |
|
45 |
1.1 |
|
46 |
1.1 2.2 |
|
48 |
1.1 2.2 |
|
54 |
1.1 |
|
59 |
1.1 |
|
61 |
1.1 |
|
67 |
1.1 |
|
69 |
1.1 |
|
74 |
1.1 |
|
78 |
1.1 |
|
82 |
1.1 |
|
86 |
1.1 |