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

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

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.hamcrest.StringDescription;
6import org.jmock.Expectations;
7import org.jmock.Mockery;
8import org.jmock.Sequence;
9import org.jmock.api.ExpectationError;
10import org.jmock.test.unit.support.AssertThat;
11
12public class SequenceAcceptanceTests extends TestCase {
13    Mockery context = new Mockery();
14    MockedType mock = context.mock(MockedType.class, "mock");
15    
16    public void testCanConstrainInvocationsToOccurInOrder() {
17        final Sequence s = context.sequence("s");
18        
19        context.checking(new Expectations() {{
20            oneOf (mock).method1(); inSequence(s);
21            oneOf (mock).method2(); inSequence(s);
22        }});
23        
24        try {
25            mock.method2();
26            fail("should have thrown ExpectationError");
27        }
28        catch (ExpectationError e) {
29            // expected
30        }
31    }
32    
33    public void testAllowsInvocationsInSequence() {
34        final Sequence s = context.sequence("s");
35        
36        context.checking(new Expectations() {{
37            oneOf (mock).method1(); inSequence(s);
38            oneOf (mock).method2(); inSequence(s);
39        }});
40        
41        mock.method1();
42        mock.method2();
43    }
44    
45    public void testCanSkipAllowedInvocationsInSequence() {
46        final Sequence s = context.sequence("s");
47        
48        context.checking(new Expectations() {{
49            oneOf (mock).method1(); inSequence(s);
50            allowing (mock).method2(); inSequence(s);
51            oneOf (mock).method3(); inSequence(s);
52        }});
53        
54        mock.method1();
55        mock.method3();
56    }
57    
58    public void testSequencesAreIndependentOfOneAnother() {
59        final Sequence s = context.sequence("s");
60        final Sequence t = context.sequence("t");
61        
62        context.checking(new Expectations() {{
63            oneOf (mock).method1(); inSequence(s);
64            oneOf (mock).method2(); inSequence(s);
65            
66            oneOf (mock).method3(); inSequence(t);
67            oneOf (mock).method4(); inSequence(t);
68        }});
69        
70        mock.method1();
71        mock.method3();
72        mock.method2();
73        mock.method4();
74    }
75    
76    public void testExpectationIncludesSequenceInDescription() {
77        final Sequence s = context.sequence("s");
78        
79        context.checking(new Expectations() {{
80            oneOf (mock).method1(); inSequence(s);
81        }});
82        
83        try {
84            mock.method2();
85            fail("should have thrown ExpectationError");
86        }
87        catch (ExpectationError e) {
88            AssertThat.stringIncludes("error message", "in sequence s", StringDescription.toString(e));
89        }
90    }
91    
92    public void testAnExpectationCanBeInMoreThanOneSequence() {
93        final Sequence s = context.sequence("s");
94        final Sequence t = context.sequence("t");
95        
96        context.checking(new Expectations() {{
97            oneOf (mock).method1(); inSequence(s);
98            oneOf (mock).method2(); inSequence(t);
99            oneOf (mock).method3(); inSequence(s); inSequence(t);
100        }});
101        
102        mock.method1();
103    
104        try {
105            mock.method3();
106            fail("should have thrown ExpectationError");
107        }
108        catch (ExpectationError e) {
109            AssertThat.stringIncludes("error message", "in sequence s", StringDescription.toString(e));
110            AssertThat.stringIncludes("error message", "in sequence t", StringDescription.toString(e));
111        }
112    }
113
114    // See issue JMOCK-142
115    public void testHasShortcutForIncludingExpectationInMultipleSequences() {
116        final Sequence s = context.sequence("s");
117        final Sequence t = context.sequence("t");
118        
119        context.checking(new Expectations() {{
120            oneOf (mock).method1(); inSequence(s);
121            oneOf (mock).method2(); inSequence(t);
122            oneOf (mock).method3(); inSequences(s, t);
123        }});
124        
125        mock.method1();
126    
127        try {
128            mock.method3();
129            fail("should have thrown ExpectationError");
130        }
131        catch (ExpectationError e) {
132            AssertThat.stringIncludes("error message", "in sequence s", StringDescription.toString(e));
133            AssertThat.stringIncludes("error message", "in sequence t", StringDescription.toString(e));
134        }
135    }
136}
137
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)