|
Groovy example source code file (MockForJavaTest.groovy)
The Groovy MockForJavaTest.groovy source codepackage groovy.mock.interceptor class MockForJavaTest extends GroovyTestCase { void testIterator() { def iteratorContext = new MockFor(Iterator) iteratorContext.demand.hasNext() { true } iteratorContext.demand.hasNext() { true } iteratorContext.demand.hasNext() { false } def iterator = iteratorContext.proxyDelegateInstance() iteratorContext.demand.next() { "foo" } def iterator2 = iteratorContext.proxyDelegateInstance() assert new IteratorCounter().count(iterator2) == 2 assert iterator2.next() == "foo" iteratorContext.verify(iterator2) assert new IteratorCounter().count(iterator) == 2 iteratorContext.verify(iterator) iteratorContext = new MockFor(Iterator) iteratorContext.demand.hasNext(7..7) { true } iteratorContext.demand.hasNext() { false } def iterator3 = iteratorContext.proxyDelegateInstance() assert new IteratorCounter().count(iterator3) == 7 iteratorContext.verify(iterator3) } void testString() { def stringContext = new MockFor(String) stringContext.demand.endsWith(2..2) { String arg -> arg == "foo" } def s = stringContext.proxyDelegateInstance() assert !s.endsWith("bar") assert s.endsWith("foo") stringContext.verify(s) } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy MockForJavaTest.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.