How to use method of org.easymock.tests.UsageRangeTest class

Best Easymock code snippet using org.easymock.tests.UsageRangeTest.

Run Easymock automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Copyright (c) 2001-2007 OFFIS, Tammo Freese.
3 * This program is made available under the terms of the MIT License.
4 */
5package org.easymock.tests;
6
7import static org.junit.Assert.*;
8
9import java.util.Iterator;
10
11import org.easymock.MockControl;
12import org.easymock.internal.Range;
13import org.junit.Before;
14import org.junit.Test;
15
16public class UsageRangeTest {
17
18    private Iterator mock;
19
20    private MockControl<Iterator> control;
21
22    @Before
23    public void setup() {
24        control = MockControl.createStrictControl(Iterator.class);
25        mock = control.getMock();
26    }
27
28    @Test
29    public void zeroOrMoreNoCalls() {
30        mock.hasNext();
31        control.setReturnValue(false, MockControl.ZERO_OR_MORE);
32        control.replay();
33        control.verify();
34    }
35
36    @Test
37    public void zeroOrMoreOneCall() {
38        mock.hasNext();
39        control.setReturnValue(false, MockControl.ZERO_OR_MORE);
40        control.replay();
41        assertFalse(mock.hasNext());
42        control.verify();
43    }
44
45    @Test
46    public void zeroOrMoreThreeCalls() {
47        mock.hasNext();
48        control.setReturnValue(false, MockControl.ZERO_OR_MORE);
49        control.replay();
50        assertFalse(mock.hasNext());
51        assertFalse(mock.hasNext());
52        assertFalse(mock.hasNext());
53        control.verify();
54    }
55
56    @Test
57    public void combination() {
58        mock.hasNext();
59        control.setReturnValue(true, MockControl.ONE_OR_MORE);
60        mock.next();
61        control.setReturnValue("1");
62
63        mock.hasNext();
64        control.setReturnValue(true, MockControl.ONE_OR_MORE);
65        mock.next();
66        control.setReturnValue("2");
67
68        mock.hasNext();
69        control.setReturnValue(false, MockControl.ONE_OR_MORE);
70
71        control.replay();
72
73        assertTrue(mock.hasNext());
74        assertTrue(mock.hasNext());
75        assertTrue(mock.hasNext());
76
77        assertEquals("1", mock.next());
78
79        try {
80            mock.next();
81            fail();
82        } catch (AssertionError expected) {
83        }
84
85        assertTrue(mock.hasNext());
86
87        assertEquals("2", mock.next());
88
89        assertFalse(mock.hasNext());
90
91        control.verify();
92
93    }
94
95    @Test
96    public void withIllegalOwnRange() {
97        mock.hasNext();
98        try {
99            control.setReturnValue(true, new Range(2, 7));
100        } catch (IllegalArgumentException e) {
101            assertEquals("Unexpected Range", e.getMessage());
102        }
103    }
104}
105
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)