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

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

Run Easymock automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Copyright 2001-2021 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.easymock.tests;
17
18import static org.easymock.EasyMock.*;
19import static org.junit.Assert.*;
20
21import org.junit.Before;
22import org.junit.Test;
23
24/**
25 * @author OFFIS, Tammo Freese
26 */
27public class UsageExpectAndReturnTest {
28
29    private IMethods mock;
30
31    @Before
32    public void setup() {
33        mock = createMock(IMethods.class);
34    }
35
36    @Test
37    public void booleanType() {
38        expect(mock.booleanReturningMethod(4)).andReturn(true);
39        replay(mock);
40        assertTrue(mock.booleanReturningMethod(4));
41        verify(mock);
42    }
43
44    @Test
45    public void longType() {
46        expect(mock.longReturningMethod(4)).andReturn(12L);
47        replay(mock);
48        assertEquals(12, mock.longReturningMethod(4));
49        verify(mock);
50    }
51
52    @Test
53    public void floatType() {
54        expect(mock.floatReturningMethod(4)).andReturn(12f);
55        replay(mock);
56        assertEquals(12f, mock.floatReturningMethod(4), 0f);
57        verify(mock);
58    }
59
60    @Test
61    public void doubleType() {
62        expect(mock.doubleReturningMethod(4)).andReturn(12.0);
63        replay(mock);
64        assertEquals(12.0, mock.doubleReturningMethod(4), 0.0);
65        verify(mock);
66    }
67
68    @Test
69    public void object() {
70        expect(mock.objectReturningMethod(4)).andReturn("12");
71        replay(mock);
72        assertEquals("12", mock.objectReturningMethod(4));
73        verify(mock);
74    }
75
76    @Test
77    public void booleanAndRange() {
78        expect(mock.booleanReturningMethod(4)).andReturn(true).once();
79        replay(mock);
80        assertTrue(mock.booleanReturningMethod(4));
81        verify(mock);
82    }
83
84    @Test
85    public void longAndRange() {
86        expect(mock.longReturningMethod(4)).andReturn(12L).once();
87        replay(mock);
88        assertEquals(12, mock.longReturningMethod(4));
89        verify(mock);
90    }
91
92    @Test
93    public void floatAndRange() {
94        expect(mock.floatReturningMethod(4)).andReturn(12f).once();
95        replay(mock);
96        assertEquals(12f, mock.floatReturningMethod(4), 0f);
97        verify(mock);
98    }
99
100    @Test
101    public void doubleAndRange() {
102        expect(mock.doubleReturningMethod(4)).andReturn(12.0).once();
103        replay(mock);
104        assertEquals(12.0, mock.doubleReturningMethod(4), 0.0);
105        verify(mock);
106    }
107
108    @Test
109    public void objectAndRange() {
110        expect(mock.objectReturningMethod(4)).andReturn("12").once();
111        replay(mock);
112        assertEquals("12", mock.objectReturningMethod(4));
113        verify(mock);
114    }
115
116    @Test
117    public void booleanAndCount() {
118        expect(mock.booleanReturningMethod(4)).andReturn(true).times(2);
119        replay(mock);
120        assertTrue(mock.booleanReturningMethod(4));
121        assertTrue(mock.booleanReturningMethod(4));
122        verify(mock);
123    }
124
125    @Test
126    public void longAndCount() {
127        expect(mock.longReturningMethod(4)).andReturn(12L).times(2);
128        replay(mock);
129        assertEquals(12, mock.longReturningMethod(4));
130        assertEquals(12, mock.longReturningMethod(4));
131        verify(mock);
132    }
133
134    @Test
135    public void floatAndCount() {
136        expect(mock.floatReturningMethod(4)).andReturn(12f).times(2);
137        replay(mock);
138        assertEquals(12f, mock.floatReturningMethod(4), 0f);
139        assertEquals(12f, mock.floatReturningMethod(4), 0f);
140        verify(mock);
141    }
142
143    @Test
144    public void doubleAndCount() {
145        expect(mock.doubleReturningMethod(4)).andReturn(12.0).times(2);
146        replay(mock);
147        assertEquals(12.0, mock.doubleReturningMethod(4), 0.0);
148        assertEquals(12.0, mock.doubleReturningMethod(4), 0.0);
149        verify(mock);
150    }
151
152    @Test
153    public void objectAndCount() {
154        expect(mock.objectReturningMethod(4)).andReturn("12").times(2);
155        replay(mock);
156        assertEquals("12", mock.objectReturningMethod(4));
157        assertEquals("12", mock.objectReturningMethod(4));
158        verify(mock);
159    }
160
161    @Test
162    public void booleanAndMinMax() {
163        expect(mock.booleanReturningMethod(4)).andReturn(true).times(2, 3);
164        replay(mock);
165        assertTrue(mock.booleanReturningMethod(4));
166        assertTrue(mock.booleanReturningMethod(4));
167        verify(mock);
168    }
169
170    @Test
171    public void longAndMinMax() {
172        expect(mock.longReturningMethod(4)).andReturn(12L).times(2, 3);
173        replay(mock);
174        assertEquals(12, mock.longReturningMethod(4));
175        assertEquals(12, mock.longReturningMethod(4));
176        verify(mock);
177    }
178
179    @Test
180    public void floatAndMinMax() {
181        expect(mock.floatReturningMethod(4)).andReturn(12f).times(2, 3);
182        replay(mock);
183        assertEquals(12f, mock.floatReturningMethod(4), 0f);
184        assertEquals(12f, mock.floatReturningMethod(4), 0f);
185        verify(mock);
186    }
187
188    @Test
189    public void doubleAndMinMax() {
190        expect(mock.doubleReturningMethod(4)).andReturn(12.0).times(2, 3);
191        replay(mock);
192        assertEquals(12.0, mock.doubleReturningMethod(4), 0.0);
193        assertEquals(12.0, mock.doubleReturningMethod(4), 0.0);
194        verify(mock);
195    }
196
197    @Test
198    public void objectAndMinMax() {
199        expect(mock.objectReturningMethod(4)).andReturn("12").times(2, 3);
200        replay(mock);
201        assertEquals("12", mock.objectReturningMethod(4));
202        assertEquals("12", mock.objectReturningMethod(4));
203        verify(mock);
204    }
205}
206
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)