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

Groovy example source code file (MockWithZeroRangeTest.groovy)

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

foo, foo, groovytestcase, groovytestcase, mockfor, mockfor, mockforwithzerorangetest, mockforwithzerorangetest

The Groovy MockWithZeroRangeTest.groovy source code

package groovy.mock.interceptor

import groovy.mock.interceptor.MockFor
import junit.framework.AssertionFailedError

class MockForWithZeroRangeTest extends GroovyTestCase {
    void testMockWithZeroRangeDemandAndNoCall() {
        MockFor mockForFoo = new MockFor(Foo)
        mockForFoo.demand.createBar(0..0) {}
        mockForFoo.use {
            println 'Foo is not called'
        }
        // We should get here and the test should pass.
    }

    void testMockWithZeroRangeDemandAndOneCall() {
        MockFor mockForFoo = new MockFor(Foo)
        mockForFoo.demand.createBar(0..0) {}
        shouldFail(AssertionFailedError) {
            mockForFoo.use {
                new Foo().createBar()
            }
        }
    }
}


class Foo {
    def createBar() {
        println 'bar'
    }
}

Other Groovy examples (source code examples)

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

new blog posts

 

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