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

Groovy example source code file (PrimitiveTypeFieldTest.groovy)

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

groovytestcase, groovytestcase, primitivetypefieldtest, primitivetypefieldtest, short, short

The Groovy PrimitiveTypeFieldTest.groovy source code

package groovy

class PrimitiveTypeFieldTest extends GroovyTestCase {
    private long longField
    private static short shortField

    void setValue() {
        longField = 1
    }

    def getValue() {
        def x = longField
        return x
    }

    void testPrimitiveField() {
        setValue()

        def value = getValue()
        assert value == 1

        assert longField == 1
    }

    void testIntParamBug() {
        assert bugMethod(123) == 246
        assert bugMethod2(123) == 246

        // @todo GROOVY-133
        def closure = {int x-> x * 2 }
        assert closure.call(123) == 246

    }

    int bugMethod(int x) {
        x * 2
    }

    def bugMethod2(int x) {
        x * 2
    }
    void testStaticPrimitiveField() {
        shortField = (Short) 123

        assert shortField == 123
    }

    void testIntLocalVariable() {
        int x = 123
        def y = x + 1
        assert y == 124
    }

    void testLongLocalVariable() {
        long x = 123
        def y = x + 1
        assert y == 124
    }
}

Other Groovy examples (source code examples)

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

new blog posts

 

Copyright 1998-2016 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.