ContextFunction.java

1
package com.github.dakusui.actionunit.core.context;
2
3
import com.github.dakusui.actionunit.core.Context;
4
import com.github.dakusui.printables.PrintableFunction;
5
import com.github.dakusui.printables.PrintableFunctionals;
6
7
import java.util.function.Function;
8
import java.util.function.Supplier;
9
10
import static java.util.Objects.requireNonNull;
11
12
@FunctionalInterface
13
public interface ContextFunction<R> extends Function<Context, R>, Printable {
14
  default <V> Function<V, R> compose(Function<? super V, ? extends Context> before) {
15 2 1. compose : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::compose → NO_COVERAGE
2. lambda$compose$0 : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::lambda$compose$0 → NO_COVERAGE
    return v -> ContextFunction.this.apply(before.apply(v));
16
  }
17
18
  default <V> ContextFunction<V> andThen(Function<? super R, ? extends V> after) {
19
    requireNonNull(after);
20 2 1. andThen : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::andThen → NO_COVERAGE
2. lambda$andThen$1 : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::lambda$andThen$1 → NO_COVERAGE
    return (Context r) -> after.apply(apply(r));
21
  }
22
23
  static <R> ContextFunction<R> of(Supplier<String> formatter, Function<Context, R> function) {
24 1 1. of : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::of → KILLED
    return new ContextFunction.Impl<>(formatter, function);
25
  }
26
27
  class Impl<R> extends PrintableFunction<Context, R> implements ContextFunction<R> {
28
    public Impl(Supplier<String> formatter, Function<Context, R> function) {
29
      super(formatter, function);
30
    }
31
32
    @Override
33
    public <V> Function<V, R> compose(Function<? super V, ? extends Context> before) {
34 1 1. compose : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::compose → NO_COVERAGE
      return PrintableFunctionals.<V, R>printableFunction(ContextFunction.super.compose(before))
35 1 1. lambda$compose$0 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::lambda$compose$0 → NO_COVERAGE
          .describe(() -> String.format("%s(%s)", getFormatter().get(), before));
36
    }
37
38
    @Override
39
    public <V> ContextFunction<V> andThen(Function<? super R, ? extends V> after) {
40 1 1. andThen : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::andThen → KILLED
      return new ContextFunction.Impl<>(
41 1 1. lambda$andThen$1 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::lambda$andThen$1 → KILLED
          () -> String.format("%s(%s)", after, getFormatter().get()),
42
          toContextFunction(getFunction().andThen(after))
43
      );
44
    }
45
46
    @SuppressWarnings("unchecked")
47
    private static <R> ContextFunction<R> toContextFunction(Function<? super Context, ? extends R> function) {
48 1 1. toContextFunction : negated conditional → KILLED
      if (function instanceof ContextFunction)
49 1 1. toContextFunction : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::toContextFunction → KILLED
        return (ContextFunction<R>) function;
50 1 1. toContextFunction : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::toContextFunction → KILLED
      return new ContextFunction.Impl<>(function::toString, (Function<Context, R>) function);
51
    }
52
  }
53
}

Mutations

15

1.1
Location : compose
Killed by : none
replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::compose → NO_COVERAGE

2.2
Location : lambda$compose$0
Killed by : none
replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::lambda$compose$0 → NO_COVERAGE

20

1.1
Location : andThen
Killed by : none
replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::andThen → NO_COVERAGE

2.2
Location : lambda$andThen$1
Killed by : none
replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction::lambda$andThen$1 → NO_COVERAGE

24

1.1
Location : of
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/core/context/ContextFunction::of → KILLED

34

1.1
Location : compose
Killed by : none
replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::compose → NO_COVERAGE

35

1.1
Location : lambda$compose$0
Killed by : none
replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::lambda$compose$0 → NO_COVERAGE

40

1.1
Location : andThen
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test3(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::andThen → KILLED

41

1.1
Location : lambda$andThen$1
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test3(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::lambda$andThen$1 → KILLED

48

1.1
Location : toContextFunction
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test3(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
negated conditional → KILLED

49

1.1
Location : toContextFunction
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithoutUsername.composeLocalScpCommandLine(com.github.dakusui.actionunit.ut.actions.cmd.UnixCommanderFactoryTest$WithoutUsername)
replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::toContextFunction → KILLED

50

1.1
Location : toContextFunction
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test3(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunction$Impl::toContextFunction → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3