How to use NoByteCodeDependenciesTest class of org.mockitointegration package

Best Mockito code snippet using org.mockitointegration.NoByteCodeDependenciesTest

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1/*
2 * Copyright (c) 2019 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockitointegration;
6
7import org.hamcrest.Matcher;
8import org.junit.*;
9import org.mockito.Mockito;
10import org.mockitoutil.ClassLoaders;
11
12import java.util.Set;
13
14import static org.mockitoutil.ClassLoaders.coverageTool;
15
16public class NoByteCodeDependenciesTest {
17
18    private ClassLoader contextClassLoader;
19
20    @Test
21    public void pure_mockito_should_not_depend_bytecode_libraries() throws Exception {
22
23        ClassLoader classLoader_without_bytecode_libraries = ClassLoaders.excludingClassLoader()
24            .withCodeSourceUrlOf(
25                Mockito.class,
26                Matcher.class
27            )
28            .withCodeSourceUrlOf(coverageTool())
29            .without("net.bytebuddy", "org.objenesis")
30            .build();
31
32        Set<String> pureMockitoAPIClasses = ClassLoaders.in(classLoader_without_bytecode_libraries).omit(
33            "bytebuddy", "runners", "junit", "JUnit", "opentest4j").listOwnedClasses();
34        pureMockitoAPIClasses.remove("org.mockito.internal.creation.instance.DefaultInstantiatorProvider");
35        pureMockitoAPIClasses.remove("org.mockito.internal.creation.instance.ObjenesisInstantiator");
36
37        // Remove classes that trigger plugin-loading, since bytebuddy plugins are the default.
38        pureMockitoAPIClasses.remove("org.mockito.internal.debugging.LocationImpl");
39        pureMockitoAPIClasses.remove("org.mockito.internal.exceptions.stacktrace.StackTraceFilter");
40        pureMockitoAPIClasses.remove("org.mockito.internal.util.MockUtil");
41
42        for (String pureMockitoAPIClass : pureMockitoAPIClasses) {
43            checkDependency(classLoader_without_bytecode_libraries, pureMockitoAPIClass);
44        }
45    }
46
47    private void checkDependency(ClassLoader classLoader, String pureMockitoAPIClass) throws ClassNotFoundException {
48        try {
49            Class.forName(pureMockitoAPIClass, true, classLoader);
50        } catch (Throwable e) {
51            e.printStackTrace();
52            throw new AssertionError(String.format("'%s' has some dependency to Byte Buddy or Objenesis", pureMockitoAPIClass));
53        }
54    }
55}
56
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 NoByteCodeDependenciesTest

    No relevant questions found for this class 😞

Most used methods in NoByteCodeDependenciesTest

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)