Attempt.java

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
Location : accept
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenAttemptAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
removed call to com/github/dakusui/actionunit/core/Action$Visitor::visit → KILLED

40

1.1
Location : lambda$new$0
Killed by : com.github.dakusui.actionunit.scenarios.Compat2ActionSupportTest$AttemptTest.attemptTest2(com.github.dakusui.actionunit.scenarios.Compat2ActionSupportTest$AttemptTest)
negated conditional → KILLED

54

1.1
Location : lambda$recover$1
Killed by : none
removed call to java/util/function/Consumer::accept → NO_COVERAGE

57

1.1
Location : recover
Killed by : none
replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder::recover → NO_COVERAGE

63

1.1
Location : recover
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenAttemptAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder::recover → KILLED

68

1.1
Location : ensure
Killed by : com.github.dakusui.actionunit.ut.actions.AttemptTest.givenAttemptAction$whenPerform$thenWorksFine(com.github.dakusui.actionunit.ut.actions.AttemptTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder::ensure → KILLED

72

1.1
Location : build
Killed by : com.github.dakusui.actionunit.ut.ActionVisitorTest.givenAttemptAction$whenAccept$thenVisited(com.github.dakusui.actionunit.ut.ActionVisitorTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder::build → KILLED

76

1.1
Location : perform
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.print(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder$1::perform → KILLED

81

1.1
Location : recover
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.print(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder$1::recover → KILLED

85

1.1
Location : targetExceptionClass
Killed by : com.github.dakusui.actionunit.ut.actions.AttemptTest.givenAttemptAction$whenPerform$thenWorksFine(com.github.dakusui.actionunit.ut.actions.AttemptTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder$1::targetExceptionClass → KILLED

90

1.1
Location : ensure
Killed by : com.github.dakusui.actionunit.scenarios.ActionSupportTest.print(com.github.dakusui.actionunit.scenarios.ActionSupportTest)
replaced return value with null for com/github/dakusui/actionunit/actions/Attempt$Builder$1::ensure → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3