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

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

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.assertSame;
4
5import org.jmock.Expectations;
6import org.jmock.Mockery;
7import org.jmock.api.Imposteriser;
8import org.jmock.test.unit.lib.legacy.CodeGeneratingImposteriserParameterResolver;
9import org.jmock.test.unit.lib.legacy.ImposteriserParameterResolver;
10import org.jmock.testjar.InterfaceFromOtherClassLoader;
11import org.junit.Assert;
12import org.junit.jupiter.params.ParameterizedTest;
13import org.junit.jupiter.params.provider.ArgumentsSource;
14
15public class MockingClassesAcceptanceTests {
16
17    public static final class FinalClass {
18    }
19
20    public static class ClassToMock {
21        public FinalClass returnInstanceOfFinalClass() {
22            return null;
23        }
24    }
25
26    Mockery context = new Mockery();
27
28    @ParameterizedTest
29    @ArgumentsSource(CodeGeneratingImposteriserParameterResolver.class)
30    public void testCanMockClassesWithMethodsThatReturnFinalClasses(Imposteriser imposteriserImpl) {
31        context.setImposteriser(imposteriserImpl);
32
33        final ClassToMock mock = context.mock(ClassToMock.class);
34        final FinalClass result = new FinalClass();
35
36        context.checking(new Expectations() {
37            {
38                oneOf(mock).returnInstanceOfFinalClass();
39                will(returnValue(result));
40            }
41        });
42
43        // This should not crash
44
45        assertSame(result, mock.returnInstanceOfFinalClass());
46    }
47    
48    @SuppressWarnings("rawtypes")
49    @ParameterizedTest
50    @ArgumentsSource(ImposteriserParameterResolver.class)
51    public void testMockClassIsCached(Imposteriser imposteriserImpl) {
52        Class class1 = context.mock(InterfaceFromOtherClassLoader.class,"1").getClass();
53        Class class2 = context.mock(InterfaceFromOtherClassLoader.class,"2").getClass();
54        Assert.assertEquals("Type should be cached", class1, class2);
55    }
56}
57
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)