Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
c9427191
Commit
c9427191
authored
Nov 21, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set TCCL before initialising test class in FilteredClassPathRunner
Closes gh-7435
parent
249ed899
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
20 deletions
+53
-20
FilteredClassPathRunner.java
...pringframework/boot/testutil/FilteredClassPathRunner.java
+53
-20
No files found.
spring-boot/src/test/java/org/springframework/boot/testutil/FilteredClassPathRunner.java
View file @
c9427191
...
...
@@ -62,6 +62,19 @@ public class FilteredClassPathRunner extends BlockJUnit4ClassRunner {
}
}
@Override
protected
Object
createTest
()
throws
Exception
{
FilteredTestClass
testClass
=
(
FilteredTestClass
)
getTestClass
();
return
testClass
.
doWithFilteredContextClassLoader
(
new
FilteredTestClass
.
FilteredTcclAction
<
Object
,
Exception
>()
{
@Override
public
Object
perform
()
throws
Exception
{
return
FilteredClassPathRunner
.
super
.
createTest
();
}
});
}
private
URLClassLoader
createTestClassLoader
(
Class
<?>
testClass
)
throws
Exception
{
URLClassLoader
classLoader
=
(
URLClassLoader
)
this
.
getClass
().
getClassLoader
();
return
new
FilteredClassLoader
(
filterUrls
(
extractUrls
(
classLoader
),
testClass
),
...
...
@@ -183,40 +196,60 @@ public class FilteredClassPathRunner extends BlockJUnit4ClassRunner {
List
<
FrameworkMethod
>
wrapped
=
new
ArrayList
<
FrameworkMethod
>(
methods
.
size
());
for
(
FrameworkMethod
frameworkMethod
:
methods
)
{
wrapped
.
add
(
new
FilteredFrameworkMethod
(
this
.
classLoader
,
frameworkMethod
.
getMethod
()));
wrapped
.
add
(
new
FilteredFrameworkMethod
(
frameworkMethod
.
getMethod
()));
}
return
wrapped
;
}
}
/**
* Filtered version of JUnit's {@link FrameworkMethod}.
*/
private
static
final
class
FilteredFrameworkMethod
extends
FrameworkMethod
{
private
final
ClassLoader
classLoader
;
private
FilteredFrameworkMethod
(
ClassLoader
classLoader
,
Method
method
)
{
super
(
method
);
this
.
classLoader
=
classLoader
;
}
@Override
public
Object
invokeExplosively
(
Object
target
,
Object
...
params
)
throws
Throwable
{
private
<
T
,
E
extends
Throwable
>
T
doWithFilteredContextClassLoader
(
FilteredTcclAction
<
T
,
E
>
action
)
throws
E
{
ClassLoader
originalClassLoader
=
Thread
.
currentThread
()
.
getContextClassLoader
();
Thread
.
currentThread
().
setContextClassLoader
(
this
.
classLoader
);
try
{
return
super
.
invokeExplosively
(
target
,
params
);
return
action
.
perform
(
);
}
finally
{
Thread
.
currentThread
().
setContextClassLoader
(
originalClassLoader
);
}
}
/**
* An action to be performed with the {@link FilteredClassLoader} set as the
* thread context class loader.
*/
private
interface
FilteredTcclAction
<
T
,
E
extends
Throwable
>
{
T
perform
()
throws
E
;
}
/**
* Filtered version of JUnit's {@link FrameworkMethod}.
*/
private
final
class
FilteredFrameworkMethod
extends
FrameworkMethod
{
private
FilteredFrameworkMethod
(
Method
method
)
{
super
(
method
);
}
@Override
public
Object
invokeExplosively
(
final
Object
target
,
final
Object
...
params
)
throws
Throwable
{
return
doWithFilteredContextClassLoader
(
new
FilteredTcclAction
<
Object
,
Throwable
>()
{
@Override
public
Object
perform
()
throws
Throwable
{
return
FilteredFrameworkMethod
.
super
.
invokeExplosively
(
target
,
params
);
}
});
}
}
}
private
static
final
class
FilteredClassLoader
extends
URLClassLoader
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment