How to use method of org.jmock.test.acceptance.ReturningIteratorsAcceptanceTests class

Best Jmock-library code snippet using org.jmock.test.acceptance.ReturningIteratorsAcceptanceTests.

Run Jmock-library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.jmock.test.acceptance;
2
3import java.util.Enumeration;
4import java.util.Iterator;
5
6import junit.framework.TestCase;
7
8import org.jmock.Expectations;
9import org.jmock.Mockery;
10
11public class ReturningIteratorsAcceptanceTests extends TestCase {
12    
13    public interface Iterators {
14        Iterator<String> i();
15        Enumeration<String> e();
16    }
17    
18    Mockery context = new Mockery();
19    Iterators iterators = context.mock(Iterators.class);
20    
21    public void testReturnsIteratorsOverCollectionOfValues() {
22        context.checking(new Expectations() {{
23            allowing (iterators).i(); will(returnIterator("a", "b", "c"));
24        }});
25        
26        assertIteratorOverSequence(iterators.i(), "a", "b", "c");
27
28        // We get a new iterator every time
29        assertIteratorOverSequence(iterators.i(), "a", "b", "c");
30    }
31    
32    public void testReturnsEnumerationsOverCollectionOfValues() {
33        context.checking(new Expectations() {{
34            allowing (iterators).e(); will(returnEnumeration("x", "y", "z"));
35        }});
36        
37        assertEnumerationOverSequence(iterators.e(), "x", "y", "z");
38
39        // We get a new iterator every time
40        assertEnumerationOverSequence(iterators.e(), "x", "y", "z");
41    }
42    
43    private <T> void assertIteratorOverSequence(Iterator<?> e, T... values) {
44        for (int i = 0; i < values.length; i++) {
45            assertEquals("element " + i,
46                         values[i], e.next());
47        }
48        
49        assertTrue("at end", !e.hasNext());
50    }
51    
52    private <T> void assertEnumerationOverSequence(Enumeration<?> e, T... values) {
53        for (int i = 0; i < values.length; i++) {
54            assertEquals("element " + i,
55                         values[i], e.nextElement());
56        }
57        
58        assertTrue("at end", !e.hasMoreElements());
59    }
60
61}
62
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger code on LambdaTest Cloud Grid

Execute automation tests with on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)