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

Groovy example source code file (Groovy3852Bug.groovy)

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

compilabletestsupport, deprecated, deprecated, groovy3852bug, groovy3925, groovy3930, groovyclassloader, newify, newify, runtime, runtime, toodeprecatedgroovy3852v2, toodeprecatedgroovy3852v3, toodeprecatedgroovy3852v3

The Groovy Groovy3852Bug.groovy source code

package groovy.bugs

import gls.CompilableTestSupport

class Groovy3852Bug extends CompilableTestSupport {
    def gcl = new GroovyClassLoader()
    void testDuplicationAnnotationOnClassNoParams() {
        try {
            gcl.parseClass """
                @Deprecated
                @Deprecated
                @Deprecated
                class TooDeprecatedGroovy3852V1 {}
            """
            fail('The class compilation should have failed as it has duplication annotations')
        }catch(ex) {
            assertTrue ex.message.contains('Cannot specify duplicate annotation')
        }
    }

    void testDuplicationAnnotationOnClassWithParams() {
        try {
            gcl.parseClass """
                import java.lang.annotation.*
                @Retention(value=RetentionPolicy.CLASS)
                @Retention(value=RetentionPolicy.CLASS)
                @interface TooDeprecatedGroovy3852V2 {}
            """
            fail('The class compilation should have failed as it has duplication annotations')
        }catch(ex) {
            assertTrue ex.message.contains('Cannot specify duplicate annotation')
        }
    }

    void testDuplicationAnnotationOnOtherTargets() {
        try {
            gcl.parseClass """
                class TooDeprecatedGroovy3852V3 {
                    @Deprecated
                    @Deprecated
                    @Deprecated
                    def m() {}
                }
            """
            fail('The class compilation should have failed as it has duplication annotations on a method')
        }catch(ex) {
            assertTrue ex.message.contains('Cannot specify duplicate annotation')
        }

        try {
            gcl.parseClass """
                class TooDeprecatedGroovy3852V3 {
                    @Deprecated
                    @Deprecated
                    @Deprecated
                    def f
                }
            """
            fail('The class compilation should have failed as it has duplication annotations on a field')
        }catch(ex) {
            assertTrue ex.message.contains('Cannot specify duplicate annotation')
        }
    }

    void testDuplicationNonRuntimeRetentionPolicyAnnotations() {
        try {
            gcl.parseClass """
                @Newify(auto=false, value=String)
                @Newify(auto=false, value=String)
                class Groovy3930 {}
            """
        } catch (ex) {
            fail('The class compilation should have succeeded as it has duplication annotations but with retention policy not at RUNTIME')
        }
    }

    void testDuplicationAnnotationsForImport() {
        // TODO: replace with better test - Newify doesn't really make sense for import
        try {
            gcl.parseClass """
                @Newify(auto=false, value=String)
                @Newify(auto=false, value=String)
                import java.lang.String
                class Groovy3925 {}
            """
        } catch (ex) {
            fail('The class compilation should have succeeded as it has duplication annotations but with retention policy not at RUNTIME')
        }
    }
}

Other Groovy examples (source code examples)

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

new blog posts

 

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