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

Groovy example source code file (BadLineNumberOnExceptionBugTest.groovy)

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

badlinenumberonexceptionbugtest, badlinenumberonexceptionbugtest, foo, foo, groovytestcase, missingmethodexception, missingmethodexception, missingpropertyexception, missingpropertyexception

The Groovy BadLineNumberOnExceptionBugTest.groovy source code

package groovy.bugs

/**
 * Ensure that the correct line information is reported when an exception is thrown.
 * <p>
 * This test covers: <ul>
 * <li>GROOVY-3067
 * <li>GROOVY-2983
 *
 * @author Guillaume Laforge
 */
class BadLineNumberOnExceptionBugTest extends GroovyTestCase {

    void testGroovy3067() {
        assertScript """
            class Foo {
                boolean hello() { true }
            }

            try {
                foo = new Foo()

                if(foo.hello()()) { // line 9
                    println "do"
                    println "do"
                    println "do"
                    println "do"
                }

                assert false
            } catch (MissingMethodException e) {
                def scriptTraceElement = e.stackTrace.find { it.declaringClass.startsWith(GroovyTestCase.TEST_SCRIPT_NAME_PREFIX) }
                assert 9 == scriptTraceElement.lineNumber
            }
        """
    }

    void testGroovy2983() {
        assertScript """
            def foo() {
                integer.metaClass = null // line 3
                integer.metaClass = null
                integer.metaClass = null
                integer.metaClass = null
            }
            
            try {
                foo()

                assert false
            } catch (MissingPropertyException e) {
                def scriptTraceElement = e.stackTrace.find { it.declaringClass.startsWith(GroovyTestCase.TEST_SCRIPT_NAME_PREFIX) }
                assert 3 == scriptTraceElement.lineNumber
            }
        """
    }
}

Other Groovy examples (source code examples)

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

new blog posts

 

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