How to use method of org.mockito.internal.MockedConstructionImpl class

Best Mockito code snippet using org.mockito.internal.MockedConstructionImpl.

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal;
6
7import java.util.Collections;
8import java.util.List;
9
10import org.mockito.MockedConstruction;
11import org.mockito.exceptions.base.MockitoException;
12import org.mockito.internal.debugging.LocationImpl;
13import org.mockito.invocation.Location;
14import org.mockito.plugins.MockMaker;
15
16import static org.mockito.internal.util.StringUtil.*;
17
18public final class MockedConstructionImpl<T> implements MockedConstruction<T> {
19
20    private final MockMaker.ConstructionMockControl<T> control;
21
22    private boolean closed;
23
24    private final Location location = new LocationImpl();
25
26    protected MockedConstructionImpl(MockMaker.ConstructionMockControl<T> control) {
27        this.control = control;
28    }
29
30    @Override
31    public List<T> constructed() {
32        return Collections.unmodifiableList(control.getMocks());
33    }
34
35    @Override
36    public boolean isClosed() {
37        return closed;
38    }
39
40    @Override
41    public void close() {
42        assertNotClosed();
43
44        closed = true;
45        control.disable();
46    }
47
48    @Override
49    public void closeOnDemand() {
50        if (!closed) {
51            close();
52        }
53    }
54
55    private void assertNotClosed() {
56        if (closed) {
57            throw new MockitoException(
58                    join(
59                            "The static mock created at",
60                            location.toString(),
61                            "is already resolved and cannot longer be used"));
62        }
63    }
64}
65
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)