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

Groovy example source code file (NewExpressionTest.groovy)

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

bob, bob, created, dummybean, dummybean, file, foo, foo, groovytestcase, james, newexpressiontest, newexpressiontest, string

The Groovy NewExpressionTest.groovy source code

package groovy

import org.codehaus.groovy.runtime.DummyBean

class NewExpressionTest extends GroovyTestCase {

    void testNewInstance() {
        def cheese = new String( "hey you hosers" )
        
        assert cheese != null
        
        println(cheese)
    }

    void testNewBeanNoArgs() {
        def bean = new DummyBean()
        assert bean.name == "James"
        assert bean.i == 123
    }

    void testNewBean1Args() {
        def bean = new DummyBean("Bob")
        assert bean.name == "Bob"
        assert bean.i == 123
    }

    void testNewBean2Args() {
        def bean = new DummyBean("Bob", 1707)
        assert bean.name == "Bob"
        assert bean.i == 1707
    }

    void testNewInstanceWithFullyQualifiedName() {
        def bean = new org.codehaus.groovy.runtime.DummyBean("Bob", 1707)
        assert bean.name == "Bob"
        assert bean.i == 1707
    }

    void testNewInstanceWithFullyQualifiedNameNotImported() {
        def bean = new java.io.File("Foo")

        println "Created $bean"

        assert bean != null
    }
    
    void testNewOnMultipleLines() {
        def bean = 
          new
            File
            ("Foo")

        assert bean != null
    }

}

Other Groovy examples (source code examples)

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