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

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

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 UsageExpectAndThrowTest {
28
29    private IMethods mock;
30
31    private static RuntimeException EXCEPTION = new RuntimeException();
32
33    @Before
34    public void setup() {
35        mock = createMock(IMethods.class);
36    }
37
38    @Test
39    public void booleanType() {
40        expect(mock.booleanReturningMethod(4)).andThrow(EXCEPTION);
41        replay(mock);
42        try {
43            mock.booleanReturningMethod(4);
44            fail();
45        } catch (RuntimeException exception) {
46            assertSame(EXCEPTION, exception);
47        }
48        verify(mock);
49    }
50
51    @Test
52    public void longType() {
53        expect(mock.longReturningMethod(4)).andThrow(EXCEPTION);
54        replay(mock);
55        try {
56            mock.longReturningMethod(4);
57            fail();
58        } catch (RuntimeException exception) {
59            assertSame(EXCEPTION, exception);
60        }
61        verify(mock);
62    }
63
64    @Test
65    public void floatType() {
66        expect(mock.floatReturningMethod(4)).andThrow(EXCEPTION);
67        replay(mock);
68        try {
69            mock.floatReturningMethod(4);
70            fail();
71        } catch (RuntimeException exception) {
72            assertSame(EXCEPTION, exception);
73        }
74        verify(mock);
75    }
76
77    @Test
78    public void doubleType() {
79        expect(mock.doubleReturningMethod(4)).andThrow(EXCEPTION);
80        replay(mock);
81        try {
82            mock.doubleReturningMethod(4);
83            fail();
84        } catch (RuntimeException exception) {
85            assertSame(EXCEPTION, exception);
86        }
87        verify(mock);
88    }
89
90    @Test
91    public void object() {
92        expect(mock.objectReturningMethod(4)).andThrow(EXCEPTION);
93        replay(mock);
94        try {
95            mock.objectReturningMethod(4);
96            fail();
97        } catch (RuntimeException exception) {
98            assertSame(EXCEPTION, exception);
99        }
100        verify(mock);
101    }
102
103    @Test
104    public void booleanAndRange() {
105        expect(mock.booleanReturningMethod(4)).andThrow(EXCEPTION).once();
106        replay(mock);
107        try {
108            mock.booleanReturningMethod(4);
109            fail();
110        } catch (RuntimeException exception) {
111            assertSame(EXCEPTION, exception);
112        }
113        verify(mock);
114    }
115
116    @Test
117    public void longAndRange() {
118        expect(mock.longReturningMethod(4)).andThrow(EXCEPTION).once();
119        replay(mock);
120        try {
121            mock.longReturningMethod(4);
122            fail();
123        } catch (RuntimeException exception) {
124            assertSame(EXCEPTION, exception);
125        }
126        verify(mock);
127    }
128
129    @Test
130    public void floatAndRange() {
131        expect(mock.floatReturningMethod(4)).andThrow(EXCEPTION).once();
132        replay(mock);
133        try {
134            mock.floatReturningMethod(4);
135            fail();
136        } catch (RuntimeException exception) {
137            assertSame(EXCEPTION, exception);
138        }
139        verify(mock);
140    }
141
142    @Test
143    public void doubleAndRange() {
144        expect(mock.doubleReturningMethod(4)).andThrow(EXCEPTION).once();
145        replay(mock);
146        try {
147            mock.doubleReturningMethod(4);
148            fail();
149        } catch (RuntimeException exception) {
150            assertSame(EXCEPTION, exception);
151        }
152        verify(mock);
153    }
154
155    @Test
156    public void objectAndRange() {
157        expect(mock.objectReturningMethod(4)).andThrow(EXCEPTION).once();
158        replay(mock);
159        try {
160            mock.objectReturningMethod(4);
161            fail();
162        } catch (RuntimeException exception) {
163            assertSame(EXCEPTION, exception);
164        }
165        verify(mock);
166    }
167
168    @Test
169    public void booleanAndCount() {
170        expect(mock.booleanReturningMethod(4)).andThrow(EXCEPTION).times(2);
171        replay(mock);
172        try {
173            mock.booleanReturningMethod(4);
174            fail();
175        } catch (RuntimeException exception) {
176            assertSame(EXCEPTION, exception);
177        }
178        try {
179            mock.booleanReturningMethod(4);
180            fail();
181        } catch (RuntimeException exception) {
182            assertSame(EXCEPTION, exception);
183        }
184        verify(mock);
185    }
186
187    @Test
188    public void longAndCount() {
189        expect(mock.longReturningMethod(4)).andThrow(EXCEPTION).times(2);
190        replay(mock);
191        try {
192            mock.longReturningMethod(4);
193            fail();
194        } catch (RuntimeException exception) {
195            assertSame(EXCEPTION, exception);
196        }
197        try {
198            mock.longReturningMethod(4);
199            fail();
200        } catch (RuntimeException exception) {
201            assertSame(EXCEPTION, exception);
202        }
203        verify(mock);
204    }
205
206    @Test
207    public void floatAndCount() {
208        expect(mock.floatReturningMethod(4)).andThrow(EXCEPTION).times(2);
209        replay(mock);
210        try {
211            mock.floatReturningMethod(4);
212            fail();
213        } catch (RuntimeException exception) {
214            assertSame(EXCEPTION, exception);
215        }
216        try {
217            mock.floatReturningMethod(4);
218            fail();
219        } catch (RuntimeException exception) {
220            assertSame(EXCEPTION, exception);
221        }
222        verify(mock);
223    }
224
225    @Test
226    public void doubleAndCount() {
227        expect(mock.doubleReturningMethod(4)).andThrow(EXCEPTION).times(2);
228        replay(mock);
229        try {
230            mock.doubleReturningMethod(4);
231            fail();
232        } catch (RuntimeException exception) {
233            assertSame(EXCEPTION, exception);
234        }
235        try {
236            mock.doubleReturningMethod(4);
237            fail();
238        } catch (RuntimeException exception) {
239            assertSame(EXCEPTION, exception);
240        }
241        verify(mock);
242    }
243
244    @Test
245    public void objectAndCount() {
246        expect(mock.objectReturningMethod(4)).andThrow(EXCEPTION).times(2);
247        replay(mock);
248        try {
249            mock.objectReturningMethod(4);
250            fail();
251        } catch (RuntimeException exception) {
252            assertSame(EXCEPTION, exception);
253        }
254        try {
255            mock.objectReturningMethod(4);
256            fail();
257        } catch (RuntimeException exception) {
258            assertSame(EXCEPTION, exception);
259        }
260        verify(mock);
261    }
262
263    @Test
264    public void booleanAndMinMax() {
265        expect(mock.booleanReturningMethod(4)).andThrow(EXCEPTION).times(2, 3);
266        replay(mock);
267        try {
268            mock.booleanReturningMethod(4);
269            fail();
270        } catch (RuntimeException exception) {
271            assertSame(EXCEPTION, exception);
272        }
273        try {
274            mock.booleanReturningMethod(4);
275            fail();
276        } catch (RuntimeException exception) {
277            assertSame(EXCEPTION, exception);
278        }
279        verify(mock);
280        try {
281            mock.booleanReturningMethod(4);
282            fail();
283        } catch (RuntimeException exception) {
284            assertSame(EXCEPTION, exception);
285        }
286        verify(mock);
287    }
288
289    @Test
290    public void longAndMinMax() {
291        expect(mock.longReturningMethod(4)).andThrow(EXCEPTION).times(2, 3);
292        replay(mock);
293        try {
294            mock.longReturningMethod(4);
295            fail();
296        } catch (RuntimeException exception) {
297            assertSame(EXCEPTION, exception);
298        }
299        try {
300            mock.longReturningMethod(4);
301            fail();
302        } catch (RuntimeException exception) {
303            assertSame(EXCEPTION, exception);
304        }
305        verify(mock);
306        try {
307            mock.longReturningMethod(4);
308            fail();
309        } catch (RuntimeException exception) {
310            assertSame(EXCEPTION, exception);
311        }
312        verify(mock);
313    }
314
315    @Test
316    public void floatAndMinMax() {
317        expect(mock.floatReturningMethod(4)).andThrow(EXCEPTION).times(2, 3);
318        replay(mock);
319        try {
320            mock.floatReturningMethod(4);
321            fail();
322        } catch (RuntimeException exception) {
323            assertSame(EXCEPTION, exception);
324        }
325        try {
326            mock.floatReturningMethod(4);
327            fail();
328        } catch (RuntimeException exception) {
329            assertSame(EXCEPTION, exception);
330        }
331        verify(mock);
332        try {
333            mock.floatReturningMethod(4);
334            fail();
335        } catch (RuntimeException exception) {
336            assertSame(EXCEPTION, exception);
337        }
338        verify(mock);
339    }
340
341    @Test
342    public void doubleAndMinMax() {
343        expect(mock.doubleReturningMethod(4)).andThrow(EXCEPTION).times(2, 3);
344        replay(mock);
345        try {
346            mock.doubleReturningMethod(4);
347            fail();
348        } catch (RuntimeException exception) {
349            assertSame(EXCEPTION, exception);
350        }
351        try {
352            mock.doubleReturningMethod(4);
353            fail();
354        } catch (RuntimeException exception) {
355            assertSame(EXCEPTION, exception);
356        }
357        verify(mock);
358        try {
359            mock.doubleReturningMethod(4);
360            fail();
361        } catch (RuntimeException exception) {
362            assertSame(EXCEPTION, exception);
363        }
364        verify(mock);
365    }
366
367    @Test
368    public void objectAndMinMax() {
369        expect(mock.objectReturningMethod(4)).andThrow(EXCEPTION).times(2, 3);
370        replay(mock);
371        try {
372            mock.objectReturningMethod(4);
373            fail();
374        } catch (RuntimeException exception) {
375            assertSame(EXCEPTION, exception);
376        }
377        try {
378            mock.objectReturningMethod(4);
379            fail();
380        } catch (RuntimeException exception) {
381            assertSame(EXCEPTION, exception);
382        }
383        verify(mock);
384        try {
385            mock.objectReturningMethod(4);
386            fail();
387        } catch (RuntimeException exception) {
388            assertSame(EXCEPTION, exception);
389        }
390        verify(mock);
391    }
392
393}
394
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)