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

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

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 org.easymock.EasyMock;
19import org.easymock.IExpectationSetters;
20import org.easymock.IMocksControl;
21import org.junit.Before;
22import org.junit.Test;
23
24import static org.junit.Assert.assertEquals;
25import static org.junit.Assert.assertThrows;
26
27/**
28 * @author OFFIS, Tammo Freese
29 */
30public class ReplayStateInvalidUsageTest {
31
32    private IMethods mock;
33
34    private IMocksControl mocksControl;
35
36    private IExpectationSetters<String> expectationSetters;
37
38    @SuppressWarnings("unchecked")
39    @Before
40    public void setUp() {
41        mock = EasyMock.createMock(IMethods.class);
42        EasyMock.replay(mock);
43        mocksControl = EasyMock.createControl();
44        mocksControl.replay();
45        expectationSetters = (IExpectationSetters<String>) mocksControl;
46    }
47
48    @Test
49    public void setVoidCallable() {
50        assertThrows(IllegalStateException.class, EasyMock::expectLastCall);
51    }
52
53    @Test
54    public void replay() {
55        assertThrows(IllegalStateException.class, () -> EasyMock.replay(mock));
56    }
57
58    @Test
59    public void replaySameMethod() {
60        EasyMock.reset(mock);
61
62        RuntimeException t = assertThrows(RuntimeException.class, () -> EasyMock.replay(mock, mock));
63        assertEquals(IllegalStateException.class, t.getCause().getClass());
64        assertEquals("On mock #1 (zero indexed): This method must not be called in replay state.", t.getMessage());
65    }
66
67    @Test
68    public void createMock() {
69        assertThrows(IllegalStateException.class, () -> mocksControl.createMock(IMethods.class));
70    }
71
72    @Test
73    public void createMockWithName() {
74        assertThrows(IllegalStateException.class, () -> mocksControl.createMock("", IMethods.class));
75    }
76
77    @Test
78    public void checkOrder() {
79        assertThrows(IllegalStateException.class, () -> mocksControl.checkOrder(true));
80    }
81
82    @Test
83    public void makeThreadSafe() {
84        assertThrows(IllegalStateException.class, () -> mocksControl.makeThreadSafe(true));
85    }
86
87    @Test
88    public void checkIsUsedInOneThread() {
89        assertThrows(IllegalStateException.class, () -> mocksControl.checkIsUsedInOneThread(true));
90    }
91
92    @Test
93    public void andStubReturn() {
94        assertThrows(IllegalStateException.class, () -> expectationSetters.andStubReturn("7"));
95    }
96
97    @Test
98    public void andStubThrow() {
99        assertThrows(IllegalStateException.class, () -> expectationSetters.andStubThrow(new RuntimeException()));
100    }
101
102    @Test
103    public void asStub() {
104        assertThrows(IllegalStateException.class, () -> expectationSetters.asStub());
105    }
106
107    @Test
108    public void times() {
109        assertThrows(IllegalStateException.class, () -> expectationSetters.times(3));
110    }
111
112    @Test
113    public void anyTimes() {
114        assertThrows(IllegalStateException.class, () -> expectationSetters.anyTimes());
115    }
116
117    @Test
118    public void manyMocks() {
119        EasyMock.reset(mock);
120
121        RuntimeException t = assertThrows(RuntimeException.class, () -> EasyMock.replay(mock, mock));
122        assertEquals(IllegalStateException.class, t.getCause().getClass());
123        assertEquals("On mock #1 (zero indexed): This method must not be called in replay state.", t.getMessage());
124    }
125}
126
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)