UnionPropertyAccessor.java

1
package pro.verron.officestamper.core;
2
3
import org.jspecify.annotations.Nullable;
4
import org.springframework.expression.AccessException;
5
import org.springframework.expression.EvaluationContext;
6
import org.springframework.expression.PropertyAccessor;
7
import org.springframework.expression.TypedValue;
8
9
import java.util.List;
10
11
record UnionPropertyAccessor(List<PropertyAccessor> accessors)
12
        implements PropertyAccessor {
13
14
    @Override
15
    public Class<?>[] getSpecificTargetClasses() {
16 1 1. getSpecificTargetClasses : replaced return value with null for pro/verron/officestamper/core/UnionPropertyAccessor::getSpecificTargetClasses → SURVIVED
        return new Class[]{ContextBranch.class};
17
    }
18
19
    @Override
20
    public boolean canRead(EvaluationContext context, @Nullable Object target, String name)
21
            throws AccessException {
22 2 1. canRead : replaced boolean return with true for pro/verron/officestamper/core/UnionPropertyAccessor::canRead → NO_COVERAGE
2. canRead : negated conditional → NO_COVERAGE
        if (!(target instanceof ContextBranch branch)) return false;
23
        for (Object element : branch)
24
            for (PropertyAccessor accessor : accessors)
25 2 1. canRead : replaced boolean return with false for pro/verron/officestamper/core/UnionPropertyAccessor::canRead → NO_COVERAGE
2. canRead : negated conditional → NO_COVERAGE
                if (accessor.canRead(context, element, name)) return true;
26 1 1. canRead : replaced boolean return with true for pro/verron/officestamper/core/UnionPropertyAccessor::canRead → NO_COVERAGE
        return false;
27
    }
28
29
    @Override
30
    public TypedValue read(EvaluationContext context, @Nullable Object target, String name)
31
            throws AccessException {
32 1 1. read : negated conditional → NO_COVERAGE
        if (!(target instanceof ContextBranch branch)) throw new AccessException("Target is not a ContextBranch");
33
34
        for (Object element : branch)
35
            for (PropertyAccessor accessor : accessors)
36 2 1. read : replaced return value with null for pro/verron/officestamper/core/UnionPropertyAccessor::read → NO_COVERAGE
2. read : negated conditional → NO_COVERAGE
                if (accessor.canRead(context, element, name)) return accessor.read(context, element, name);
37
        throw new AccessException("Unable to read property '" + name + "' from any context object");
38
    }
39
40
    @Override
41
    public boolean canWrite(EvaluationContext context, @Nullable Object target, String name)
42
            throws AccessException {
43 2 1. canWrite : replaced boolean return with true for pro/verron/officestamper/core/UnionPropertyAccessor::canWrite → NO_COVERAGE
2. canWrite : negated conditional → NO_COVERAGE
        if (!(target instanceof ContextBranch branch)) return false;
44
        for (Object element : branch)
45
            for (PropertyAccessor accessor : accessors)
46 2 1. canWrite : replaced boolean return with false for pro/verron/officestamper/core/UnionPropertyAccessor::canWrite → NO_COVERAGE
2. canWrite : negated conditional → NO_COVERAGE
                if (accessor.canWrite(context, element, name)) return true;
47 1 1. canWrite : replaced boolean return with true for pro/verron/officestamper/core/UnionPropertyAccessor::canWrite → NO_COVERAGE
        return false;
48
    }
49
50
    @Override
51
    public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue)
52
            throws AccessException {
53 1 1. write : negated conditional → NO_COVERAGE
        if (!(target instanceof ContextBranch branch)) throw new AccessException("Target is not a ContextBranch");
54
55
        AccessException lastException = null;
56
        for (Object element : branch) {
57
            for (PropertyAccessor accessor : accessors) {
58 1 1. write : negated conditional → NO_COVERAGE
                if (!accessor.canWrite(context, element, name)) {continue;}
59
                try {
60 1 1. write : removed call to org/springframework/expression/PropertyAccessor::write → NO_COVERAGE
                    accessor.write(context, element, name, newValue);
61
                    return;
62
                } catch (AccessException e) {
63
                    lastException = e;
64
                }
65
            }
66
        }
67
68 1 1. write : negated conditional → NO_COVERAGE
        if (lastException != null) throw lastException;
69
        throw new AccessException("Unable to write property '%s' to any context object".formatted(name));
70
    }
71
}

Mutations

16

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

22

1.1
Location : canRead
Killed by : none
replaced boolean return with true for pro/verron/officestamper/core/UnionPropertyAccessor::canRead → NO_COVERAGE

2.2
Location : canRead
Killed by : none
negated conditional → NO_COVERAGE

25

1.1
Location : canRead
Killed by : none
replaced boolean return with false for pro/verron/officestamper/core/UnionPropertyAccessor::canRead → NO_COVERAGE

2.2
Location : canRead
Killed by : none
negated conditional → NO_COVERAGE

26

1.1
Location : canRead
Killed by : none
replaced boolean return with true for pro/verron/officestamper/core/UnionPropertyAccessor::canRead → NO_COVERAGE

32

1.1
Location : read
Killed by : none
negated conditional → NO_COVERAGE

36

1.1
Location : read
Killed by : none
replaced return value with null for pro/verron/officestamper/core/UnionPropertyAccessor::read → NO_COVERAGE

2.2
Location : read
Killed by : none
negated conditional → NO_COVERAGE

43

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

2.2
Location : canWrite
Killed by : none
negated conditional → NO_COVERAGE

46

1.1
Location : canWrite
Killed by : none
replaced boolean return with false for pro/verron/officestamper/core/UnionPropertyAccessor::canWrite → NO_COVERAGE

2.2
Location : canWrite
Killed by : none
negated conditional → NO_COVERAGE

47

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

53

1.1
Location : write
Killed by : none
negated conditional → NO_COVERAGE

58

1.1
Location : write
Killed by : none
negated conditional → NO_COVERAGE

60

1.1
Location : write
Killed by : none
removed call to org/springframework/expression/PropertyAccessor::write → NO_COVERAGE

68

1.1
Location : write
Killed by : none
negated conditional → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.22.1