How to use method of org.jmock.test.unit.lib.action.ReturnEnumerationActionTests class

Best Jmock-library code snippet using org.jmock.test.unit.lib.action.ReturnEnumerationActionTests.

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.unit.lib.action;
2
3import java.util.Arrays;
4import java.util.Collection;
5import java.util.Enumeration;
6
7import junit.framework.TestCase;
8
9import org.hamcrest.StringDescription;
10import org.jmock.api.Action;
11import org.jmock.api.Invocation;
12import org.jmock.lib.action.ReturnEnumerationAction;
13
14public class ReturnEnumerationActionTests extends TestCase {
15    private static final Object[] resultElements = {"0", "1", "2", "3"};
16    
17    public void testReturnsIteratorOverContentsOfCollection() throws Throwable {
18        Collection<Object> collection = collectionOf(resultElements);
19        ReturnEnumerationAction action = new ReturnEnumerationAction(collection);
20        
21        assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);
22    }
23    
24    public void testReturnsNewIteratorOnEachInvocation() throws Throwable {
25        Collection<?> collection = collectionOf(resultElements);
26        ReturnEnumerationAction action = new ReturnEnumerationAction(collection);
27        
28        assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);
29        assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);
30        assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);
31    }
32    
33    public void testCanReturnIteratorOverArray() throws Throwable {
34        ReturnEnumerationAction action = new ReturnEnumerationAction(resultElements);
35        
36        assertEnumerationOverSequence(action.invoke(ANY_INVOCATION), resultElements);
37    }
38    
39    public void testHasAReadableDescription() {
40        Action action = new ReturnEnumerationAction(resultElements);
41        
42        assertEquals("return enumeration over \"0\", \"1\", \"2\", \"3\"", 
43                	 StringDescription.toString(action));
44    }
45    
46    private <T> Collection<T> collectionOf(T... values) {
47        return Arrays.asList(values);
48    }
49    
50    private <T> void assertEnumerationOverSequence(Enumeration<?> e, T[] values) {
51        for (int i = 0; i < values.length; i++) {
52            assertEquals("element " + i,
53                    	 values[i], e.nextElement());
54        }
55    }
56    
57    private static final Invocation ANY_INVOCATION = null;
58}
59
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)