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

Groovy example source code file (PlusEqualsTest.groovy)

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

character, character, groovytestcase, plusequalstest, plusequalstest, sortedset, sortedset, treeset, treeset

The Groovy PlusEqualsTest.groovy source code

package groovy

class PlusEqualsTest extends GroovyTestCase {

    void testIntegerPlusEquals() {
        def x = 1
        def y = 2
        x += y
        
        assert x == 3
        
        y += 10
        
        assert y == 12
    }

    void testCharacterPlusEquals() {
        Character x = 1
        Character y = 2
        x += y
        
        assert x == 3
        
        y += 10
        
        assert y == 12
    }
    
    void testNumberPlusEquals() {
        def x = 1.2
        def y = 2
        x += y
        
        assert x == 3.2
        
        y += 10.1
        
        assert y == 12.1
    }
    
    void testStringPlusEquals() {
        def x = "bbc"
        def y = 2
        x += y
        
        assert x == "bbc2"
        
        def foo = "nice cheese"
        foo += " gromit"
        
        assert foo == "nice cheese gromit"
    }

    void testSortedSetPlusEquals() {
        def sortedSet = new TreeSet()
        sortedSet += 'abc'
        assertTrue 'sortedSet should have been a SortedSet',
                   sortedSet instanceof SortedSet
        sortedSet += ['def', 'ghi']
        assertTrue 'sortedSet should have been a SortedSet',
                   sortedSet instanceof SortedSet
        assertEquals 'sortedSet had wrong number of elements',
                     3, sortedSet.size()
    }
}

Other Groovy examples (source code examples)

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