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

Groovy example source code file (Groovy3839Bug.groovy)

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

g3839a2, g3839a3, g3839a4, g3839v1, g3839v1, g3839v2, g3839v3, g3839v3, g3839v4, g3839v4, groovy3839bug, groovyasttransformationclass, groovyasttransformationclass, groovytestcase

The Groovy Groovy3839Bug.groovy source code

package groovy.bugs

class Groovy3839Bug extends GroovyTestCase {
    void testGroovyASTTransformationWithOneClass() {
        assertScript """
            import groovy.bugs.*
    
            @G3839A1
            class G3839V1 {}
            // verify if the ast transform added field 1
            assert G3839V1.class.fields.find{it.name == 'f1'} != null
        """
    }

    void testGroovyASTTransformationWithMultipleClass() {
        assertScript """
            import groovy.bugs.*
    
            @G3839A2
            class G3839V2 {}
            // verify if the ast transforms added field f2 and f3
            assert G3839V2.class.fields.find{it.name == 'f2'} != null
            assert G3839V2.class.fields.find{it.name == 'f3'} != null
        """
    }
    
    void testGroovyASTTransformationWithNeitherTransClassNamesNorClasses() {
        try {
            assertScript """
                import groovy.bugs.*
        
                @G3839A3
                class G3839V3 {}
                new G3839V3()
            """
            fail('The script should have failed as @GroovyASTTransformationClass in GroovyASTTransformationClass does not specify transform class names or classes')
        }catch(ex) {
            assert ex.message.contains('@GroovyASTTransformationClass in groovy.bugs.G3839A3 does not specify any transform class names/classes')
        }
    }

    void testGroovyASTTransformationWithBothTransClassNamesAndClasses() {
        try {
            assertScript """
                import groovy.bugs.*
        
                @G3839A4
                class G3839V4 {}
                new G3839V4()
            """
            fail('The script should have failed as @GroovyASTTransformationClass in GroovyASTTransformationClass does specifies both transform class names and classes')
        }catch(ex) {
            assert ex.message.contains('@GroovyASTTransformationClass in groovy.bugs.G3839A4 should specify transforms only by class names or by classes and not by both')
        }
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy Groovy3839Bug.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.