How to use method of org.jmock.test.unit.internal.InvocationDispatcherTests class

Best Jmock-library code snippet using org.jmock.test.unit.internal.InvocationDispatcherTests.

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.internal;
2
3import junit.framework.TestCase;
4
5import org.jmock.api.ExpectationError;
6import org.jmock.api.Invocation;
7import org.jmock.internal.InvocationDispatcher;
8import org.jmock.test.unit.support.MethodFactory;
9import org.jmock.test.unit.support.MockExpectation;
10
11public class InvocationDispatcherTests extends TestCase {
12	MethodFactory methodFactory = new MethodFactory();
13	Invocation invocation = new Invocation(
14	    "invokedObject", 
15		methodFactory.newMethod("invokedMethod"),
16		Invocation.NO_PARAMETERS);
17	
18	static final boolean NOT_RELEVANT = true;
19	
20    public void testInvokesFirstMatchingExpectationInGroup() throws Throwable {
21        MockExpectation expectation1 = new MockExpectation(false, NOT_RELEVANT, NOT_RELEVANT);
22        MockExpectation expectation2 = new MockExpectation(true, NOT_RELEVANT, NOT_RELEVANT);
23        MockExpectation expectation3 = new MockExpectation(true, NOT_RELEVANT, NOT_RELEVANT);
24        
25        InvocationDispatcher dispatcher = new InvocationDispatcher();
26        dispatcher.add(expectation1);
27        dispatcher.add(expectation2);
28        dispatcher.add(expectation3);
29        
30        expectation1.shouldNotBeInvoked();
31        expectation2.shouldBeInvokedWith(invocation);
32        expectation3.shouldNotBeInvoked();
33        
34        dispatcher.dispatch(invocation);
35        
36        assertTrue("expectation2 should have been invoked", 
37                   expectation2.wasInvoked);
38    }
39
40    public void testThrowsExpectationErrorIfNoExpectationsMatchAnInvocation() throws Throwable {
41        MockExpectation expectation1 = new MockExpectation(false, NOT_RELEVANT, NOT_RELEVANT);
42        MockExpectation expectation2 = new MockExpectation(false, NOT_RELEVANT, NOT_RELEVANT);
43        MockExpectation expectation3 = new MockExpectation(false, NOT_RELEVANT, NOT_RELEVANT);
44        
45        InvocationDispatcher dispatcher = new InvocationDispatcher();
46        dispatcher.add(expectation1);
47        dispatcher.add(expectation2);
48        dispatcher.add(expectation3);
49        
50        expectation1.shouldNotBeInvoked();
51        expectation2.shouldNotBeInvoked();
52        expectation3.shouldNotBeInvoked();
53        
54        try {
55            dispatcher.dispatch(invocation);
56            fail("should have thrown ExpectationError");
57        }
58        catch (ExpectationError e) {
59            // expected
60        }
61    }
62
63    public void testIsSatisfiedOnlyIfAllExpectationsAreSatisfied() {
64        InvocationDispatcher dispatcherAll = new InvocationDispatcher();
65        dispatcherAll.add(new MockExpectation(NOT_RELEVANT, true, NOT_RELEVANT));
66        dispatcherAll.add(new MockExpectation(NOT_RELEVANT, true, NOT_RELEVANT));
67        assertTrue("should be satisfied if all expectations are satisfied",
68                   dispatcherAll.isSatisfied());
69        
70        InvocationDispatcher dispatcher1 = new InvocationDispatcher();
71        dispatcher1.add(new MockExpectation(NOT_RELEVANT, true, NOT_RELEVANT));
72        dispatcher1.add(new MockExpectation(NOT_RELEVANT, false, NOT_RELEVANT));
73        assertFalse("should not be satisfied if first expectation is not satisfied",
74                   dispatcher1.isSatisfied());
75        
76        InvocationDispatcher dispatcher2 = new InvocationDispatcher();
77        dispatcher2.add(new MockExpectation(NOT_RELEVANT, false, NOT_RELEVANT));
78        dispatcher2.add(new MockExpectation(NOT_RELEVANT, true, NOT_RELEVANT));
79        assertFalse("should not be satisfied if second expectation is not satisfied",
80                   dispatcher2.isSatisfied());
81        
82        InvocationDispatcher dispatcherNone = new InvocationDispatcher();
83        dispatcherNone.add(new MockExpectation(NOT_RELEVANT, false, NOT_RELEVANT));
84        dispatcherNone.add(new MockExpectation(NOT_RELEVANT, true, NOT_RELEVANT));
85        assertFalse("should not be satisfied if no expectations are satisfied",
86                    dispatcherNone.isSatisfied());
87    }
88}
89
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
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)