|
Groovy example source code file (NodeGPathTest.groovy)
The Groovy NodeGPathTest.groovy source codepackage groovy.gpath /** * Some GPath tests using trees */ class NodeGPathTest extends GroovyTestCase { void testFind() { def tree = createTree() assert tree.person.find { it['@name'] == 'James' }.location[0]['@name'] == 'London' } void testFindAll() { def tree = createTree() def peopleWithNameBob = tree.person.findAll { it['@name'] != 'Bob' } assert peopleWithNameBob.size() == 1 } void testCollect() { def tree = createTree() def namesOfAllPeople = tree.person.collect { it['@name'] } assert namesOfAllPeople == ['James', 'Bob'] } protected def createTree() { def builder = NodeBuilder.newInstance() def root = builder.people() { person(name:'James') { location(name:'London') projects { project(name:'geronimo') } } person(name:'Bob') { location(name:'Atlanta') projects { project(name:'drools') } } } assert root != null return root } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy NodeGPathTest.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.