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

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

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1/**
2 * Copyright 2001-2013 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.junit.Test;
22
23/**
24 * @author Henri Tremblay
25 */
26public class ConstructorTest {
27
28    public static class FooClass {
29        public void foo() {
30            // Since it's always mocked, it should never be called
31            fail();
32        }
33    }
34
35    public static class EmptyConstructorClass extends FooClass {
36    }
37
38    public static class ConstructorCallingPublicMethodClass extends FooClass {
39
40        public ConstructorCallingPublicMethodClass() {
41            foo();
42        }
43    }
44
45    private void testConstructor(final Class<? extends FooClass> mockedClass) {
46        final FooClass mock = createMock(mockedClass);
47        assertTrue(mockedClass.isAssignableFrom(mock.getClass()));
48        mock.foo();
49        expectLastCall();
50        replay(mock);
51        mock.foo();
52        verify(mock);
53    }
54
55    /**
56     * Test if a class with an empty constructor is mocked correctly.
57     */
58//    @Test
59    public void emptyConstructor() {
60        testConstructor(EmptyConstructorClass.class);
61    }
62
63    /**
64     * Test that a constructor calling a mocked method (in this case a public
65     * one) is mocked correctly. The expected behavior is that the mocked method
66     * won't be called and just be ignored
67     */
68    @Test
69    public void constructorCallingPublicMethod() {
70        testConstructor(ConstructorCallingPublicMethodClass.class);
71    }
72}
73
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)