|
Groovy example source code file (MockWithZeroRangeTest.groovy)
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: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.