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

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

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.tests2;
6
7import static org.easymock.EasyMock.*;
8import static org.junit.Assert.*;
9
10import org.easymock.tests.IMethods;
11import org.junit.Before;
12import org.junit.Test;
13
14public class StubTest {
15    private IMethods mock;
16
17    @Before
18    public void setup() {
19        mock = createStrictMock(IMethods.class);
20    }
21
22    @Test
23    public void stub() {
24        mock.simpleMethodWithArgument("1");
25        expectLastCall().anyTimes();
26        mock.simpleMethodWithArgument("2");
27        expectLastCall().anyTimes();
28        mock.simpleMethodWithArgument("3");
29        expectLastCall().asStub();
30
31        replay(mock);
32
33        mock.simpleMethodWithArgument("3");
34        mock.simpleMethodWithArgument("3");
35        mock.simpleMethodWithArgument("1");
36        mock.simpleMethodWithArgument("2");
37        mock.simpleMethodWithArgument("3");
38        mock.simpleMethodWithArgument("3");
39
40        verify(mock);
41
42    }
43
44    @Test
45    public void stubWithReturnValue() {
46        expect(mock.oneArg("1")).andReturn("A").andStubReturn("B");
47        expect(mock.oneArg("2")).andThrow(new IllegalArgumentException()).andStubThrow(new IllegalStateException());
48
49        replay(mock);
50
51        assertEquals("A", mock.oneArg("1"));
52        assertEquals("B", mock.oneArg("1"));
53        assertEquals("B", mock.oneArg("1"));
54        try {
55            mock.oneArg("2");
56        } catch (IllegalArgumentException ignored) {
57        }
58        assertEquals("B", mock.oneArg("1"));
59        try {
60            mock.oneArg("2");
61        } catch (IllegalStateException ignored) {
62        }
63        assertEquals("B", mock.oneArg("1"));
64        try {
65            mock.oneArg("2");
66        } catch (IllegalStateException ignored) {
67        }
68        verify(mock);
69    }
70
71}
72
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 used method in StubTest

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)