|
Groovy example source code file (StubForJavaTest.groovy)
The Groovy StubForJavaTest.groovy source codepackage 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: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.