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

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

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.ArrayList;
4import java.util.Collection;
5
6import junit.framework.TestCase;
7
8import org.hamcrest.Description;
9import org.jmock.Expectations;
10import org.jmock.Mockery;
11import org.jmock.api.Action;
12import org.jmock.api.Invocation;
13
14public class DoAllAcceptanceTests extends TestCase {
15    public interface Collector {
16        void addThingsTo(Collection<String> collection);
17    }
18    
19    Mockery context = new Mockery();
20    Collector collector = context.mock(Collector.class);
21    
22    
23    public void testCanSpecifyMultipleStubsForOneInvocation() {
24        final ArrayList<String> list = new ArrayList<String>();
25        
26        context.checking(new Expectations() {{
27            exactly(1).of (collector).addThingsTo(with(same(list)));
28            	will(doAll(addElement("1"), 
29                           addElement("2"), 
30                           addElement("3"), 
31                           addElement("4")));
32        }});
33        
34        collector.addThingsTo(list);
35        
36        assertEquals("list length", 4, list.size());
37        for (int i = 0; i < list.size(); i++) {
38            assertEquals("element "+(i+1), Integer.toString(i+1), list.get(i));
39        }
40    }
41    
42    private Action addElement(String newElement) {
43        return new AddElementAction(newElement);
44    }
45    
46    public static class AddElementAction implements Action {
47        private final String newElement;
48
49        public AddElementAction(String newElement) {
50            this.newElement = newElement;
51        }
52
53        @SuppressWarnings("unchecked")
54        public Object invoke(Invocation invocation) throws Throwable {
55            ((Collection<Object>)invocation.getParameter(0)).add(newElement);
56            return null;
57        }
58        
59        public void describeTo(Description description) {
60            throw new UnsupportedOperationException("AddElementStub.describeTo not implemented");
61        }
62    }
63}
64
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)