FileDocCategorySizeDatePackage
ASTUtilTest.javaAPI DocHibernate 3.2.52038Tue Dec 12 16:22:26 GMT 2006org.hibernate.test.ast

ASTUtilTest

public class ASTUtilTest extends org.hibernate.junit.UnitTestCase
Unit test for ASTUtil.

Fields Summary
private antlr.ASTFactory
factory
Constructors Summary
public ASTUtilTest(String name)
Standard JUnit test case constructor.

param
name The name of the test case.

		super( name );
	
Methods Summary
protected voidsetUp()

		super.setUp();
		factory = new ASTFactory();
	
public static junit.framework.Testsuite()

		return new TestSuite( ASTUtilTest.class );
	
public voidtestCreate()

		AST n = ASTUtil.create( factory, 1, "one");
		assertNull( n.getFirstChild() );
		assertEquals("one",n.getText());
		assertEquals(1,n.getType());
	
public voidtestCreateTree()
Test adding a tree of children.

		AST[] tree = new AST[4];
		AST grandparent = tree[0] = ASTUtil.create(factory, 1, "grandparent");
		AST parent = tree[1] = ASTUtil.create(factory,2,"parent");
		AST child = tree[2] = ASTUtil.create(factory,3,"child");
		AST baby = tree[3] = ASTUtil.create(factory,4,"baby");
		AST t = ASTUtil.createTree( factory, tree);
		assertSame(t,grandparent);
		assertSame(parent,t.getFirstChild());
		assertSame(child,t.getFirstChild().getFirstChild());
		assertSame(baby,t.getFirstChild().getFirstChild().getFirstChild());
	
public voidtestFindPreviousSibling()

		AST child1 = ASTUtil.create(factory,2, "child1");
		AST child2 = ASTUtil.create(factory,3, "child2");
		AST n = factory.make( new AST[] {
			ASTUtil.create(factory, 1, "parent"),
			child1,
			child2,
		});
		assertSame(child1,ASTUtil.findPreviousSibling( n,child2));
		Exception e = null;
		try {
			ASTUtil.findPreviousSibling(child1,null);
		}
		catch (Exception x) {
			e = x;
		}
		assertNotNull(e);