How to use method of org.jmock.test.acceptance.RedeclaredObjectMethodsAcceptanceTests class

Best Jmock-library code snippet using org.jmock.test.acceptance.RedeclaredObjectMethodsAcceptanceTests.

Run Jmock-library automation tests on LambdaTest cloud grid

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

copy
1package org.jmock.test.acceptance;
2
3import static org.junit.Assert.assertEquals;
4
5import java.util.Vector;
6
7import org.jmock.Expectations;
8import org.jmock.Mockery;
9import org.jmock.api.ExpectationError;
10import org.jmock.api.Imposteriser;
11import org.jmock.test.unit.lib.legacy.CodeGeneratingImposteriserParameterResolver;
12import org.jmock.test.unit.lib.legacy.ImposteriserParameterResolver;
13import org.junit.jupiter.params.ParameterizedTest;
14import org.junit.jupiter.params.provider.ArgumentsSource;
15
16// Fixes issue JMOCK-96
17public class RedeclaredObjectMethodsAcceptanceTests {
18
19    Mockery context = new Mockery();
20
21    public interface MockedInterface {
22        String toString();
23    }
24
25    public static class MockedClass {
26        @Override
27        public String toString() {
28            return "not mocked";
29        }
30    }
31
32    @ParameterizedTest
33    @ArgumentsSource(ImposteriserParameterResolver.class)
34    public void testCanRedeclareObjectMethodsInMockedInterfaces(Imposteriser imposteriserImpl) {
35        context.setImposteriser(imposteriserImpl);
36        MockedInterface mock = context.mock(MockedInterface.class, "X");
37
38        assertEquals("X", mock.toString());
39    }
40
41    @ParameterizedTest
42    @ArgumentsSource(CodeGeneratingImposteriserParameterResolver.class)
43    public void testCanRedeclareObjectMethodsInMockedClasses(Imposteriser imposteriserImpl) {
44
45        context.setImposteriser(imposteriserImpl);
46        MockedClass mock = context.mock(MockedClass.class, "X");
47
48        assertEquals("X", mock.toString());
49    }
50
51    /*
52     * Adapted from Jira issue JMOCK-96
53     */
54    @SuppressWarnings("unchecked")
55    @ParameterizedTest
56    @ArgumentsSource(CodeGeneratingImposteriserParameterResolver.class)
57    public void testUseMockObjectHangs1(Imposteriser imposteriserImpl) {
58
59        context.setImposteriser(imposteriserImpl);
60        final Vector<Object> mock = (Vector<Object>) context.mock(Vector.class);
61
62        context.checking(new Expectations() {
63            {
64                atLeast(1).of(mock).size();
65                will(returnValue(2));
66            }
67        });
68
69        try {
70            for (int i = 0; i < mock.size(); i++) {
71                System.out.println("Vector entry " + i + " = " + mock.get(i));
72            }
73        } catch (ExpectationError error) {
74            // expected
75        }
76    }
77}
78
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)