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

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

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.easymock.internal.MocksControl;
22import org.junit.Before;
23import org.junit.Test;
24
25/**
26 * @author OFFIS, Tammo Freese
27 */
28public class RecordStateMethodCallMissingTest {
29
30    private static final String METHOD_CALL_NEEDED = "method call on the mock needed before setting ";
31
32    IMethods mock;
33
34    MocksControl control;
35
36    @Before
37    public void setup() {
38        control = (MocksControl) createControl(); // this cast is a hack. It will provoke the errors below but I don't think it can happen using EasyMock normally
39        mock = control.createMock(IMethods.class);
40    }
41
42    private void assertMessage(String suffix, IllegalStateException expected) {
43        assertEquals(METHOD_CALL_NEEDED + suffix, expected.getMessage());
44    }
45
46    @Test
47    public void setBooleanReturnValueWithoutMethodCall() {
48        try {
49            control.andReturn(false);
50            fail("IllegalStateException expected");
51        } catch (IllegalStateException expected) {
52            assertMessage("return value", expected);
53        }
54    }
55
56    @Test
57    public void setLongReturnValueWithoutMethodCall() {
58        try {
59            control.andReturn(0L);
60            fail("IllegalStateException expected");
61        } catch (IllegalStateException expected) {
62            assertMessage("return value", expected);
63        }
64    }
65
66    @Test
67    public void setFloatReturnValueWithoutMethodCall() {
68        try {
69            control.andReturn(0.0f);
70            fail("IllegalStateException expected");
71        } catch (IllegalStateException expected) {
72            assertMessage("return value", expected);
73        }
74    }
75
76    @Test
77    public void setDoubleReturnValueWithoutMethodCall() {
78        try {
79            control.andReturn(0.0);
80            fail("IllegalStateException expected");
81        } catch (IllegalStateException expected) {
82            assertMessage("return value", expected);
83        }
84    }
85
86    @Test
87    public void setObjectReturnValueWithoutMethodCall() {
88        try {
89            control.andReturn(null);
90            fail("IllegalStateException expected");
91        } catch (IllegalStateException expected) {
92            assertMessage("return value", expected);
93        }
94    }
95
96    @Test
97    public void setThrowableWithoutMethodCall() {
98        try {
99            control.andThrow(new RuntimeException());
100            fail("IllegalStateException expected");
101        } catch (IllegalStateException expected) {
102            assertMessage("Throwable", expected);
103        }
104    }
105
106    @Test
107    public void setAnswerWithoutMethodCall() {
108        try {
109            control.andAnswer(() -> null);
110            fail("IllegalStateException expected");
111        } catch (IllegalStateException expected) {
112            assertMessage("answer", expected);
113        }
114    }
115
116    @Test
117    public void setDelegateToWithoutMethodCall() {
118        try {
119            control.andDelegateTo(null);
120            fail("IllegalStateException expected");
121        } catch (IllegalStateException expected) {
122            assertMessage("delegate", expected);
123        }
124    }
125
126    @Test
127    public void setAnyTimesWithoutMethodCall() {
128        try {
129            control.anyTimes();
130            fail("IllegalStateException expected");
131        } catch (IllegalStateException expected) {
132            assertMessage("times", expected);
133        }
134    }
135
136    @Test
137    public void setAtLeastOnceWithoutMethodCall() {
138        try {
139            control.atLeastOnce();
140            fail("IllegalStateException expected");
141        } catch (IllegalStateException expected) {
142            assertMessage("times", expected);
143        }
144    }
145
146    @Test
147    public void setTimesWithoutMethodCall() {
148        try {
149            control.times(3);
150            fail("IllegalStateException expected");
151        } catch (IllegalStateException expected) {
152            assertMessage("times", expected);
153        }
154    }
155
156    @Test
157    public void setTimesMinMaxWithoutMethodCall() {
158        try {
159            control.times(1, 3);
160            fail("IllegalStateException expected");
161        } catch (IllegalStateException expected) {
162            assertMessage("times", expected);
163        }
164    }
165
166    @Test
167    public void setOnceWithoutMethodCall() {
168        try {
169            control.once();
170            fail("IllegalStateException expected");
171        } catch (IllegalStateException expected) {
172            assertMessage("times", expected);
173        }
174    }
175
176    @Test
177    public void setBooleanDefaultReturnValueWithoutMethodCall() {
178        try {
179            control.andStubReturn(false);
180            fail("IllegalStateException expected");
181        } catch (IllegalStateException expected) {
182            assertMessage("stub return value", expected);
183        }
184    }
185
186    @Test
187    public void setLongDefaultReturnValueWithoutMethodCall() {
188        try {
189            control.andStubReturn(0L);
190            fail("IllegalStateException expected");
191        } catch (IllegalStateException expected) {
192            assertMessage("stub return value", expected);
193        }
194    }
195
196    @Test
197    public void setFloatDefaultReturnValueWithoutMethodCall() {
198        try {
199            control.andStubReturn(0.0f);
200            fail("IllegalStateException expected");
201        } catch (IllegalStateException expected) {
202            assertMessage("stub return value", expected);
203        }
204    }
205
206    @Test
207    public void setDoubleDefaultReturnValueWithoutMethodCall() {
208        try {
209            control.andStubReturn(0.0);
210            fail("IllegalStateException expected");
211        } catch (IllegalStateException expected) {
212            assertMessage("stub return value", expected);
213        }
214    }
215
216    @Test
217    public void setObjectDefaultReturnValueWithoutMethodCall() {
218        try {
219            control.andStubReturn(null);
220            fail("IllegalStateException expected");
221        } catch (IllegalStateException expected) {
222            assertMessage("stub return value", expected);
223        }
224    }
225
226    @Test
227    public void setDefaultVoidCallableWithoutMethodCall() {
228        try {
229            control.asStub();
230            fail("IllegalStateException expected");
231        } catch (IllegalStateException expected) {
232            assertMessage("stub behavior", expected);
233        }
234    }
235
236    @Test
237    public void setDefaultThrowableWithoutMethodCall() {
238        try {
239            control.andStubThrow(new RuntimeException());
240            fail("IllegalStateException expected");
241        } catch (IllegalStateException expected) {
242            assertMessage("stub Throwable", expected);
243        }
244    }
245
246    @Test
247    public void setStubAnswerWithoutMethodCall() {
248        try {
249            control.andStubAnswer(() -> null);
250            fail("IllegalStateException expected");
251        } catch (IllegalStateException expected) {
252            assertMessage("stub answer", expected);
253        }
254    }
255
256    @Test
257    public void setStubDelegateToWithoutMethodCall() {
258        try {
259            control.andStubDelegateTo(null);
260            fail("IllegalStateException expected");
261        } catch (IllegalStateException expected) {
262            assertMessage("stub delegate", expected);
263        }
264    }
265
266    @Test
267    public void timesWithoutReturnValue() {
268        mock.booleanReturningMethod(1);
269        try {
270            expectLastCall().times(3);
271            fail();
272        } catch (IllegalStateException expected) {
273            assertEquals("last method called on mock is not a void method", expected.getMessage());
274        }
275    }
276
277    @Test
278    public void asStubWithNonVoidMethod() {
279        mock.booleanReturningMethod(1);
280        try {
281            expectLastCall().asStub();
282            fail();
283        } catch (IllegalStateException expected) {
284            assertEquals("last method called on mock is not a void method", expected.getMessage());
285        }
286    }
287
288    @Test
289    public void andVoidWithNonVoidMethod() {
290        mock.booleanReturningMethod(1);
291        try {
292            expectLastCall().andVoid();
293            fail();
294        } catch (IllegalStateException expected) {
295            assertEquals("last method called on mock is not a void method", expected.getMessage());
296        }
297    }
298}
299
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
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)