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

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

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 junit.framework.TestCase;
4
5import org.jmock.Expectations;
6import org.jmock.Mockery;
7import org.jmock.api.ExpectationError;
8
9@SuppressWarnings("unused")
10public class ExpectationCountsAcceptanceTests extends TestCase {
11    Mockery context = new Mockery();
12    MockedType mock = context.mock(MockedType.class, "mock");
13    
14    public void testOne() {
15        context.checking(new Expectations() {{
16            oneOf (mock).doSomething();
17        }});
18        
19        assertContextIsNotSatisfied();
20        mock.doSomething();
21        context.assertIsSatisfied();
22        assertAnotherInvocationFailsTheTest();
23    }
24    
25    public void testExpectsExactly() {
26        context.checking(new Expectations() {{
27            exactly(2).of (mock).doSomething();
28        }});
29        
30        assertContextIsNotSatisfied();
31        mock.doSomething();
32        assertContextIsNotSatisfied();
33        mock.doSomething();
34        context.assertIsSatisfied();
35        assertAnotherInvocationFailsTheTest();
36    }
37    
38    public void testExpectsAtLeast() {
39        context.checking(new Expectations() {{
40            atLeast(2).of (mock).doSomething();
41        }});
42        
43        assertContextIsNotSatisfied();
44        mock.doSomething();
45        assertContextIsNotSatisfied();
46        mock.doSomething();
47        context.assertIsSatisfied();
48        
49        for (any_number of : times) {
50            mock.doSomething();
51            context.assertIsSatisfied();
52        }
53    }
54    
55    public void testExpectsAtMost() {
56        context.checking(new Expectations() {{
57            atMost(2).of (mock).doSomething();
58        }});
59        
60        context.assertIsSatisfied();
61        mock.doSomething();
62        context.assertIsSatisfied();
63        mock.doSomething();
64        assertAnotherInvocationFailsTheTest();
65    }
66    
67    public void testExpectsBetween() {
68        context.checking(new Expectations() {{
69            between(2,3).of (mock).doSomething();
70        }});
71        
72        assertContextIsNotSatisfied();
73        mock.doSomething();
74        assertContextIsNotSatisfied();
75        mock.doSomething();
76        context.assertIsSatisfied();
77        mock.doSomething();
78        context.assertIsSatisfied();
79        
80        assertAnotherInvocationFailsTheTest();
81    }
82    
83    public void testAllows() {
84        context.checking(new Expectations() {{
85            allowing (mock).doSomething();
86        }});
87        
88        for (any_number of : times) {
89            mock.doSomething();
90            context.assertIsSatisfied();
91        }
92    }
93    
94    public void testNever() {
95        context.checking(new Expectations() {{
96            never (mock).doSomething();
97        }});
98        
99        context.assertIsSatisfied();
100        assertAnotherInvocationFailsTheTest();
101    }
102    
103    private void assertAnotherInvocationFailsTheTest() {
104        try {
105            mock.doSomething();
106            fail("should have thrown ExpectationError");
107        }
108        catch (ExpectationError e) {
109            // expected
110        }
111    }
112    
113    private void assertContextIsNotSatisfied() {
114        try {
115            context.assertIsSatisfied();
116            fail("should have thrown ExpectationError");
117        }
118        catch (ExpectationError e) {
119            // expected
120        }
121    }
122    
123    private class any_number {}
124    static final any_number[] times = new any_number[4];
125}
126
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)