How to use ActionSequenceTests class of org.jmock.test.unit.lib.action package

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

Run Jmock-library automation tests on LambdaTest cloud grid

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

copy
1/*  Copyright (c) 2000-20047 jMock.org
2 */
3package org.jmock.test.unit.lib.action;
4
5import java.lang.reflect.Method;
6
7import junit.framework.TestCase;
8
9import org.hamcrest.StringDescription;
10import org.jmock.api.Action;
11import org.jmock.api.ExpectationError;
12import org.jmock.api.Invocation;
13import org.jmock.lib.action.ActionSequence;
14import org.jmock.test.unit.support.AssertThat;
15import org.jmock.test.unit.support.MethodFactory;
16import org.jmock.test.unit.support.MockAction;
17
18
19public class ActionSequenceTests extends TestCase {
20    private Object invokedObject = "INVOKED_OBJECT";
21    private MethodFactory methodFactory = new MethodFactory();
22    private Method invokedMethod = methodFactory.newMethodReturning(String.class);
23    private Invocation invocation = new Invocation(invokedObject, invokedMethod);
24    
25    
26    @SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!
27    public void testInvokesActionsInOrder() throws Throwable {
28    	final int sequenceLength = 4;
29    	
30        MockAction[] actions = new MockAction[sequenceLength];        
31        for (int i = 0; i < sequenceLength; i++) {
32            actions[i] = new MockAction();
33            actions[i].result = "RESULT-" + i;
34            if (i > 0) actions[i].previous = actions[i-1];
35        }
36        
37        Invocation[] invocations = new Invocation[actions.length];
38        for (int i = 0; i < sequenceLength; i++) {
39        	invocations[i] = new Invocation(invokedObject, invokedMethod);
40        }
41        
42        ActionSequence sequence = new ActionSequence((Action[])actions);
43        
44        for (int current = 0; current < actions.length; current++) {
45            reset(actions);
46            actions[current].expectInvoke = true;
47            actions[current].expectedInvocation = invocation;
48            
49            Object result = sequence.invoke(invocation);
50            
51			assertSame("should be result of actions[" + current + "]",
52                         actions[current].result, result);
53        }
54    }
55    
56    @SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!
57    public void testFailsIfInvokedMoreTimesThanThereAreActionsInTheSequence() throws Throwable {
58        MockAction[] actions = new MockAction[]{new MockAction(), new MockAction()};
59        ActionSequence sequence = new ActionSequence((Action[])actions);
60        
61        for (int i = 0; i < actions.length; i++) sequence.invoke(invocation);
62        
63        try {
64            sequence.invoke(invocation);
65            fail("should have thrown IllegalStateException");
66        }
67        catch (ExpectationError ex) {
68            AssertThat.stringIncludes("should describe error",
69                "no more actions", ex.getMessage());
70            return;
71        }
72    }
73    
74    @SuppressWarnings("cast") // Eclipse gives warning if there is a cast and if there is not!
75    public void testDescribesItselfAsSequenceOfActions() throws Throwable {
76        MockAction[] actions = new MockAction[]{new MockAction(), new MockAction()};
77        ActionSequence sequence = new ActionSequence((Action[])actions);
78        
79        String sequenceDescription = StringDescription.toString(sequence);
80
81        for (int i = 0; i < actions.length; i++) {
82            AssertThat.stringIncludes("should include action " + i,
83                actions[i].descriptionText, sequenceDescription);
84
85            if (i > 0) {
86                int h = i - 1;
87                
88                assertTrue("description of action " + h + " should be before that of action " + i,
89                           sequenceDescription.indexOf(actions[h].descriptionText) <
90                           sequenceDescription.indexOf(actions[i].descriptionText));
91            }
92        }
93    }
94
95    private void reset( MockAction[] actions ) {
96        for (int i = 0; i < actions.length; i++) {
97            actions[i].expectInvoke = false;
98        }
99    }
100}
101
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

...Most popular Stackoverflow questions on ActionSequenceTests

    No relevant questions found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)