View Javadoc

1   package org.kuali.student.common.messagebuilder.booleanmessage.ast;
2   
3   import org.antlr.runtime.Token;
4   import org.antlr.runtime.tree.CommonTreeAdaptor;
5   import org.junit.Assert;
6   import org.junit.Test;
7   import org.kuali.student.common.messagebuilder.booleanmessage.ast.BooleanNode;
8   import org.kuali.student.common.messagebuilder.booleanmessage.ast.parsers.BooleanFunctionParser;
9   
10  public class BooleanNodeTest {
11  
12  	private final static CommonTreeAdaptor adapter = new CommonTreeAdaptor();
13  	
14  	@Test
15  	public void testBooleanNode() throws Exception {
16  		Token and = adapter.createToken(BooleanFunctionParser.AND, "*");
17  		Token a = adapter.createToken(BooleanFunctionParser.ALPHA, "A");
18  		Token b = adapter.createToken(BooleanFunctionParser.ALPHA, "B");
19  		
20  		// root node
21  		BooleanNode andNode = new BooleanNode(and);
22  		
23  		BooleanNode aNode = new BooleanNode(a);
24  		aNode.setParent(andNode);
25  		aNode.setValue(Boolean.TRUE);
26  		aNode.setLanguage("en");
27  		aNode.setNodeMessage("MATH101");
28  
29  		BooleanNode bNode = new BooleanNode(b);
30  		bNode.setParent(andNode);
31  		bNode.setValue(Boolean.FALSE);
32  		bNode.setNodeMessage("MATH201");
33  		
34  		andNode.addChild(aNode); // left node
35  		andNode.addChild(bNode); // right node
36  		
37  		Assert.assertEquals("en", aNode.getLanguage());
38  		Assert.assertEquals("MATH101", aNode.getNodeMessage());
39  		Assert.assertEquals(Boolean.TRUE, aNode.getValue());
40  		Assert.assertSame(andNode, aNode.getParent());
41  		Assert.assertSame(aNode, andNode.getLeftNode());
42  		Assert.assertSame(bNode, andNode.getRightNode());
43  	}
44  }