|
Groovy example source code file (StubForJavaTest.groovy)
The Groovy StubForJavaTest.groovy source code
package groovy.mock.interceptor
class StubForJavaTest extends GroovyTestCase {
void testIterator() {
// ProxyGenerator.INSTANCE.debug = true
def iteratorContext = new StubFor(Iterator)
iteratorContext.demand.hasNext() { true }
iteratorContext.demand.hasNext() { false }
iteratorContext.demand.hasNext() { true }
iteratorContext.demand.hasNext() { false }
iteratorContext.ignore('dump')
iteratorContext.ignore('getMetaClass')
def iterator = iteratorContext.proxyDelegateInstance()
def counter = new IteratorCounter()
assert counter.count(iterator) == 1
assert counter.count(iterator) == 1
iteratorContext.verify(iterator)
}
void testString() {
ProxyGenerator.INSTANCE.debug = false
def stringContext = new StubFor(String)
stringContext.demand.startsWith(2) { String arg -> arg == "wiz" }
stringContext.demand.endsWith(2..2) { String arg -> arg == "foo" }
def s = stringContext.proxyDelegateInstance()
assert !s.endsWith("bar")
assert s.endsWith("foo")
assert !s.startsWith("bar")
assert s.startsWith("wiz")
stringContext.verify(s)
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy StubForJavaTest.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.