MapAccessor.java

1
package pro.verron.officestamper.preset;
2
3
import org.springframework.expression.AccessException;
4
import org.springframework.expression.EvaluationContext;
5
import org.springframework.expression.PropertyAccessor;
6
import org.springframework.expression.TypedValue;
7
import org.springframework.lang.Nullable;
8
import org.springframework.util.Assert;
9
10
import java.util.Map;
11
12
public class MapAccessor
13
        implements PropertyAccessor {
14
15
    @Override
16
    public Class<?>[] getSpecificTargetClasses() {
17 1 1. getSpecificTargetClasses : replaced return value with null for pro/verron/officestamper/preset/MapAccessor::getSpecificTargetClasses → SURVIVED
        return new Class<?>[]{Map.class};
18
    }
19
20
    @Override
21
    public boolean canRead(EvaluationContext context, @Nullable Object target, String name) {
22 3 1. canRead : replaced boolean return with true for pro/verron/officestamper/preset/MapAccessor::canRead → SURVIVED
2. canRead : negated conditional → KILLED
3. canRead : negated conditional → KILLED
        return (target instanceof Map<?, ?> map && map.containsKey(name));
23
    }
24
25
    @Override
26
    public TypedValue read(EvaluationContext context, @Nullable Object target, String name)
27
            throws AccessException {
28 1 1. read : removed call to org/springframework/util/Assert::state → SURVIVED
        Assert.state(target instanceof Map, "Target must be of type Map");
29
        Map<?, ?> map = (Map<?, ?>) target;
30
        Object value = map.get(name);
31 2 1. read : negated conditional → SURVIVED
2. read : negated conditional → KILLED
        if (value == null && !map.containsKey(name)) {
32
            throw new MapAccessException(name);
33
        }
34 1 1. read : replaced return value with null for pro/verron/officestamper/preset/MapAccessor::read → KILLED
        return new TypedValue(value);
35
    }
36
37
    @Override
38
    public boolean canWrite(EvaluationContext context, @Nullable Object target, String name) {
39 2 1. canWrite : replaced boolean return with true for pro/verron/officestamper/preset/MapAccessor::canWrite → NO_COVERAGE
2. canWrite : replaced boolean return with false for pro/verron/officestamper/preset/MapAccessor::canWrite → NO_COVERAGE
        return target instanceof Map;
40
    }
41
42
    @Override
43
    @SuppressWarnings("unchecked")
44
    public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue) {
45 1 1. write : removed call to org/springframework/util/Assert::state → NO_COVERAGE
        Assert.state(target instanceof Map, "Target must be of type Map");
46
        Map<Object, Object> map = (Map<Object, Object>) target;
47
        map.put(name, newValue);
48
    }
49
50
    /**
51
     * Exception thrown from {@code read} in order to reset a cached
52
     * PropertyAccessor, allowing other accessors to have a try.
53
     */
54
    private static class MapAccessException
55
            extends AccessException {
56
57
        private final String key;
58
59
        public MapAccessException(String key) {
60
            super("");
61
            this.key = key;
62
        }
63
64
        @Override
65
        public String getMessage() {
66 1 1. getMessage : replaced return value with "" for pro/verron/officestamper/preset/MapAccessor$MapAccessException::getMessage → NO_COVERAGE
            return "Map does not contain a value for key '" + this.key + "'";
67
        }
68
    }
69
}

Mutations

17

1.1
Location : getSpecificTargetClasses
Killed by : none
replaced return value with null for pro/verron/officestamper/preset/MapAccessor::getSpecificTargetClasses → SURVIVED
Covering tests

22

1.1
Location : canRead
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]
negated conditional → KILLED

2.2
Location : canRead
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]
negated conditional → KILLED

3.3
Location : canRead
Killed by : none
replaced boolean return with true for pro/verron/officestamper/preset/MapAccessor::canRead → SURVIVED
Covering tests

28

1.1
Location : read
Killed by : none
removed call to org/springframework/util/Assert::state → SURVIVED
Covering tests

31

1.1
Location : read
Killed by : none
negated conditional → SURVIVED
Covering tests

2.2
Location : read
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]
negated conditional → KILLED

34

1.1
Location : read
Killed by : pro.verron.officestamper.test.NullPointerResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.NullPointerResolutionTest]/[test-template:nullPointerResolutionTest_testThrowingCase(pro.verron.officestamper.test.ContextFactory)]/[test-template-invocation:#2]
replaced return value with null for pro/verron/officestamper/preset/MapAccessor::read → KILLED

39

1.1
Location : canWrite
Killed by : none
replaced boolean return with true for pro/verron/officestamper/preset/MapAccessor::canWrite → NO_COVERAGE

2.2
Location : canWrite
Killed by : none
replaced boolean return with false for pro/verron/officestamper/preset/MapAccessor::canWrite → NO_COVERAGE

45

1.1
Location : write
Killed by : none
removed call to org/springframework/util/Assert::state → NO_COVERAGE

66

1.1
Location : getMessage
Killed by : none
replaced return value with "" for pro/verron/officestamper/preset/MapAccessor$MapAccessException::getMessage → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.20.0