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

Mutations

16

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

22

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

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

25

1.1
Location : canRead
Killed by : none
replaced boolean return with false for pro/verron/officestamper/core/UnionIndexAccessor::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/UnionIndexAccessor::canRead → NO_COVERAGE

32

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

35

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

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

42

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

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

45

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

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

46

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

52

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

57

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

59

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

67

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

Active mutators

Tests examined


Report generated by PIT 1.22.1