### Question:
NodeTree { public NodeTree withValue(String node, int value) { String[] parts = SPLIT_REGEX.split(node.toLowerCase()); Node newRoot = new Node(new HashMap<>(this.rootNode.children)); Node newPtr = newRoot; Node currentPtr = this.rootNode; newPtr.value = currentPtr == null ? 0 : currentPtr.value; for (String part : parts) { Node oldChild = currentPtr == null ? null : currentPtr.children.get(part); Node newChild = new Node(oldChild != null ? new HashMap<>(oldChild.children) : new HashMap<String, Node>()); newPtr.children.put(part, newChild); currentPtr = oldChild; newPtr = newChild; } newPtr.value = value; return new NodeTree(newRoot); } private  NodeTree(int value); private  NodeTree(Node rootNode); static NodeTree of(Map<String, Integer> values); static NodeTree of(Map<String, Integer> values, int defaultValue); int get(String node); Map<String, Integer> asMap(); NodeTree withValue(String node, int value); NodeTree withAll(Map<String, Integer> values); static final int PERMISSION_UNDEFINED; }### Answer:
@Test public void testWithValue() { final Map<String, Integer> testPermissions = new HashMap<>(); testPermissions.put("generate.rainbow", 1); testPermissions.put("generate.sunset", -1); testPermissions.put("generate", 1); testPermissions.put("generate.thunderstorm.explosive", -1); NodeTree oldTree = NodeTree.of(testPermissions); assertEquals(-1, oldTree.get("generate.thunderstorm.explosive")); NodeTree newTree = oldTree.withValue("generate.thunderstorm.explosive", 1); assertEquals(-1, oldTree.get("generate.thunderstorm.explosive")); assertEquals(1, newTree.get("generate.thunderstorm.explosive")); }