TreeRouter implements Router { @Override public Agent[] route(Request request) { Node node = root; while (node != null && !node.isLeaf()) { node = node.selectChild(request); } if (node != null) { return node.getValue(); } else { return new Agent[0]; } } TreeRouter(Node root); @Override Agent[] route(Request request); @Override Agent[] getAgents();  }
@Test public void testRoutingWithBinaryTree() { Router router = createBinaryTreeRouter(); Request r1 = new Request("What is the historical weather for June"); Request r2 = new Request("What is the current weather for Seattle"); Request r3 = new Request("What was score for last night's baseball game"); Request r4 = new Request("What was the score for last night's football game"); assertEquals("historical", router.route(r1)[0].getName()); assertEquals("current", router.route(r2)[0].getName()); assertEquals("baseball", router.route(r3)[0].getName()); assertEquals("football", router.route(r4)[0].getName()); }
@Test public void testNoText() { Router router = createBinaryTreeRouter(); assertEquals(0, router.route(new Request("")).length); }