How to use RealMethod class of org.mockito.internal.invocation package

Best Mockito code snippet using org.mockito.internal.invocation.RealMethod

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Copyright (c) 2017 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal.invocation;
6
7import java.lang.reflect.Method;
8import java.util.concurrent.Callable;
9
10import org.mockito.internal.creation.DelegatingMethod;
11import org.mockito.internal.debugging.LocationImpl;
12import org.mockito.internal.invocation.mockref.MockWeakReference;
13import org.mockito.internal.progress.SequenceNumber;
14import org.mockito.invocation.Invocation;
15import org.mockito.invocation.InvocationFactory;
16import org.mockito.invocation.Location;
17import org.mockito.mock.MockCreationSettings;
18
19public class DefaultInvocationFactory implements InvocationFactory {
20
21    public Invocation createInvocation(
22            Object target,
23            MockCreationSettings settings,
24            Method method,
25            final Callable realMethod,
26            Object... args) {
27        RealMethod superMethod = new RealMethod.FromCallable(realMethod);
28        return createInvocation(target, settings, method, superMethod, args);
29    }
30
31    public Invocation createInvocation(
32            Object target,
33            MockCreationSettings settings,
34            Method method,
35            RealMethodBehavior realMethod,
36            Object... args) {
37        RealMethod superMethod = new RealMethod.FromBehavior(realMethod);
38        return createInvocation(target, settings, method, superMethod, args);
39    }
40
41    private Invocation createInvocation(
42            Object target,
43            MockCreationSettings settings,
44            Method method,
45            RealMethod superMethod,
46            Object[] args) {
47        return createInvocation(target, method, args, superMethod, settings);
48    }
49
50    public static InterceptedInvocation createInvocation(
51            Object mock,
52            Method invokedMethod,
53            Object[] arguments,
54            RealMethod realMethod,
55            MockCreationSettings settings,
56            Location location) {
57        return new InterceptedInvocation(
58                new MockWeakReference<Object>(mock),
59                createMockitoMethod(invokedMethod, settings),
60                arguments,
61                realMethod,
62                location,
63                SequenceNumber.next());
64    }
65
66    private static InterceptedInvocation createInvocation(
67            Object mock,
68            Method invokedMethod,
69            Object[] arguments,
70            RealMethod realMethod,
71            MockCreationSettings settings) {
72        return createInvocation(
73                mock, invokedMethod, arguments, realMethod, settings, new LocationImpl());
74    }
75
76    private static MockitoMethod createMockitoMethod(Method method, MockCreationSettings settings) {
77        if (settings.isSerializable()) {
78            return new SerializableMethod(method);
79        } else {
80            return new DelegatingMethod(method);
81        }
82    }
83}
84
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 RealMethod

    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)