### Question:
NumNode5 implements Node5 { @Override public int accept(Visitor5 visitor) { return visitor.visit(this); } NumNode5(int value); @Override int accept(Visitor5 visitor); final int value; }### Answer:
@Test public void testCalc() throws Exception { Node5 node1 = new NumNode5(2); Node5 node2 = new NumNode5(3); Node5 node3 = new AddNode5(node1, node2); Node5 node4 = new NumNode5(4); Node5 node5 = new AddNode5(node3, node4); Calclurator5 calclurator = new Calclurator5(); int actual = node5.accept(calclurator); int expected = 2 + 3 + 4; assertThat(actual, is(expected)); }
@Test public void testPrint() throws Exception { Node5 node1 = new NumNode5(2); Node5 node2 = new NumNode5(3); Node5 node3 = new AddNode5(node1, node2); Node5 node4 = new NumNode5(4); Node5 node5 = new AddNode5(node3, node4); StringWriter out = new StringWriter(); Printer5 printer = new Printer5(out); node5.accept(printer); String actual = out.toString(); String expected = "((2+3)+4)"; assertThat(actual, is(expected)); }