nodegpathtest.groovy
来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· GROOVY 代码 · 共 45 行
GROOVY
45 行
package 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
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?