1 | package com.github.dakusui.actionunit.actions; | |
2 | ||
3 | import com.github.dakusui.actionunit.core.Action; | |
4 | import com.github.dakusui.actionunit.core.ActionSupport; | |
5 | import com.github.dakusui.actionunit.core.Context; | |
6 | import com.github.dakusui.actionunit.exceptions.ActionException; | |
7 | ||
8 | import java.util.Formatter; | |
9 | import java.util.function.Consumer; | |
10 | ||
11 | import static com.github.dakusui.actionunit.core.ActionSupport.leaf; | |
12 | import static com.github.dakusui.actionunit.core.ActionSupport.named; | |
13 | import static java.util.Objects.requireNonNull; | |
14 | ||
15 | public interface Attempt extends Action { | |
16 | @Override | |
17 | default void accept(Visitor visitor) { | |
18 |
1
1. accept : removed call to com/github/dakusui/actionunit/core/Action$Visitor::visit → KILLED |
visitor.visit(this); |
19 | } | |
20 | ||
21 | Action perform(); | |
22 | ||
23 | Action recover(); | |
24 | ||
25 | Action ensure(); | |
26 | ||
27 | Class<? extends Throwable> targetExceptionClass(); | |
28 | ||
29 | @Override | |
30 | default void formatTo(Formatter formatter, int flags, int width, int precision) { | |
31 | formatter.format("attempt"); | |
32 | } | |
33 | ||
34 | class Builder extends Action.Builder<Attempt> { | |
35 | private Class<? extends Throwable> targetExceptionClass = Exception.class; | |
36 | private final Action perform; | |
37 | private Action recover = Named.of("recover", | |
38 | Leaf.of( | |
39 | (Context $) -> { | |
40 |
1
1. lambda$new$0 : negated conditional → KILLED |
if ($.wasExceptionThrown()) { |
41 | throw ActionException.wrap($.thrownException()); | |
42 | } | |
43 | })); | |
44 | private Action ensure = Named.of("ensure", | |
45 | ActionSupport.nop() | |
46 | ); | |
47 | ||
48 | public Builder(Action perform) { | |
49 | this.perform = requireNonNull(perform); | |
50 | } | |
51 | ||
52 | public Builder recover(Class<? extends Throwable> targetExceptionClass, Consumer<Throwable> exceptionHandler) { | |
53 | this.recover = Named.of("recover", leaf(c -> { | |
54 |
1
1. lambda$recover$1 : removed call to java/util/function/Consumer::accept → NO_COVERAGE |
exceptionHandler.accept(c.thrownException()); |
55 | })); | |
56 | this.targetExceptionClass = requireNonNull(targetExceptionClass); | |
57 |
1
1. recover : replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder::recover → NO_COVERAGE |
return this; |
58 | } | |
59 | ||
60 | public Builder recover(Class<? extends Throwable> targetExceptionClass, Action recover) { | |
61 | this.recover = Named.of("recover", requireNonNull(recover)); | |
62 | this.targetExceptionClass = requireNonNull(targetExceptionClass); | |
63 |
1
1. recover : replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder::recover → KILLED |
return this; |
64 | } | |
65 | ||
66 | public Action ensure(Action ensure) { | |
67 | this.ensure = named("ensure", requireNonNull(ensure)); | |
68 |
1
1. ensure : replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder::ensure → KILLED |
return this.$(); |
69 | } | |
70 | ||
71 | public Attempt build() { | |
72 |
1
1. build : replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder::build → KILLED |
return new Attempt() { |
73 | ||
74 | @Override | |
75 | public Action perform() { | |
76 |
1
1. perform : replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder$1::perform → KILLED |
return perform; |
77 | } | |
78 | ||
79 | @Override | |
80 | public Action recover() { | |
81 |
1
1. recover : replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder$1::recover → KILLED |
return recover; |
82 | } | |
83 | ||
84 | public Class<? extends Throwable> targetExceptionClass() { | |
85 |
1
1. targetExceptionClass : replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder$1::targetExceptionClass → KILLED |
return targetExceptionClass; |
86 | } | |
87 | ||
88 | @Override | |
89 | public Action ensure() { | |
90 |
1
1. ensure : replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder$1::ensure → KILLED |
return ensure; |
91 | } | |
92 | }; | |
93 | } | |
94 | } | |
95 | } | |
Mutations | ||
18 |
1.1 |
|
40 |
1.1 |
|
54 |
1.1 |
|
57 |
1.1 |
|
63 |
1.1 |
|
68 |
1.1 |
|
72 |
1.1 |
|
76 |
1.1 |
|
81 |
1.1 |
|
85 |
1.1 |
|
90 |
1.1 |