-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #360 from yrodiere/mockito-classloader
Always use the classloader of mocked classes when creating/configuring mocks
- Loading branch information
Showing
4 changed files
with
45 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
testing/src/main/java/io/quarkiverse/githubapp/testing/internal/MockitoUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkiverse.githubapp.testing.internal; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class MockitoUtils { | ||
|
||
private MockitoUtils() { | ||
} | ||
|
||
public static <T> T doWithMockedClassClassLoader(Class<?> mockedClass, Supplier<T> action) { | ||
ClassLoader mockedClassClassLoader = mockedClass.getClassLoader(); | ||
ClassLoader old = Thread.currentThread().getContextClassLoader(); | ||
try { | ||
Thread.currentThread().setContextClassLoader(mockedClassClassLoader); | ||
return action.get(); | ||
} finally { | ||
Thread.currentThread().setContextClassLoader(old); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters