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.MultiParamsContextConsumerBuilder; | |
6 | import com.github.dakusui.actionunit.core.context.multiparams.MultiParamsContextFunctionBuilder; | |
7 | import com.github.dakusui.actionunit.core.context.multiparams.MultiParamsContextPredicateBuilder; | |
8 | import com.github.dakusui.actionunit.utils.Checks; | |
9 | import com.github.dakusui.actionunit.utils.InternalUtils; | |
10 | import com.github.dakusui.actionunit.utils.StableTemplatingUtils; | |
11 | ||
12 | import java.io.PrintStream; | |
13 | import java.util.Arrays; | |
14 | import java.util.TreeMap; | |
15 | import java.util.function.Consumer; | |
16 | import java.util.function.Function; | |
17 | import java.util.function.IntFunction; | |
18 | import java.util.stream.IntStream; | |
19 | ||
20 | import static com.github.dakusui.actionunit.utils.InternalUtils.objectToStringIfOverridden; | |
21 | import static com.github.dakusui.actionunit.utils.InternalUtils.toStringIfOverriddenOrNoname; | |
22 | import static java.lang.String.format; | |
23 | import static java.util.Objects.requireNonNull; | |
24 | import static java.util.stream.Collectors.joining; | |
25 | ||
26 | public enum ContextFunctions { | |
27 | ; | |
28 | ||
29 | public static MultiParamsContextPredicateBuilder multiParamsPredicateFor(ContextVariable... variables) { | |
30 |
1
1. multiParamsPredicateFor : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::multiParamsPredicateFor → KILLED |
return new MultiParamsContextPredicateBuilder(variables); |
31 | } | |
32 | ||
33 | public static MultiParamsContextConsumerBuilder multiParamsConsumerFor(ContextVariable... variables) { | |
34 |
1
1. multiParamsConsumerFor : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::multiParamsConsumerFor → KILLED |
return new MultiParamsContextConsumerBuilder(variables); |
35 | } | |
36 | ||
37 | public static <R> MultiParamsContextFunctionBuilder<R> multiParamsFunctionFor(ContextVariable... variables) { | |
38 |
1
1. multiParamsFunctionFor : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::multiParamsFunctionFor → KILLED |
return new MultiParamsContextFunctionBuilder<>(variables); |
39 | } | |
40 | ||
41 | public static String describeFunctionalObject(Object f, final IntFunction<String> placeHolderFormatter, ContextVariable... variables) { | |
42 |
1
1. describeFunctionalObject : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::describeFunctionalObject → KILLED |
return String.format("(%s)->%s", |
43 |
1
1. lambda$describeFunctionalObject$0 : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$describeFunctionalObject$0 → KILLED |
String.join(",", Arrays.stream(variables).map(ContextVariable::variableName).toArray(String[]::new)), |
44 | summarize(StableTemplatingUtils.template( | |
45 |
1
1. lambda$describeFunctionalObject$1 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$describeFunctionalObject$1 → KILLED |
objectToStringIfOverridden(f, obj -> formatPlaceHolders(obj, placeHolderFormatter, variables)), |
46 | new TreeMap<String, Object>() {{ | |
47 |
1
1. <init> : removed call to java/util/stream/IntStream::forEach → KILLED |
IntStream.range(0, variables.length).forEach( |
48 | i -> put(placeHolderFormatter.apply(i), String.format("${%s}", variables[i])) | |
49 | ); | |
50 | }}), 60)); | |
51 | } | |
52 | ||
53 | private static String formatPlaceHolders(Object obj, IntFunction<String> placeHolderFormatter, ContextVariable[] v) { | |
54 |
1
1. formatPlaceHolders : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::formatPlaceHolders → KILLED |
return InternalUtils.fallbackFormatter().apply(obj) + |
55 | IntStream.range(0, v.length) | |
56 | .mapToObj(placeHolderFormatter) | |
57 | .collect(joining(", ", "(", ")")); | |
58 | } | |
59 | ||
60 | public static <R> ContextConsumer assignTo(ContextVariable contextVariable, Function<Context, R> value) { | |
61 | requireNonNull(contextVariable); | |
62 | requireNonNull(value); | |
63 |
1
1. assignTo : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::assignTo → KILLED |
return ContextConsumer.of( |
64 |
1
1. lambda$assignTo$2 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$assignTo$2 → NO_COVERAGE |
() -> format("assignTo[%s](%s)", contextVariable.variableName(), toStringIfOverriddenOrNoname(value)), |
65 | (c) -> c.assignTo(contextVariable.internalVariableName(), value.apply(c))); | |
66 | } | |
67 | ||
68 | public static <R> ContextFunction<R> immediateOf(R value) { | |
69 |
3
1. immediateOf : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::immediateOf → KILLED 2. lambda$immediateOf$4 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$immediateOf$4 → KILLED 3. lambda$immediateOf$5 : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$immediateOf$5 → KILLED |
return ContextFunction.of(() -> format("%s", value), c -> value); |
70 | } | |
71 | ||
72 | public static <R> ContextFunction<R> contextValueOf(ContextVariable contextVariable) { | |
73 | requireNonNull(contextVariable); | |
74 |
1
1. contextValueOf : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::contextValueOf → KILLED |
return ContextFunction.of( |
75 |
1
1. lambda$contextValueOf$6 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$contextValueOf$6 → NO_COVERAGE |
() -> format("valueOf[%s]", contextVariable.variableName()), |
76 | contextVariable::resolve | |
77 | ); | |
78 | } | |
79 | ||
80 | public static ContextConsumer throwIllegalArgument() { | |
81 |
1
1. throwIllegalArgument : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::throwIllegalArgument → KILLED |
return ContextConsumer.of( |
82 |
1
1. lambda$throwIllegalArgument$7 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$throwIllegalArgument$7 → NO_COVERAGE |
() -> "throw IllegalArgumentException", |
83 | (c) -> { | |
84 | throw new IllegalArgumentException(); | |
85 | } | |
86 | ); | |
87 | } | |
88 | ||
89 | public static <R> ContextConsumer printTo(PrintStream ps, Function<Context, R> value) { | |
90 | requireNonNull(ps); | |
91 |
1
1. printTo : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::printTo → KILLED |
return ContextConsumer.of( |
92 |
1
1. lambda$printTo$9 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$printTo$9 → NO_COVERAGE |
() -> format("printTo[%s](%s)", prettyClassName(ps.getClass()), value), |
93 |
1
1. lambda$printTo$10 : removed call to java/io/PrintStream::println → SURVIVED |
c -> ps.println(value.apply(c)) |
94 | ); | |
95 | } | |
96 | ||
97 | public static <R> ContextConsumer writeTo(Consumer<R> sink, Function<Context, R> value) { | |
98 | requireNonNull(sink); | |
99 |
1
1. writeTo : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::writeTo → KILLED |
return ContextConsumer.of( |
100 |
1
1. lambda$writeTo$11 : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$writeTo$11 → NO_COVERAGE |
() -> format("writeTo[%s](%s)", prettyClassName(sink.getClass()), value), |
101 |
1
1. lambda$writeTo$12 : removed call to java/util/function/Consumer::accept → KILLED |
c -> sink.accept(value.apply(c)) |
102 | ); | |
103 | } | |
104 | ||
105 | public static String prettyClassName(Class<?> c) { | |
106 | String ret = c.getSimpleName(); | |
107 |
1
1. prettyClassName : negated conditional → KILLED |
if (ret.equals("")) { |
108 | Class<?> mostRecentNamedSuper = mostRecentNamedSuperOf(c); | |
109 |
1
1. prettyClassName : negated conditional → KILLED |
if (!mostRecentNamedSuper.equals(Object.class)) |
110 | ret = format("(anon:%s)", mostRecentNamedSuperOf(c).getSimpleName()); | |
111 | else | |
112 | ret = Arrays.stream(c.getInterfaces()).map(Class::getSimpleName).collect(joining | |
113 | (",", "(anon:", ")")); | |
114 | } | |
115 |
1
1. prettyClassName : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::prettyClassName → KILLED |
return ret.replaceFirst("\\$\\$Lambda\\$\\d+/(0x)?[\\da-f]+$", ".lambda"); |
116 | } | |
117 | ||
118 | private static Class<?> mostRecentNamedSuperOf(Class<?> c) { | |
119 |
1
1. mostRecentNamedSuperOf : negated conditional → KILLED |
if ("".equals(c.getSimpleName())) |
120 |
1
1. mostRecentNamedSuperOf : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::mostRecentNamedSuperOf → KILLED |
return mostRecentNamedSuperOf(c.getSuperclass()); |
121 |
1
1. mostRecentNamedSuperOf : replaced return value with null for com/github/dakusui/actionunit/core/context/ContextFunctions::mostRecentNamedSuperOf → KILLED |
return c; |
122 | } | |
123 | ||
124 | public static String summarize(String commandLine, int length) { | |
125 |
3
1. lambda$summarize$13 : changed conditional boundary → SURVIVED 2. lambda$summarize$13 : replaced boolean return with true for com/github/dakusui/actionunit/core/context/ContextFunctions::lambda$summarize$13 → SURVIVED 3. lambda$summarize$13 : negated conditional → KILLED |
Checks.requireArgument(l -> l > 3, length); |
126 |
3
1. summarize : changed conditional boundary → SURVIVED 2. summarize : negated conditional → KILLED 3. summarize : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::summarize → KILLED |
return requireNonNull(commandLine).length() < length ? |
127 | replaceNewLines(commandLine) : | |
128 |
1
1. summarize : Replaced integer subtraction with addition → SURVIVED |
replaceNewLines(commandLine).substring(0, length - 3) + "..."; |
129 | } | |
130 | ||
131 | private static String replaceNewLines(String s) { | |
132 |
1
1. replaceNewLines : replaced return value with "" for com/github/dakusui/actionunit/core/context/ContextFunctions::replaceNewLines → KILLED |
return s.replaceAll("\n", " "); |
133 | } | |
134 | } | |
Mutations | ||
30 |
1.1 |
|
34 |
1.1 |
|
38 |
1.1 |
|
42 |
1.1 |
|
43 |
1.1 |
|
45 |
1.1 |
|
47 |
1.1 |
|
54 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
69 |
1.1 2.2 3.3 |
|
74 |
1.1 |
|
75 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
91 |
1.1 |
|
92 |
1.1 |
|
93 |
1.1 |
|
99 |
1.1 |
|
100 |
1.1 |
|
101 |
1.1 |
|
107 |
1.1 |
|
109 |
1.1 |
|
115 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 |
|
121 |
1.1 |
|
125 |
1.1 2.2 3.3 |
|
126 |
1.1 2.2 3.3 |
|
128 |
1.1 |
|
132 |
1.1 |