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

Groovy example source code file (StringBufferTest.groovy)

This example Groovy source code file (StringBufferTest.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, string, string, stringbuffer, stringbuffer, stringbuffertest, stringbuffertest

The Groovy StringBufferTest.groovy source code

package groovy

class StringBufferTest extends GroovyTestCase {
    void testSize() {
        def x = new StringBuffer()
        assert x.size() == x.length()
        x = new StringBuffer('some text')
        assert x.size() == x.length()

    void testPutAt(){
        def buf = new StringBuffer('0123')
        buf[1..2] = 'xx'
        assert '0xx3' == buf.toString()  , 'replace with String'
        buf = new StringBuffer('0123')
        buf[1..2] = 99
        assert '0993' == buf.toString()  , 'replace with obj.toString()'
        buf = new StringBuffer('0123')
        buf[0..<0] = 'xx'
        assert 'xx0123' == buf.toString(), 'border case left'
        buf = new StringBuffer('0123')
        buf[4..4] = 'xx'
        println buf.toString()
        assert '0123xx' == buf.toString(), 'border case right'
        // more weird Ranges already tested in ListTest

Other Groovy examples (source code examples)

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