View Javadoc
1   package org.kuali.student.common.messagebuilder.booleanmessage.ast;
2   
3   import java.util.HashMap;
4   import java.util.List;
5   import java.util.Map;
6   
7   import org.junit.Assert;
8   import org.junit.Before;
9   import org.junit.Test;
10  import org.kuali.student.common.messagebuilder.booleanmessage.BooleanMessage;
11  import org.kuali.student.common.messagebuilder.booleanmessage.ast.BinaryMessageTree;
12  import org.kuali.student.common.messagebuilder.booleanmessage.ast.BooleanMessageImpl;
13  import org.kuali.student.common.messagebuilder.booleanmessage.ast.BooleanNode;
14  
15  public class BinaryMessageTreeTest {
16  	private Map<String,BooleanMessage> messageMap;
17  	
18  	@Before
19  	public void setUp() throws Exception {
20  		messageMap = new HashMap<String, BooleanMessage>();
21  		messageMap.put("A", new BooleanMessageImpl("A", true, "A is true"));
22  		messageMap.put("B", new BooleanMessageImpl("B", true, "B is true"));
23  	}
24  	
25  	@Test
26  	public void testGetRoot() throws Exception {
27  		BinaryMessageTree btree = new BinaryMessageTree("en", messageMap);
28  		BooleanNode rootNode = btree.buildTree("A*B");
29  		
30  		Assert.assertSame(rootNode, btree.getRoot());
31  	}
32  
33  	@Test
34  	public void testBuildTree() throws Exception {
35  		BinaryMessageTree btree = new BinaryMessageTree("en", messageMap);
36  		BooleanNode rootNode = btree.buildTree("A*B");
37  		
38  		Assert.assertEquals(2, rootNode.getChildren().size());
39  		Assert.assertEquals("*", rootNode.getLabel());
40  		Assert.assertEquals("A", rootNode.getLeftNode().getLabel());
41  		Assert.assertEquals("B", rootNode.getRightNode().getLabel());
42  	}
43  
44  	@Test
45  	public void testTraverseTreePostOrder_GetAllNodes() throws Exception {
46  		BinaryMessageTree btree = new BinaryMessageTree("en", messageMap);
47  		BooleanNode rootNode = btree.buildTree("A*B");
48  		btree.traverseTreePostOrder(rootNode, null);
49  		List<BooleanNode> nodeList = btree.getAllNodes();
50  
51  		Assert.assertEquals(3, nodeList.size());
52  	}
53  
54  	@Test
55  	public void testTraverseTreePostOrderDontSetNode_GetAllNodes2() throws Exception {
56  		BinaryMessageTree btree = new BinaryMessageTree();
57  		BooleanNode rootNode = btree.buildTree("A*B");
58  		btree.traverseTreePostOrderDontSetNode(rootNode, null);
59  		List<BooleanNode> nodeList = btree.getAllNodes();
60  
61  		Assert.assertEquals(3, nodeList.size());
62  	}
63  }