ContextRoot.java

1
package pro.verron.officestamper.core;
2
3
import pro.verron.officestamper.api.ContextTree;
4
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8
9
/// The root of the context tree.
10
public class ContextRoot
11
        implements ContextTree {
12
13
    private static final String ROOT_KEY = String.valueOf(0);
14
    private final Map<String, ContextBranch> branches;
15
    private final Object root;
16
17
    /// Constructs a ContextRoot with the given root object.
18
    ///
19
    /// @param root the root object.
20
    public ContextRoot(Object root) {
21
        this.branches = new HashMap<>();
22
        this.root = root;
23
        this.branches.put(ROOT_KEY, new ContextBranch(this, root));
24
    }
25
26
    /// Finds a branch by its key.
27
    ///
28
    /// @param key the key of the branch.
29
    ///
30
    /// @return the branch, or `null` if not found.
31
    public ContextBranch find(String key) {
32 1 1. find : replaced return value with null for pro/verron/officestamper/core/ContextRoot::find → TIMED_OUT
        return branches.get(key);
33
    }
34
35
    @Override
36
    public String addBranch(Object subContext) {
37
        var contextElements = List.of(root, subContext);
38
        var contextBranch = new ContextBranch(this, contextElements);
39 1 1. addBranch : replaced return value with "" for pro/verron/officestamper/core/ContextRoot::addBranch → NO_COVERAGE
        return addBranch(contextBranch);
40
    }
41
42
    /// Adds a branch to the root.
43
    ///
44
    /// @param contextBranch the branch to add.
45
    /// @return the key of the added branch.
46
    public String addBranch(ContextBranch contextBranch) {
47
        var key = computeNewKey();
48
        branches.put(key, contextBranch);
49 1 1. addBranch : replaced return value with "" for pro/verron/officestamper/core/ContextRoot::addBranch → KILLED
        return key;
50
    }
51
52
    private String computeNewKey() {
53 1 1. computeNewKey : replaced return value with "" for pro/verron/officestamper/core/ContextRoot::computeNewKey → KILLED
        return String.valueOf(branches.size());
54
    }
55
}

Mutations

32

1.1
Location : find
Killed by : none
replaced return value with null for pro/verron/officestamper/core/ContextRoot::find → TIMED_OUT

39

1.1
Location : addBranch
Killed by : none
replaced return value with "" for pro/verron/officestamper/core/ContextRoot::addBranch → NO_COVERAGE

49

1.1
Location : addBranch
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#2]
replaced return value with "" for pro/verron/officestamper/core/ContextRoot::addBranch → KILLED

53

1.1
Location : computeNewKey
Killed by : pro.verron.officestamper.test.RegressionTests.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.RegressionTests]/[test-template:test52(pro.verron.officestamper.test.RegressionTests$Conditions, java.lang.String)]/[test-template-invocation:#2]
replaced return value with "" for pro/verron/officestamper/core/ContextRoot::computeNewKey → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.0