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

Groovy example source code file (GroovyCategoryTest.groovy)

This example Groovy source code file (GroovyCategoryTest.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

category1, category2, category2, groovycategorytest, groovytestcase, hello, hello, illegalargumentexception, illegalargumentexception, string, string

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:

new blog posts

 

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