home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (NavigationTest.groovy)

This example Groovy source code file (NavigationTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

groovytestcase, groovytestcase, navigationtest, navigationtest

The Groovy NavigationTest.groovy source code

package groovy.tree

/**
 * Simple test of tree walking
 */
class NavigationTest extends GroovyTestCase {
    
    void testDepthFirst() {
        def tree = createTree()
        
        def names = tree.depthFirst().collect { it.name() }
        def expected = ['a', 'b1', 'b2', 'c1', 'c2', 'b3', 'b4', 'c3', 'c4', 'b5']
        
        assert names == expected
    }
    
    void testBreadthFirst() {
        def tree = createTree()
        
        def names = tree.breadthFirst().collect { it.name() }
        def expected = ['a', 'b1', 'b2', 'b3', 'b4', 'b5', 'c1', 'c2', 'c3', 'c4']
        
        assert names == expected
    }
    
    protected def createTree() {       
        def b = NodeBuilder.newInstance()
        
        def root = b.a(a:5, b:7) {
            b1()
            b2 {
                c1()
                c2()
            }
            b3()
            b4 {
                c3()
                c4()
            }
            b5()
        }
        
        assert root != null
        
        println(root)
        
        return root
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy NavigationTest.groovy source code file:

new blog posts

 

Copyright 1998-2013 Alvin Alexander, alvinalexander.com
All Rights Reserved.