alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (ClassExpressionTest.groovy)

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

classexpressiontest, classexpressiontest, groovytestcase, groovytestcase, i, integer, integer, string, string

The Groovy ClassExpressionTest.groovy source code

package groovy

/** 
 * Tests the use of classes as variable expressions
 * 
 * @author <a href="mailto:james@coredevelopers.net">James Strachan
 * @version $Revision: 4996 $
 */
class ClassExpressionTest extends GroovyTestCase {

    void testUseOfClass() {
        def x = String
        
        System.out.println("x: " + x)
        
        assert x != null

        assert x.getName().endsWith('String')
        assert x.name.endsWith('String')

        x = Integer
        
        assert x != null
        assert x.name.endsWith('Integer')
        
        x = GroovyTestCase
        
        assert x != null
        assert x.name.endsWith('GroovyTestCase')
        
        x = ClassExpressionTest
        
        assert x != null

        System.out.println("x: " + x)
    }

    void testClassPsuedoProperty() {

        def x = "cheese";

        assert x.class != null

        assert x.class == x.getClass();

        System.err.println( "x.class: " + x.class );
    }
    
    void testPrimitiveClasses() {
        assert void == Void.TYPE
        assert int == Integer.TYPE
        assert byte == Byte.TYPE
        assert char == Character.TYPE
        assert double == Double.TYPE
        assert float == Float.TYPE
        assert long == Long.TYPE
        assert short == Short.TYPE
    }
    
    void testArrayClassReference() {
       def foo = int[]
       assert foo.name == "[I"
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy ClassExpressionTest.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.