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

Groovy example source code file (Groovy3904Bug.groovy)

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

g3904r1a, g3904r2a, g3904r3a, g3904r3b, g3904r3b, g3904r4a, g3904r5b, g3904r5b, g3904r5c, g3904r6b, g3904r6b, g3904r6c, g3904r6c, g3904r6d

The Groovy Groovy3904Bug.groovy source code

package groovy.bugs

import org.codehaus.groovy.control.MultipleCompilationErrorsException

class Groovy3904Bug extends GroovyTestCase {
    
    void compileAndVerifyCyclicInheritenceCompilationError(script) {
        try {
            new GroovyShell().parse(script)
            fail('The compilation should have failed as it is a cyclic reference')
        } catch (MultipleCompilationErrorsException e) {
            def syntaxError = e.errorCollector.getSyntaxError(0)
            assert syntaxError.message.contains('Cyclic inheritance')
        }
    }
    
    void testCyclicInheritenceTC1() {
        compileAndVerifyCyclicInheritenceCompilationError """
            class G3904R1A extends G3904R1A {}
        """ 
    }

    void testCyclicInheritenceTC2() {
        compileAndVerifyCyclicInheritenceCompilationError """
            class G3904R2A extends G3904R2A {
                public static void main(String []argv) {
                  print 'hey'
                }
            }
        """
    }

    /* next 2 tests are similar but in reverse order */
    void testCyclicInheritenceTC3() {
        compileAndVerifyCyclicInheritenceCompilationError """
            class G3904R3A extends G3904R3B {}
            class G3904R3B extends G3904R3A {}
        """
    }

    void testCyclicInheritenceTC4() {
        compileAndVerifyCyclicInheritenceCompilationError """
            class G3904R4B extends G3904R4A {}
            class G3904R4A extends G3904R4B {}
        """
    }

    // cyclic inheritence is between 2 parent classes
    void testCyclicInheritenceTC5() {
        compileAndVerifyCyclicInheritenceCompilationError """
            class G3904R5A extends G3904R5B {}
            class G3904R5B extends G3904R5C {}
            class G3904R5C extends G3904R5B {}
        """
    }

    // cyclic inheritence is between 2 parent classes with a normal level in-between
    void testCyclicInheritenceTC6() {
        compileAndVerifyCyclicInheritenceCompilationError """
            class G3904R6A extends G3904R6B {}
            class G3904R6B extends G3904R6C {}
            class G3904R6C extends G3904R6D {}
            class G3904R6D extends G3904R6B {}
        """
    }
}

Other Groovy examples (source code examples)

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