How to use method of org.easymock.tests2.EasyMockSupportClassTest class

Best Easymock code snippet using org.easymock.tests2.EasyMockSupportClassTest.

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.tests2;
17
18import org.easymock.EasyMockSupport;
19import org.easymock.IMocksControl;
20import org.junit.Before;
21import org.junit.Test;
22
23import java.lang.reflect.Method;
24
25import static org.easymock.EasyMock.*;
26import static org.hamcrest.core.Is.*;
27import static org.junit.Assert.*;
28
29/**
30 * @author Henri Tremblay
31 */
32@SuppressWarnings("deprecation")
33public class EasyMockSupportClassTest extends EasyMockSupport {
34
35    public static class ToMock {
36        public int foo() {
37            return 5;
38        }
39    }
40
41    private Method foo;
42
43    @Before
44    public void setUp() throws Exception {
45        foo = ToMock.class.getMethod("foo");
46    }
47
48    @Test
49    public void testCreateStrictControl() {
50        IMocksControl ctrl = createStrictControl();
51        assertThat(ctrl.createMock(ToMock.class), is(ToMock.class));
52    }
53
54    @Test
55    public void testCreateControl() {
56        IMocksControl ctrl = createControl();
57        assertThat(ctrl.createMock(ToMock.class), is(ToMock.class));
58    }
59
60    @Test
61    public void testCreateNiceControl() {
62        IMocksControl ctrl = createNiceControl();
63        assertThat(ctrl.createMock(ToMock.class), is(ToMock.class));
64    }
65
66    @Test
67    public void testCreateStrictMockClassOfT() {
68        assertThat(createStrictMock(ToMock.class), is(ToMock.class));
69    }
70
71    @Test
72    public void testCreateStrictMockStringClassOfT() {
73        assertThat(createStrictMock("myMock", ToMock.class), is(ToMock.class));
74    }
75
76    @Test
77    public void testCreateMockClassOfT() {
78        assertThat(createMock(ToMock.class), is(ToMock.class));
79    }
80
81    @Test
82    public void testCreateMockStringClassOfT() {
83        assertThat(createMock("myMock", ToMock.class), is(ToMock.class));
84    }
85
86    @Test
87    public void testCreateNiceMockClassOfT() {
88        assertThat(createNiceMock(ToMock.class), is(ToMock.class));
89    }
90
91    @Test
92    public void testCreateNiceMockStringClassOfT() {
93        assertThat(createNiceMock("myMock", ToMock.class), is(ToMock.class));
94    }
95
96    @Test
97    public void testAll() {
98        ToMock t = createMock(ToMock.class);
99        expect(t.foo()).andReturn(1);
100        replayAll();
101        t.foo();
102        verifyAll();
103        resetAll();
104        resetAllToDefault();
105        resetAllToNice();
106        resetAllToStrict();
107    }
108
109    @Test
110    public void testCreateMockBuilder() {
111        ToMock t = createMockBuilder(ToMock.class).addMockedMethod(foo).createMock();
112        expect(t.foo()).andReturn(1);
113        replayAll();
114        assertEquals(1, t.foo());
115        verifyAll();
116    }
117
118    @Test
119    public void testCreateMockBuilder_existingControl() {
120        IMocksControl ctrl = createControl(); // ctrl registered once here
121        ToMock t = createMockBuilder(ToMock.class).addMockedMethod(foo).createMock(ctrl); // should not be registered a second time here
122        expect(t.foo()).andReturn(1);
123        replayAll();
124        assertEquals(1, t.foo());
125        verifyAll();
126    }
127
128    @Test
129    public void testAllMockBuilderFlavors() {
130        ToMock t1 = createMockBuilder(ToMock.class).addMockedMethod(foo).createMock();
131        ToMock t2 = createMockBuilder(ToMock.class).addMockedMethod(foo).createNiceMock();
132        ToMock t3 = createMockBuilder(ToMock.class).addMockedMethod(foo).createStrictMock();
133        expect(t1.foo()).andReturn(1);
134        expect(t2.foo()).andReturn(2);
135        expect(t3.foo()).andReturn(3);
136        replayAll();
137        assertEquals(1, t1.foo());
138        assertEquals(2, t2.foo());
139        assertEquals(3, t3.foo());
140        verifyAll();
141    }
142}
143
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)