### Question:
NumNode2 implements Node2 { @Override public void print(Writer out) throws IOException { out.write(String.valueOf(value)); } NumNode2(int value); @Override int calc(); @Override void print(Writer out); final int value; }### Answer:
@Test public void testPrint() throws Exception { Node2 node1 = new NumNode2(2); Node2 node2 = new NumNode2(3); Node2 node3 = new AddNode2(node1, node2); Node2 node4 = new NumNode2(4); Node2 node5 = new AddNode2(node3, node4); StringWriter out = new StringWriter(); node5.print(out); String actual = out.toString(); String expected = "((2+3)+4)"; assertThat(actual, is(expected)); }