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

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

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 net.sf.cglib.proxy.Enhancer;
19import net.sf.cglib.proxy.NoOp;
20import org.droidparts.dexmaker.stock.ProxyBuilder;
21import org.easymock.EasyMock;
22import org.easymock.internal.AndroidSupport;
23import org.junit.Test;
24
25import java.lang.reflect.InvocationHandler;
26import java.lang.reflect.Proxy;
27import java.util.ArrayList;
28import java.util.List;
29
30import static org.easymock.EasyMock.*;
31import static org.easymock.internal.MocksControl.*;
32import static org.junit.Assert.*;
33
34/**
35 * @author Henri Tremblay
36 */
37public class ClassExtensionHelperTest {
38
39    private static final InvocationHandler NOOP_INVOCATION_HANDLER = (proxy, method, args) -> null;
40
41    @Test
42    public void testGetControl_EasyMock() {
43        List<?> mock = EasyMock.createMock(List.class);
44        assertNotNull(getControl(mock));
45    }
46
47    @Test
48    public void testGetControl_EasyMockClassExtension() {
49        ArrayList<?> mock = EasyMock.createMock(ArrayList.class);
50        assertNotNull(getControl(mock));
51    }
52
53    @Test
54    public void testGetControl_EnhancedButNotAMock() throws Exception {
55        Object o;
56        if (AndroidSupport.isAndroid()) {
57            o = ProxyBuilder.forClass(ArrayList.class)
58                    .handler(NOOP_INVOCATION_HANDLER)
59                    .build();
60        } else {
61            o = Enhancer.create(ArrayList.class, NoOp.INSTANCE);
62        }
63        try {
64            getControl(o);
65            fail();
66        } catch (IllegalArgumentException e) {
67            assertEquals("Not a mock: " + o.getClass().getName(), e.getMessage());
68        }
69    }
70
71    @Test
72    public void testGetControl_ProxyButNotMock() {
73        Object o = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { List.class },
74            (proxy, method, args) -> null);
75        try {
76            getControl(o);
77            fail();
78        } catch (IllegalArgumentException e) {
79            assertEquals("Not a mock: " + o.getClass().getName(), e.getMessage());
80        }
81    }
82
83    @Test
84    public void testGetControl_NotAMock() {
85        try {
86            getControl("");
87            fail();
88        } catch (IllegalArgumentException expected) {
89        }
90    }
91
92    @Test
93    public void testMockType_Class() {
94        Object o = createMock(ArrayList.class);
95        Class<?> c = getMockedClass(o);
96        assertSame(ArrayList.class, c);
97    }
98
99    @Test
100    public void testMockType_Interface() {
101        Object o = createMock(List.class);
102        Class<?> c = getMockedClass(o);
103        assertSame(List.class, c);
104    }
105}
106
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)