|
Groovy example source code file (GroovyCategoryTest.groovy)
The Groovy GroovyCategoryTest.groovy source codepackage 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: |
... 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.