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 (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.easymock.EasyMock.*;
8import static org.junit.Assert.*;
9
10import org.easymock.MockControl;
11import org.junit.Before;
12import org.junit.Test;
13
14/**
15 * Same as UsageExpectAndThrowTest except that each mocked method is called twice to make sure the defaulting works
16 * fine.
17 * 
18 * @author Henri Tremblay
19 */
20public class UsageExpectAndDefaultThrowTest {
21    private MockControl<IMethods> control;
22
23    private IMethods mock;
24
25    private static RuntimeException EXCEPTION = new RuntimeException();
26
27    @Before
28    public void setup() {
29        control = MockControl.createControl(IMethods.class);
30        mock = control.getMock();
31    }
32
33    @Test
34    public void booleanType() {
35        control.expectAndDefaultThrow(mock.booleanReturningMethod(4), EXCEPTION);
36        control.replay();
37        try {
38            mock.booleanReturningMethod(4);
39            fail();
40        } catch (RuntimeException exception) {
41            assertSame(EXCEPTION, exception);
42        }
43        try {
44            mock.booleanReturningMethod(4);
45            fail();
46        } catch (RuntimeException exception) {
47            assertSame(EXCEPTION, exception);
48        }
49        control.verify();
50    }
51
52    @Test
53    public void longType() {
54        control.expectAndDefaultThrow(mock.longReturningMethod(4), EXCEPTION);
55        control.replay();
56        try {
57            mock.longReturningMethod(4);
58            fail();
59        } catch (RuntimeException exception) {
60            assertSame(EXCEPTION, exception);
61        }
62        try {
63            mock.longReturningMethod(4);
64            fail();
65        } catch (RuntimeException exception) {
66            assertSame(EXCEPTION, exception);
67        }
68        control.verify();
69    }
70
71    @Test
72    public void floatType() {
73        control.expectAndDefaultThrow(mock.floatReturningMethod(4), EXCEPTION);
74        control.replay();
75        try {
76            mock.floatReturningMethod(4);
77            fail();
78        } catch (RuntimeException exception) {
79            assertSame(EXCEPTION, exception);
80        }
81        try {
82            mock.floatReturningMethod(4);
83            fail();
84        } catch (RuntimeException exception) {
85            assertSame(EXCEPTION, exception);
86        }
87        control.verify();
88    }
89
90    @Test
91    public void doubleType() {
92        control.expectAndDefaultThrow(mock.doubleReturningMethod(4), EXCEPTION);
93        control.replay();
94        try {
95            mock.doubleReturningMethod(4);
96            fail();
97        } catch (RuntimeException exception) {
98            assertSame(EXCEPTION, exception);
99        }
100        try {
101            mock.doubleReturningMethod(4);
102            fail();
103        } catch (RuntimeException exception) {
104            assertSame(EXCEPTION, exception);
105        }
106        control.verify();
107    }
108
109    @Test
110    public void object() {
111        control.expectAndDefaultThrow(mock.objectReturningMethod(4), EXCEPTION);
112        control.replay();
113        try {
114            mock.objectReturningMethod(4);
115            fail();
116        } catch (RuntimeException exception) {
117            assertSame(EXCEPTION, exception);
118        }
119        try {
120            mock.objectReturningMethod(4);
121            fail();
122        } catch (RuntimeException exception) {
123            assertSame(EXCEPTION, exception);
124        }
125        control.verify();
126    }
127
128    @Test
129    public void throwableAndDefaultThrowable() throws Exception {
130
131        mock.oneArg("1");
132
133        expectLastCall().andThrow(new IllegalArgumentException());
134        control.setDefaultThrowable(new IllegalStateException());
135
136        control.replay();
137
138        try {
139            mock.oneArg("1");
140        } catch (IllegalArgumentException ignored) {
141        }
142        try {
143            mock.oneArg("1");
144        } catch (IllegalStateException ignored) {
145        }
146        try {
147            mock.oneArg("2");
148        } catch (IllegalStateException ignored) {
149        }
150        control.verify();
151    }
152
153}
154
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)