How to use RuntimeExceptionWrapper class of org.easymock.internal package

Best Easymock code snippet using org.easymock.internal.RuntimeExceptionWrapper

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 org.easymock.MockControl;
8import org.easymock.internal.MocksBehavior;
9import org.easymock.internal.ReplayState;
10import org.easymock.internal.RuntimeExceptionWrapper;
11import org.junit.Before;
12import org.junit.Test;
13
14public class ReplayStateInvalidCallsTest {
15
16    private ReplayState control;
17
18    private Exception exception;
19
20    @Before
21    public void setUp() {
22        exception = new Exception();
23        control = new ReplayState(new MocksBehavior(false));
24    }
25
26    @Test(expected = RuntimeExceptionWrapper.class)
27    public void expectAndThrowLongWithMinMax() {
28        control.andThrow(exception);
29    }
30
31    @Test(expected = RuntimeExceptionWrapper.class)
32    public void expectAndReturnObjectWithMinMax() {
33        control.andReturn("");
34    }
35
36    @Test(expected = RuntimeExceptionWrapper.class)
37    public void setDefaultMatcher() {
38        control.setDefaultMatcher(MockControl.ARRAY_MATCHER);
39    }
40
41    @Test(expected = RuntimeExceptionWrapper.class)
42    public void asStub() {
43        control.asStub();
44    }
45
46    @Test(expected = RuntimeExceptionWrapper.class)
47    public void setMatcher() {
48        control.setMatcher(null, MockControl.ARRAY_MATCHER);
49    }
50
51    @Test(expected = RuntimeExceptionWrapper.class)
52    public void setDefaultReturnValue() {
53        control.setDefaultReturnValue("");
54    }
55
56    @Test(expected = RuntimeExceptionWrapper.class)
57    public void setDefaultThrowable() {
58        control.setDefaultThrowable(exception);
59    }
60
61    @Test(expected = RuntimeExceptionWrapper.class)
62    public void setDefaultVoidCallable() {
63        control.setDefaultVoidCallable();
64    }
65
66    @Test(expected = RuntimeExceptionWrapper.class)
67    public void replay() {
68        control.replay();
69    }
70
71    @Test(expected = RuntimeExceptionWrapper.class)
72    public void checkOrder() {
73        control.checkOrder(true);
74    }
75
76    @Test(expected = RuntimeExceptionWrapper.class)
77    public void andStubReturn() {
78        control.andStubReturn("7");
79    }
80
81    @Test(expected = RuntimeExceptionWrapper.class)
82    public void andStubThrow() {
83        control.andStubThrow(new RuntimeException());
84    }
85
86    @Test(expected = RuntimeExceptionWrapper.class)
87    public void andStubAnswer() {
88        control.andStubAnswer(null);
89    }
90
91    @Test(expected = RuntimeExceptionWrapper.class)
92    public void times() {
93        control.times(MockControl.ONE);
94    }
95
96    @Test(expected = RuntimeExceptionWrapper.class)
97    public void callback() {
98        control.callback(new Runnable() {
99            public void run() {
100            };
101        });
102    }
103
104    @Test(expected = RuntimeExceptionWrapper.class)
105    public void andReturn() {
106        control.andReturn(null);
107    }
108
109    @Test(expected = RuntimeExceptionWrapper.class)
110    public void andThrow() {
111        control.andThrow(new RuntimeException());
112    }
113
114    @Test(expected = RuntimeExceptionWrapper.class)
115    public void andAnswer() {
116        control.andAnswer(null);
117    }
118
119    @Test(expected = RuntimeExceptionWrapper.class)
120    public void defaultThrowable() {
121        control.setDefaultThrowable(new RuntimeException());
122    }
123
124    @Test(expected = RuntimeExceptionWrapper.class)
125    public void defaultReturnValue() {
126        control.setDefaultReturnValue(null);
127    }
128
129    @Test(expected = RuntimeExceptionWrapper.class)
130    public void defaultVoidCallable() {
131        control.setDefaultVoidCallable();
132    }
133}
Full Screen
copy
1/*
2 * Copyright 2001-2009 OFFIS, Tammo Freese
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.internal;
17
18import java.io.Serializable;
19
20import org.easymock.IAnswer;
21import org.easymock.IExpectationSetters;
22import org.easymock.IMocksControl;
23
24public class MocksControl implements IMocksControl, IExpectationSetters<Object>, Serializable {
25
26    private static final long serialVersionUID = 443604921336702014L;
27
28    private IMocksControlState state;
29
30    private IMocksBehavior behavior;
31
32    public enum MockType {
33        NICE, DEFAULT, STRICT
34    }
35
36    private MockType type;
37
38    public MocksControl(MockType type) {
39        this.type = type;
40        reset();
41    }
42
43    public IMocksControlState getState() {
44        return state;
45    }
46
47    public <T> T createMock(Class<T> toMock) {
48        try {
49            state.assertRecordState();
50            IProxyFactory<T> proxyFactory = createProxyFactory(toMock);
51            return proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
52                    toMock, new MockInvocationHandler(this), null));
53        } catch (RuntimeExceptionWrapper e) {
54            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
55        }
56    }
57
58    public <T> T createMock(String name, Class<T> toMock) {
59        try {
60            state.assertRecordState();
61            IProxyFactory<T> proxyFactory = createProxyFactory(toMock);
62            return proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
63                    toMock, new MockInvocationHandler(this), name));
64        } catch (RuntimeExceptionWrapper e) {
65            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
66        }
67    }
68
69    protected <T> IProxyFactory<T> createProxyFactory(Class<T> toMock) {
70        return new JavaProxyFactory<T>();
71    }
72
73    public final void reset() {
74        behavior = new MocksBehavior(type == MockType.NICE);
75        behavior.checkOrder(type == MockType.STRICT);
76        state = new RecordState(behavior);
77        LastControl.reportLastControl(null);
78    }
79
80    public void resetToNice() {
81        type = MockType.NICE;
82        reset();
83    }
84    
85    public void resetToDefault() {
86        type = MockType.DEFAULT;
87        reset();        
88    }
89    
90    public void resetToStrict() {
91        type = MockType.STRICT;
92        reset();
93    }
94    
95    public void replay() {
96        try {
97            state.replay();
98            state = new ReplayState(behavior);
99            LastControl.reportLastControl(null);
100        } catch (RuntimeExceptionWrapper e) {
101            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
102        }
103    }
104
105    public void verify() {
106        try {
107            state.verify();
108        } catch (RuntimeExceptionWrapper e) {
109            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
110        } catch (AssertionErrorWrapper e) {
111            throw (AssertionError) e.getAssertionError().fillInStackTrace();
112        }
113    }
114
115    public void checkOrder(boolean value) {
116        try {
117            state.checkOrder(value);
118        } catch (RuntimeExceptionWrapper e) {
119            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
120        }
121    }
122    
123    public void makeThreadSafe(boolean threadSafe) {
124        try {
125            state.makeThreadSafe(threadSafe);
126        } catch (RuntimeExceptionWrapper e) {
127            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
128        }
129    }
130    
131    public void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread) {
132        try {
133            state.checkIsUsedInOneThread(shouldBeUsedInOneThread);
134        } catch (RuntimeExceptionWrapper e) {
135            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
136        }
137    }
138
139    // methods from IBehaviorSetters
140
141    public IExpectationSetters<Object> andReturn(Object value) {
142        try {
143            state.andReturn(value);
144            return this;
145        } catch (RuntimeExceptionWrapper e) {
146            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
147        }
148    }
149
150    public IExpectationSetters<Object> andThrow(Throwable throwable) {
151        try {
152            state.andThrow(throwable);
153            return this;
154        } catch (RuntimeExceptionWrapper e) {
155            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
156        }
157    }
158
159    public IExpectationSetters<Object> andAnswer(IAnswer<? extends Object> answer) {
160        try {
161            state.andAnswer(answer);
162            return this;
163        } catch (RuntimeExceptionWrapper e) {
164            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
165        }
166    }
167
168    public IExpectationSetters<Object> andDelegateTo(Object answer) {
169        try {
170            state.andDelegateTo(answer);
171            return this;
172        } catch (RuntimeExceptionWrapper e) {
173            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
174        }
175    }
176    
177    public void andStubReturn(Object value) {
178        try {
179            state.andStubReturn(value);
180        } catch (RuntimeExceptionWrapper e) {
181            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
182        }
183    }
184
185    public void andStubThrow(Throwable throwable) {
186        try {
187            state.andStubThrow(throwable);
188        } catch (RuntimeExceptionWrapper e) {
189            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
190        }
191    }
192
193    public void andStubAnswer(IAnswer<? extends Object> answer) {
194        try {
195            state.andStubAnswer(answer);
196        } catch (RuntimeExceptionWrapper e) {
197            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
198        }
199    }
200
201
202    public void andStubDelegateTo(Object delegateTo) {
203        try {
204            state.andStubDelegateTo(delegateTo);
205        } catch (RuntimeExceptionWrapper e) {
206            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
207        }
208    }
209    
210    public void asStub() {
211        try {
212            state.asStub();
213        } catch (RuntimeExceptionWrapper e) {
214            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
215        }
216    }
217
218    public IExpectationSetters<Object> times(int times) {
219        try {
220            state.times(new Range(times));
221            return this;
222        } catch (RuntimeExceptionWrapper e) {
223            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
224        }
225    }
226
227    public IExpectationSetters<Object> times(int min, int max) {
228        try {
229            state.times(new Range(min, max));
230            return this;
231        } catch (RuntimeExceptionWrapper e) {
232            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
233        }
234    }
235
236    public IExpectationSetters<Object> once() {
237        try {
238            state.times(ONCE);
239            return this;
240        } catch (RuntimeExceptionWrapper e) {
241            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
242        }
243    }
244
245    public IExpectationSetters<Object> atLeastOnce() {
246        try {
247            state.times(AT_LEAST_ONCE);
248            return this;
249        } catch (RuntimeExceptionWrapper e) {
250            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
251        }
252    }
253
254    public IExpectationSetters<Object> anyTimes() {
255        try {
256            state.times(ZERO_OR_MORE);
257            return this;
258        } catch (RuntimeExceptionWrapper e) {
259            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
260        }
261    }
262
263    /**
264     * Exactly one call.
265     */
266    public static final Range ONCE = new Range(1);
267
268    /**
269     * One or more calls.
270     */
271    public static final Range AT_LEAST_ONCE = new Range(1, Integer.MAX_VALUE);
272
273    /**
274     * Zero or more calls.
275     */
276    public static final Range ZERO_OR_MORE = new Range(0, Integer.MAX_VALUE);
277
278    @SuppressWarnings("deprecation")
279    public void setLegacyDefaultMatcher(org.easymock.ArgumentsMatcher matcher) {
280        try {
281            state.setDefaultMatcher(matcher);
282        } catch (RuntimeExceptionWrapper e) {
283            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
284        }
285    }
286
287    @SuppressWarnings("deprecation")
288    public void setLegacyMatcher(org.easymock.ArgumentsMatcher matcher) {
289        try {
290            state.setMatcher(null, matcher);
291        } catch (RuntimeExceptionWrapper e) {
292            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
293        }
294    }
295
296    public void setLegacyDefaultReturnValue(Object value) {
297        try {
298            state.setDefaultReturnValue(value);
299        } catch (RuntimeExceptionWrapper e) {
300            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
301        }
302    }
303
304    public void setLegacyDefaultVoidCallable() {
305        state.setDefaultVoidCallable();
306    }
307
308    public void setLegacyDefaultThrowable(Throwable throwable) {
309        try {
310            state.setDefaultThrowable(throwable);
311        } catch (RuntimeExceptionWrapper e) {
312            throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
313        }
314    }
315}
316
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

...Most popular Stackoverflow questions on RuntimeExceptionWrapper

    No relevant questions found for this class 😞

Most used methods in RuntimeExceptionWrapper

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)