/
NoJUnitDependenciesTest.java
58 lines (48 loc) · 2.17 KB
/
NoJUnitDependenciesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) 2017 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockitointegration;
import static org.mockitoutil.ClassLoaders.coverageTool;
import java.util.Set;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.ByteBuddyAgent;
import org.hamcrest.Matcher;
import org.junit.Assume;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.configuration.plugins.Plugins;
import org.mockitoutil.ClassLoaders;
import org.objenesis.Objenesis;
public class NoJUnitDependenciesTest {
@Test
public void pure_mockito_should_not_depend_JUnit___ByteBuddy() throws Exception {
Assume.assumeTrue(
"ByteBuddyMockMaker".equals(Plugins.getMockMaker().getClass().getSimpleName()));
ClassLoader classLoader_without_JUnit =
ClassLoaders.excludingClassLoader()
.withCodeSourceUrlOf(
Mockito.class,
Matcher.class,
ByteBuddy.class,
ByteBuddyAgent.class,
Objenesis.class)
.withCodeSourceUrlOf(coverageTool())
.without("junit", "org.junit", "org.opentest4j")
.build();
Set<String> pureMockitoAPIClasses =
ClassLoaders.in(classLoader_without_JUnit)
.omit("runners", "junit", "JUnit", "opentest4j")
.listOwnedClasses();
ClassLoadabilityChecker checker = new ClassLoadabilityChecker(classLoader_without_JUnit, "JUnit");
// The later class is required to be initialized before any inline mock maker classes can be
// loaded.
checker.checkLoadability(
"org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker");
pureMockitoAPIClasses.remove(
"org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker");
for (String pureMockitoAPIClass : pureMockitoAPIClasses) {
checker.checkLoadability(pureMockitoAPIClass);
}
}
}