StreamGenerator.java

1
package com.github.dakusui.actionunit.core.context;
2
3
import com.github.dakusui.actionunit.actions.ContextVariable;
4
import com.github.dakusui.actionunit.core.Context;
5
import com.github.dakusui.actionunit.core.context.multiparams.Params;
6
import com.github.dakusui.actionunit.utils.StableTemplatingUtils;
7
8
import java.util.Arrays;
9
import java.util.Collection;
10
import java.util.function.Function;
11
import java.util.stream.Stream;
12
13
import static java.util.Arrays.asList;
14
import static java.util.Objects.requireNonNull;
15
import static java.util.stream.Collectors.toMap;
16
17
public interface StreamGenerator<T> extends ContextFunction<Stream<T>> {
18
19
  @SafeVarargs
20
  static <T> Function<Context, Stream<T>> fromArray(T... elements) {
21 1 1. fromArray : replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator::fromArray → KILLED
    return fromCollection(asList(elements));
22
  }
23
24
  static <T> Function<Context, Stream<T>> fromCollection(Collection<T> collection) {
25
    requireNonNull(collection);
26 1 1. fromCollection : replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator::fromCollection → KILLED
    return fromContextWith(new Function<Params, Stream<T>>() {
27
      @Override
28
      public Stream<T> apply(Params params) {
29 1 1. apply : replaced return value with Stream.empty for com/github/dakusui/actionunit/core/context/StreamGenerator$1::apply → KILLED
        return collection.stream();
30
      }
31
32
      public String toString() {
33 1 1. toString : replaced return value with "" for com/github/dakusui/actionunit/core/context/StreamGenerator$1::toString → SURVIVED
        return String.format("%s.stream()", collection);
34
      }
35
    });
36
  }
37
38
  static <T> Function<Context, Stream<T>> fromContextWith(Function<Params, Stream<T>> func, ContextVariable... variables) {
39
    requireNonNull(func);
40 1 1. fromContextWith : replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator::fromContextWith → KILLED
    return new StreamGenerator<T>() {
41
      @Override
42
      public Stream<T> apply(Context context) {
43 1 1. apply : replaced return value with Stream.empty for com/github/dakusui/actionunit/core/context/StreamGenerator$2::apply → KILLED
        return func.apply(Params.create(context, variables));
44
      }
45
46
      @Override
47
      public String toString() {
48 1 1. toString : replaced return value with "" for com/github/dakusui/actionunit/core/context/StreamGenerator$2::toString → SURVIVED
        return String.format("(%s)->%s",
49
            String.join(",", Arrays.stream(variables)
50
                .map(ContextVariable::variableName)
51 1 1. lambda$toString$0 : replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator$2::lambda$toString$0 → KILLED
                .toArray(String[]::new)),
52
            StableTemplatingUtils.template(
53
                func.toString(),
54
                Arrays.stream(variables)
55
                    .collect(toMap(
56
                        ContextVariable::variableName,
57 1 1. lambda$toString$1 : replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator$2::lambda$toString$1 → NO_COVERAGE
                        k -> String.format("{{%s}}", k)))));
58
      }
59
    };
60
  }
61
}

Mutations

21

1.1
Location : fromArray
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test3_fromBuilder(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator::fromArray → KILLED

26

1.1
Location : fromCollection
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test3_fromBuilder(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator::fromCollection → KILLED

29

1.1
Location : apply
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsContextFunction.givenEchoVariable_i$whenPerformAsContextFunctionInsideHelloWorldLoopExpectingUnknownKeyword$thenFailureIsThrown(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsContextFunction)
replaced return value with Stream.empty for com/github/dakusui/actionunit/core/context/StreamGenerator$1::apply → KILLED

33

1.1
Location : toString
Killed by : none
replaced return value with "" for com/github/dakusui/actionunit/core/context/StreamGenerator$1::toString → SURVIVED

40

1.1
Location : fromContextWith
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test3_fromBuilder(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator::fromContextWith → KILLED

43

1.1
Location : apply
Killed by : com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsStreamGenerator.givenEchoHelloEchoWorld$whenUseAsStreamGenerator$thenBothHelloAndWorldFoundInOutput(com.github.dakusui.actionunit.ut.actions.cmd.CmdTest$AsStreamGenerator)
replaced return value with Stream.empty for com/github/dakusui/actionunit/core/context/StreamGenerator$2::apply → KILLED

48

1.1
Location : toString
Killed by : none
replaced return value with "" for com/github/dakusui/actionunit/core/context/StreamGenerator$2::toString → SURVIVED

51

1.1
Location : lambda$toString$0
Killed by : com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest.test3_fromBuilder(com.github.dakusui.actionunit.ut.ContextFunctionsHelperUnitTest)
replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator$2::lambda$toString$0 → KILLED

57

1.1
Location : lambda$toString$1
Killed by : none
replaced return value with null for com/github/dakusui/actionunit/core/context/StreamGenerator$2::lambda$toString$1 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.7.3