How to use UsageVerifyTest class of org.easymock.tests package

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

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.tests;
6
7import org.junit.runner.RunWith;
8import org.junit.runners.Suite;
9import org.junit.runners.Suite.SuiteClasses;
10
11@RunWith(Suite.class)
12@SuiteClasses(value = { ArgumentsMatcherTest.class, ArrayMatcherTest.class, DefaultMatcherTest.class,
13        EqualsMatcherTest.class, ExpectedMethodCallTest.class, LegacyBehaviorTests.class, MatchableArgumentsTest.class,
14        InvocationTest.class, MockNameTest.class, NiceMockControlTest.class,
15        NiceMockControlLongCompatibleReturnValueTest.class, ObjectMethodsTest.class,
16        RecordStateInvalidDefaultReturnValueTest.class, RecordStateInvalidDefaultThrowableTest.class,
17        RecordStateInvalidMatcherTest.class, RecordStateInvalidRangeTest.class,
18        RecordStateInvalidReturnValueTest.class, RecordStateInvalidStateChangeTest.class,
19        RecordStateInvalidThrowableTest.class, RecordStateInvalidUsageTest.class,
20        RecordStateMethodCallMissingTest.class, ReplayStateInvalidCallsTest.class, ReplayStateInvalidUsageTest.class,
21        StacktraceTest.class, UsageCallCountTest.class, UsageDefaultReturnValueTest.class,
22        UsageExpectAndDefaultReturnTest.class, UsageExpectAndDefaultThrowTest.class, UsageExpectAndReturnTest.class,
23        UsageExpectAndThrowTest.class, UsageFloatingPointReturnValueTest.class,
24        UsageLongCompatibleReturnValueTest.class, UsageOverloadedDefaultValueTest.class,
25        UsageOverloadedMethodTest.class, UsageUnorderedTest.class, UsageRangeTest.class, UsageStrictMockTest.class,
26        UsageTest.class, UsageThrowableTest.class, UsageVarargTest.class, UsageVerifyTest.class,
27        org.easymock.tests2.UsageStrictMockTest.class, org.easymock.tests2.UsageTest.class,
28        org.easymock.tests2.StubTest.class, org.easymock.tests2.UsageMatchersTest.class,
29        org.easymock.tests2.NiceMockTest.class, org.easymock.tests2.ConstraintsToStringTest.class,
30        org.easymock.tests2.CallbackTest.class, org.easymock.tests2.CallbackAndArgumentsTest.class,
31        org.easymock.tests2.UsageConstraintsTest.class, org.easymock.tests2.AnswerTest.class,
32        org.easymock.tests2.NameTest.class, org.easymock.tests2.CompareToTest.class })
33public class AllTests {
34}
35
Full Screen
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.tests;
6
7import static org.junit.Assert.*;
8
9import java.io.IOException;
10
11import org.easymock.MockControl;
12import org.easymock.internal.ReplayState;
13import org.junit.Before;
14import org.junit.Test;
15
16public class UsageVerifyTest {
17    private MockControl<IMethods> control;
18
19    private IMethods mock;
20
21    @Before
22    public void setup() {
23        control = MockControl.createControl(IMethods.class);
24        mock = control.getMock();
25    }
26
27    @Test
28    public void twoReturns() {
29        mock.throwsNothing(true);
30        control.setReturnValue("Test");
31        control.setReturnValue("Test2");
32
33        control.replay();
34
35        assertEquals("Test", mock.throwsNothing(true));
36
37        boolean failed = true;
38
39        try {
40            control.verify();
41            failed = false;
42        } catch (AssertionError expected) {
43            assertEquals("\n  Expectation failure on verify:" + "\n    throwsNothing(true): expected: 2, actual: 1",
44                    expected.getMessage());
45            assertTrue("stack trace must be filled in", Util.getStackTrace(expected).indexOf(
46                    ReplayState.class.getName()) == -1);
47        }
48
49        if (!failed)
50            fail("AssertionError expected");
51
52        assertEquals("Test2", mock.throwsNothing(true));
53
54        control.verify();
55
56        try {
57            mock.throwsNothing(true);
58            fail("AssertionError expected");
59        } catch (AssertionError expected) {
60            assertEquals("\n  Unexpected method call throwsNothing(true):"
61                    + "\n    throwsNothing(true): expected: 2, actual: 2 (+1)", expected.getMessage());
62        }
63    }
64
65    @Test
66    public void atLeastTwoReturns() {
67        mock.throwsNothing(true);
68        control.setReturnValue("Test");
69        control.setReturnValue("Test2", MockControl.ONE_OR_MORE);
70
71        control.replay();
72
73        assertEquals("Test", mock.throwsNothing(true));
74
75        try {
76            control.verify();
77            fail("AssertionError expected");
78        } catch (AssertionError expected) {
79
80            assertEquals("\n  Expectation failure on verify:"
81                    + "\n    throwsNothing(true): expected: at least 2, actual: 1", expected.getMessage());
82        }
83
84        assertEquals("Test2", mock.throwsNothing(true));
85        assertEquals("Test2", mock.throwsNothing(true));
86
87        control.verify();
88    }
89
90    @Test
91    public void twoThrows() throws IOException {
92        mock.throwsIOException(0);
93        control.setThrowable(new IOException());
94        control.setThrowable(new IOException());
95        mock.throwsIOException(1);
96        control.setThrowable(new IOException());
97
98        control.replay();
99
100        try {
101            mock.throwsIOException(0);
102            fail("IOException expected");
103        } catch (IOException expected) {
104        }
105
106        try {
107            control.verify();
108            fail("AssertionError expected");
109        } catch (AssertionError expected) {
110            assertEquals("\n  Expectation failure on verify:" + "\n    throwsIOException(0): expected: 2, actual: 1"
111                    + "\n    throwsIOException(1): expected: 1, actual: 0", expected.getMessage());
112        }
113
114        try {
115            mock.throwsIOException(0);
116            fail("IOException expected");
117        } catch (IOException expected) {
118        }
119
120        try {
121            control.verify();
122            fail("AssertionError expected");
123        } catch (AssertionError expected) {
124            assertEquals("\n  Expectation failure on verify:" + "\n    throwsIOException(1): expected: 1, actual: 0",
125                    expected.getMessage());
126        }
127
128        try {
129            mock.throwsIOException(1);
130            fail("IOException expected");
131        } catch (IOException expected) {
132        }
133
134        control.verify();
135
136        try {
137            mock.throwsIOException(0);
138            fail("AssertionError expected");
139        } catch (AssertionError expected) {
140            assertEquals("\n  Unexpected method call throwsIOException(0):"
141                    + "\n    throwsIOException(0): expected: 2, actual: 2 (+1)", expected.getMessage());
142        }
143    }
144}
145
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 popular Stackoverflow questions on UsageVerifyTest

    No relevant questions found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)