File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed
src/main/java/com/google/gwtmockito Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 36
36
<artifactId >javassist</artifactId >
37
37
</dependency >
38
38
39
+ <!-- We don't actually depend on PowerMock, but we put it in the classpath
40
+ for tests to ensure that it doesn't cause a conflict. See
41
+ https://github.com/google/gwtmockito/issues/14. -->
42
+ <dependency >
43
+ <groupId >org.powermock</groupId >
44
+ <artifactId >powermock-api-mockito</artifactId >
45
+ </dependency >
46
+
39
47
</dependencies >
40
48
</project >
Original file line number Diff line number Diff line change @@ -118,6 +118,12 @@ public GwtMockitoTestRunner(Class<?> unitTestClass) throws InitializationError {
118
118
}
119
119
gwtMockitoClassLoader = new GwtMockitoClassLoader (getParentClassloader (), classPool );
120
120
121
+ // Use this custom classloader as the context classloader during the rest of the initialization
122
+ // process so that classes loaded via the context classloader will be compatible with the ones
123
+ // used during test.
124
+ ClassLoader originalClassLoader = Thread .currentThread ().getContextClassLoader ();
125
+ Thread .currentThread ().setContextClassLoader (gwtMockitoClassLoader );
126
+
121
127
try {
122
128
// Reload the test class with our own custom class loader that does things like remove
123
129
// final modifiers, allowing GWT Elements to be mocked. Also load GwtMockito itself so we can
@@ -133,6 +139,8 @@ public GwtMockitoTestRunner(Class<?> unitTestClass) throws InitializationError {
133
139
testClassField .set (this , new TestClass (customLoadedTestClass ));
134
140
} catch (Exception e ) {
135
141
throw new InitializationError (e );
142
+ } finally {
143
+ Thread .currentThread ().setContextClassLoader (originalClassLoader );
136
144
}
137
145
}
138
146
@@ -231,8 +239,11 @@ public void run(RunNotifier notifier) {
231
239
// classloader than the class being mocked.
232
240
ClassLoader originalClassLoader = Thread .currentThread ().getContextClassLoader ();
233
241
Thread .currentThread ().setContextClassLoader (gwtMockitoClassLoader );
234
- super .run (notifier );
235
- Thread .currentThread ().setContextClassLoader (originalClassLoader );
242
+ try {
243
+ super .run (notifier );
244
+ } finally {
245
+ Thread .currentThread ().setContextClassLoader (originalClassLoader );
246
+ }
236
247
}
237
248
238
249
/**
Original file line number Diff line number Diff line change 80
80
<artifactId >gwtmockito</artifactId >
81
81
<version >${project.version} </version >
82
82
</dependency >
83
+
84
+ <!-- We don't actually depend on PowerMock, but we put it in the classpath
85
+ for tests to ensure that it doesn't cause a conflict. See
86
+ https://github.com/google/gwtmockito/issues/14. -->
87
+ <dependency >
88
+ <groupId >org.powermock</groupId >
89
+ <artifactId >powermock-api-mockito</artifactId >
90
+ <version >1.5.1</version >
91
+ <scope >test</scope >
92
+ </dependency >
83
93
</dependencies >
84
94
</dependencyManagement >
85
95
You can’t perform that action at this time.
0 commit comments