use of java.util.Iterator in project groovy-core by groovy.
the class NumberRangeTest method testStepByOneWithClosure.
/**
* Tests stepping through a range with a closure.
*/
public void testStepByOneWithClosure() {
final List callLog = new ArrayList();
final Closure closure = new RecordingClosure(callLog);
final Range range = createRange(1, 5);
range.step(1, closure);
assertEquals("wrong number of calls to closure", 5, callLog.size());
final Iterator iter = callLog.iterator();
for (int i = 1; i <= 5; i++) {
assertEquals("wrong argument passed to closure", createValue(i), iter.next());
}
}
use of java.util.Iterator in project groovy-core by groovy.
the class NumberRangeTest method testRemoveFromIterator.
/**
* Tests removing an element from the range using an iterator (not supported).
*/
public void testRemoveFromIterator() {
final Range range = createRange(1, 5);
try {
final Iterator iter = range.iterator();
iter.remove();
fail("successfully removed an element using an iterator");
} catch (UnsupportedOperationException e) {
assertTrue("expected exception thrown", true);
}
}
use of java.util.Iterator in project groovy-core by groovy.
the class NumberRangeTest method testStepByTwoWithClosure.
/**
* Tests stepping through a range by two with a closure.
*/
public void testStepByTwoWithClosure() {
final List callLog = new ArrayList();
final Closure closure = new RecordingClosure(callLog);
final Range range = createRange(0, 4);
range.step(2, closure);
assertEquals("wrong number of calls to closure", 3, callLog.size());
final Iterator iter = callLog.iterator();
for (int i = 0; i <= 4; i += 2) {
assertEquals("wrong argument passed to closure", createValue(i), iter.next());
}
}
use of java.util.Iterator in project groovy-core by groovy.
the class NumberRangeTest method testNegativeReverseStepByOneWithClosure.
/**
* Tests stepping backwards through a reversed range with a closure.
*/
public void testNegativeReverseStepByOneWithClosure() {
final List callLog = new ArrayList();
final Closure closure = new RecordingClosure(callLog);
final Range range = createRange(5, 1);
range.step(-1, closure);
assertEquals("wrong number of calls to closure", 5, callLog.size());
final Iterator iter = callLog.iterator();
for (int i = 1; i <= 5; i++) {
assertEquals("wrong argument passed to closure", createValue(i), iter.next());
}
}
use of java.util.Iterator in project groovy-core by groovy.
the class NumberRangeTest method testStepByOne.
/**
* Tests stepping through a range by one.
*/
public void testStepByOne() {
final Range range = createRange(1, 5);
final List result = range.step(1);
assertEquals("wrong number of calls", 5, result.size());
final Iterator iter = result.iterator();
for (int i = 1; i <= 5; i++) {
assertEquals("incorrect value in result", createValue(i), iter.next());
}
}
Aggregations