Invokers.java

1
package pro.verron.officestamper.core;
2
3
import org.springframework.core.convert.TypeDescriptor;
4
import org.springframework.expression.*;
5
import org.springframework.lang.NonNull;
6
7
import java.util.*;
8
import java.util.Map.Entry;
9
import java.util.stream.Stream;
10
11
import static java.util.Arrays.stream;
12
import static java.util.Collections.emptyMap;
13
import static java.util.stream.Collectors.groupingBy;
14
import static java.util.stream.Collectors.toMap;
15
16
/**
17
 * Resolves methods that are used as expression functions or comment processors.
18
 *
19
 * @author Joseph Verron
20
 * @version ${version}
21
 * @since 1.6.2
22
 */
23
public class Invokers
24
        implements MethodResolver {
25
    private final Map<String, Map<Args, MethodExecutor>> map;
26
27
    public Invokers(Stream<Invoker> invokerStream) {
28
        map = invokerStream.collect(groupingBy(Invoker::name, toMap(Invoker::args, Invoker::executor)));
29
    }
30
31
    static Stream<Invoker> streamInvokers(Map<Class<?>, ?> interfaces2implementations) {
32 1 1. streamInvokers : replaced return value with Stream.empty for pro/verron/officestamper/core/Invokers::streamInvokers → KILLED
        return interfaces2implementations.entrySet()
33
                                         .stream()
34
                                         .flatMap(Invokers::streamInvokers);
35
    }
36
37
    private static Stream<Invoker> streamInvokers(Entry<Class<?>, ?> interface2implementation) {
38 1 1. streamInvokers : replaced return value with Stream.empty for pro/verron/officestamper/core/Invokers::streamInvokers → KILLED
        return streamInvokers(interface2implementation.getKey(), interface2implementation.getValue());
39
    }
40
41
    private static Stream<Invoker> streamInvokers(Class<?> key, Object obj) {
42 2 1. streamInvokers : replaced return value with Stream.empty for pro/verron/officestamper/core/Invokers::streamInvokers → KILLED
2. lambda$streamInvokers$0 : replaced return value with null for pro/verron/officestamper/core/Invokers::lambda$streamInvokers$0 → KILLED
        return stream(key.getDeclaredMethods()).map(method -> new Invoker(obj, method));
43
    }
44
45
    /** {@inheritDoc} */
46
    @Override public MethodExecutor resolve(
47
            @NonNull EvaluationContext context,
48
            @NonNull Object targetObject,
49
            @NonNull String name,
50
            @NonNull List<TypeDescriptor> argumentTypes
51
    ) {
52
        List<Class<?>> argumentClasses = new ArrayList<>();
53 1 1. resolve : removed call to java/util/List::forEach → KILLED
        argumentTypes.forEach(at -> argumentClasses.add(at.getType()));
54 1 1. resolve : replaced return value with null for pro/verron/officestamper/core/Invokers::resolve → KILLED
        return map.getOrDefault(name, emptyMap())
55
                  .entrySet()
56
                  .stream()
57 2 1. lambda$resolve$2 : replaced boolean return with true for pro/verron/officestamper/core/Invokers::lambda$resolve$2 → KILLED
2. lambda$resolve$2 : replaced boolean return with false for pro/verron/officestamper/core/Invokers::lambda$resolve$2 → KILLED
                  .filter(entry -> entry.getKey()
58
                                        .validate(argumentClasses))
59
                  .map(Entry::getValue)
60
                  .findFirst()
61
                  .orElse(null);
62
    }
63
64
    public record Args(List<Class<?>> sourceTypes) {
65
        public boolean validate(List<Class<?>> searchedTypes) {
66 2 1. validate : replaced boolean return with true for pro/verron/officestamper/core/Invokers$Args::validate → KILLED
2. validate : negated conditional → KILLED
            if (searchedTypes.size() != sourceTypes.size()) return false;
67
68
            var sourceTypesQ = new ArrayDeque<>(sourceTypes);
69
            var searchedTypesQ = new ArrayDeque<>(searchedTypes);
70
            var valid = true;
71 2 1. validate : negated conditional → SURVIVED
2. validate : negated conditional → KILLED
            while (!sourceTypesQ.isEmpty() && valid) {
72
                Class<?> parameterType = sourceTypesQ.remove();
73
                Class<?> searchedType = searchedTypesQ.remove();
74
                valid = parameterType.isAssignableFrom(searchedType);
75
            }
76 2 1. validate : replaced boolean return with true for pro/verron/officestamper/core/Invokers$Args::validate → SURVIVED
2. validate : replaced boolean return with false for pro/verron/officestamper/core/Invokers$Args::validate → KILLED
            return valid;
77
        }
78
    }
79
}

Mutations

32

1.1
Location : streamInvokers
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test64()]
replaced return value with Stream.empty for pro/verron/officestamper/core/Invokers::streamInvokers → KILLED

38

1.1
Location : streamInvokers
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test64()]
replaced return value with Stream.empty for pro/verron/officestamper/core/Invokers::streamInvokers → KILLED

42

1.1
Location : streamInvokers
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test64()]
replaced return value with Stream.empty for pro/verron/officestamper/core/Invokers::streamInvokers → KILLED

2.2
Location : lambda$streamInvokers$0
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#34]
replaced return value with null for pro/verron/officestamper/core/Invokers::lambda$streamInvokers$0 → KILLED

53

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.DefaultTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DefaultTests]/[test-template:features(java.lang.String, pro.verron.officestamper.api.OfficeStamperConfiguration, java.lang.Object, java.io.InputStream, java.lang.String)]/[test-template-invocation:#22]
removed call to java/util/List::forEach → KILLED

54

1.1
Location : resolve
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test64()]
replaced return value with null for pro/verron/officestamper/core/Invokers::resolve → KILLED

57

1.1
Location : lambda$resolve$2
Killed by : pro.verron.officestamper.test.DateFormatTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DateFormatTests]/[method:features()]
replaced boolean return with true for pro/verron/officestamper/core/Invokers::lambda$resolve$2 → KILLED

2.2
Location : lambda$resolve$2
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test64()]
replaced boolean return with false for pro/verron/officestamper/core/Invokers::lambda$resolve$2 → KILLED

66

1.1
Location : validate
Killed by : pro.verron.officestamper.test.DateFormatTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.DateFormatTests]/[method:features()]
replaced boolean return with true for pro/verron/officestamper/core/Invokers$Args::validate → KILLED

2.2
Location : validate
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test64()]
negated conditional → KILLED

71

1.1
Location : validate
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test64()]
negated conditional → KILLED

2.2
Location : validate
Killed by : none
negated conditional → SURVIVED
Covering tests

76

1.1
Location : validate
Killed by : none
replaced boolean return with true for pro/verron/officestamper/core/Invokers$Args::validate → SURVIVED
Covering tests

2.2
Location : validate
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[method:test64()]
replaced boolean return with false for pro/verron/officestamper/core/Invokers$Args::validate → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.1