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

Groovy example source code file (BooleanBug.groovy)

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

booleanbean, booleanbean, booleanbug, booleanbug, groovytestcase, groovytestcase, string, string

The Groovy BooleanBug.groovy source code

package groovy.bugs

/**
 * @version $Revision: 21290 $
 */
class BooleanBug extends GroovyTestCase {
    
    void testBug() {
        def x = new BooleanBean(name:'James', foo:true)
        def y = new BooleanBean(name:'Bob', foo:false)

        assert x.foo
        assert ! y.foo
        y.foo = true
        assert y.foo
    }
    
    void testBug2() {
        BooleanBean bean = new BooleanBean(name:'Gromit', foo:false)
        def value = isApplicableTo(bean)
        assert value
    }
    
    public boolean isApplicableTo(BooleanBean field) {
        return !field.isFoo();
    }
    
    public testBooleanAsMethodArgumentFromCompare() {
        assertScript """
            def foo(x){x}
            def i = 0
            assert foo(i==0)==true
        """
    }

}

class BooleanBean {
    String name
    boolean foo
}

Other Groovy examples (source code examples)

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

new blog posts

 

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