001 package org.kuali.student.common.messagebuilder.booleanmessage.ast; 002 003 import org.antlr.runtime.Token; 004 import org.antlr.runtime.tree.CommonTreeAdaptor; 005 import org.junit.Assert; 006 import org.junit.Test; 007 import org.kuali.student.common.messagebuilder.booleanmessage.ast.BooleanNode; 008 import org.kuali.student.common.messagebuilder.booleanmessage.ast.parsers.BooleanFunctionParser; 009 010 public class BooleanNodeTest { 011 012 private final static CommonTreeAdaptor adapter = new CommonTreeAdaptor(); 013 014 @Test 015 public void testBooleanNode() throws Exception { 016 Token and = adapter.createToken(BooleanFunctionParser.AND, "*"); 017 Token a = adapter.createToken(BooleanFunctionParser.ALPHA, "A"); 018 Token b = adapter.createToken(BooleanFunctionParser.ALPHA, "B"); 019 020 // root node 021 BooleanNode andNode = new BooleanNode(and); 022 023 BooleanNode aNode = new BooleanNode(a); 024 aNode.setParent(andNode); 025 aNode.setValue(Boolean.TRUE); 026 aNode.setLanguage("en"); 027 aNode.setNodeMessage("MATH101"); 028 029 BooleanNode bNode = new BooleanNode(b); 030 bNode.setParent(andNode); 031 bNode.setValue(Boolean.FALSE); 032 bNode.setNodeMessage("MATH201"); 033 034 andNode.addChild(aNode); // left node 035 andNode.addChild(bNode); // right node 036 037 Assert.assertEquals("en", aNode.getLanguage()); 038 Assert.assertEquals("MATH101", aNode.getNodeMessage()); 039 Assert.assertEquals(Boolean.TRUE, aNode.getValue()); 040 Assert.assertSame(andNode, aNode.getParent()); 041 Assert.assertSame(aNode, andNode.getLeftNode()); 042 Assert.assertSame(bNode, andNode.getRightNode()); 043 } 044 }