|
Groovy example source code file (GroovyCategoryTest.groovy)
The Groovy GroovyCategoryTest.groovy source code
package org.codehaus.groovy.runtime
class GroovyCategoryTest extends GroovyTestCase {
void testUseWithVarArg() {
// Try out the single class case
use(Category1) {
assert "HeLlO".upper() == "HELLO"
}
// Try out the list case
use([Category1, Category2]) {
assert "HeLlO".upper() == "HELLO"
assert "HeLlO".lower() == "hello"
}
// Try out the vararg version
use(Category1, Category2) {
assert "HeLlO".upper() == "HELLO"
assert "HeLlO".lower() == "hello"
}
// This should fail
try {
use(Category1)
fail()
} catch (IllegalArgumentException e) {
}
// And so should this
try {
use(Category1, Category2)
fail()
} catch (IllegalArgumentException e) {
}
}
}
class Category1 {
static String upper(String message) {return message.toUpperCase()}
}
class Category2 {
static String lower(String message) {return message.toLowerCase()}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy GroovyCategoryTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.