How to use DefaultMockitoSession class of org.mockito.internal.framework package

Best Mockito code snippet using org.mockito.internal.framework.DefaultMockitoSession

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1package org.mockito.internal.framework;
2
3import java.util.List;
4import org.mockito.Mockito;
5import org.mockito.MockitoAnnotations;
6import org.mockito.MockitoSession;
7import org.mockito.exceptions.misusing.RedundantListenerException;
8import org.mockito.internal.exceptions.Reporter;
9import org.mockito.internal.junit.TestFinishedEvent;
10import org.mockito.internal.junit.UniversalTestListener;
11import org.mockito.plugins.MockitoLogger;
12import org.mockito.quality.Strictness;
13
14public class DefaultMockitoSession implements MockitoSession {
15    private final UniversalTestListener listener;
16    /* access modifiers changed from: private */
17    public final String name;
18
19    public DefaultMockitoSession(List<Object> list, String str, Strictness strictness, MockitoLogger mockitoLogger) {
20        this.name = str;
21        this.listener = new UniversalTestListener(strictness, mockitoLogger);
22        try {
23            Mockito.framework().addListener(this.listener);
24        } catch (RedundantListenerException unused) {
25            Reporter.unfinishedMockingSession();
26        }
27        try {
28            for (Object initMocks : list) {
29                MockitoAnnotations.initMocks(initMocks);
30            }
31        } catch (RuntimeException e) {
32            this.listener.setListenerDirty();
33            throw e;
34        }
35    }
36
37    public void setStrictness(Strictness strictness) {
38        this.listener.setStrictness(strictness);
39    }
40
41    public void finishMocking() {
42        finishMocking((Throwable) null);
43    }
44
45    public void finishMocking(final Throwable th) {
46        Mockito.framework().removeListener(this.listener);
47        this.listener.testFinished(new TestFinishedEvent() {
48            public Throwable getFailure() {
49                return th;
50            }
51
52            public String getTestName() {
53                return DefaultMockitoSession.this.name;
54            }
55        });
56        if (th == null) {
57            Mockito.validateMockitoUsage();
58        }
59    }
60}
61
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 DefaultMockitoSession

    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)