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
80bb7ea9
Commit
80bb7ea9
authored
Oct 23, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
1651690d
bc58d445
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
59 deletions
+32
-59
DefaultRestartInitializer.java
...work/boot/devtools/restart/DefaultRestartInitializer.java
+1
-1
DefaultRestartInitializerTests.java
...boot/devtools/restart/DefaultRestartInitializerTests.java
+31
-58
No files found.
spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/DefaultRestartInitializer.java
View file @
80bb7ea9
...
@@ -73,7 +73,7 @@ public class DefaultRestartInitializer implements RestartInitializer {
...
@@ -73,7 +73,7 @@ public class DefaultRestartInitializer implements RestartInitializer {
* @return {@code true} if the stack element means that the initializer should be
* @return {@code true} if the stack element means that the initializer should be
* skipped
* skipped
*/
*/
pr
otected
boolean
isSkippedStackElement
(
StackTraceElement
element
)
{
pr
ivate
boolean
isSkippedStackElement
(
StackTraceElement
element
)
{
for
(
String
skipped
:
SKIPPED_STACK_ELEMENTS
)
{
for
(
String
skipped
:
SKIPPED_STACK_ELEMENTS
)
{
if
(
element
.
getClassName
().
startsWith
(
skipped
))
{
if
(
element
.
getClassName
().
startsWith
(
skipped
))
{
return
true
;
return
true
;
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/DefaultRestartInitializerTests.java
View file @
80bb7ea9
...
@@ -16,87 +16,83 @@
...
@@ -16,87 +16,83 @@
package
org
.
springframework
.
boot
.
devtools
.
restart
;
package
org
.
springframework
.
boot
.
devtools
.
restart
;
import
java.net.URL
;
import
org.junit.Test
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
* Tests for {@link DefaultRestartInitializer}.
* Tests for {@link DefaultRestartInitializer}.
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Madhura Bhave
*/
*/
public
class
DefaultRestartInitializerTests
{
public
class
DefaultRestartInitializerTests
{
@Test
@Test
public
void
nullForTests
()
{
public
void
jUnitStackShouldReturnNull
()
{
MockRestartInitializer
initializer
=
new
MockRestartInitializer
(
true
);
testSkippedStacks
(
"org.junit.runners.Something"
);
assertThat
(
initializer
.
getInitialUrls
(
Thread
.
currentThread
())).
isNull
();
}
@Test
public
void
springTestStackShouldReturnNull
()
{
testSkippedStacks
(
"org.springframework.boot.test.Something"
);
}
@Test
public
void
cucumberStackShouldReturnNull
()
{
testSkippedStacks
(
"cucumber.runtime.Runtime.run"
);
}
}
@Test
@Test
public
void
validMainThread
()
{
public
void
validMainThread
ShouldReturnUrls
()
{
MockRestartInitializer
initializer
=
new
MockRestartInitializer
(
false
);
DefaultRestartInitializer
initializer
=
new
DefaultRestartInitializer
(
);
ClassLoader
classLoader
=
new
MockAppClassLoader
(
getClass
().
getClassLoader
());
ClassLoader
classLoader
=
new
MockAppClassLoader
(
getClass
().
getClassLoader
());
Thread
thread
=
new
Thread
();
Thread
thread
=
new
Thread
();
thread
.
setName
(
"main"
);
thread
.
setName
(
"main"
);
thread
.
setContextClassLoader
(
classLoader
);
thread
.
setContextClassLoader
(
classLoader
);
assertThat
(
initializer
.
isMain
(
thread
)).
isTrue
();
assertThat
(
initializer
.
getInitialUrls
(
thread
)).
isNotNull
();
assertThat
(
initializer
.
getInitialUrls
(
thread
)).
isNotEqualTo
(
nullValue
());
}
}
@Test
@Test
public
void
threadNotNamedMain
()
{
public
void
threadNotNamedMain
ShouldReturnNull
()
{
MockRestartInitializer
initializer
=
new
MockRestartInitializer
(
false
);
DefaultRestartInitializer
initializer
=
new
DefaultRestartInitializer
(
);
ClassLoader
classLoader
=
new
MockAppClassLoader
(
getClass
().
getClassLoader
());
ClassLoader
classLoader
=
new
MockAppClassLoader
(
getClass
().
getClassLoader
());
Thread
thread
=
new
Thread
();
Thread
thread
=
new
Thread
();
thread
.
setName
(
"buscuit"
);
thread
.
setName
(
"buscuit"
);
thread
.
setContextClassLoader
(
classLoader
);
thread
.
setContextClassLoader
(
classLoader
);
assertThat
(
initializer
.
isMain
(
thread
)).
isFalse
();
assertThat
(
initializer
.
getInitialUrls
(
thread
)).
isNull
();
assertThat
(
initializer
.
getInitialUrls
(
thread
)).
isNull
();
}
}
@Test
@Test
public
void
threadNotUsingAppClassLoader
()
{
public
void
threadNotUsingAppClassLoader
()
{
MockRestartInitializer
initializer
=
new
MockRestartInitializer
(
false
);
DefaultRestartInitializer
initializer
=
new
DefaultRestartInitializer
(
);
ClassLoader
classLoader
=
new
MockLauncherClassLoader
(
ClassLoader
classLoader
=
new
MockLauncherClassLoader
(
getClass
().
getClassLoader
());
getClass
().
getClassLoader
());
Thread
thread
=
new
Thread
();
Thread
thread
=
new
Thread
();
thread
.
setName
(
"main"
);
thread
.
setName
(
"main"
);
thread
.
setContextClassLoader
(
classLoader
);
thread
.
setContextClassLoader
(
classLoader
);
assertThat
(
initializer
.
isMain
(
thread
)).
isFalse
();
assertThat
(
initializer
.
getInitialUrls
(
thread
)).
isNull
();
assertThat
(
initializer
.
getInitialUrls
(
thread
)).
isNull
();
}
}
@Test
public
void
skipsDueToJUnitStacks
()
{
testSkipStack
(
"org.junit.runners.Something"
,
true
);
}
@Test
public
void
skipsDueToSpringTest
()
{
testSkipStack
(
"org.springframework.boot.test.Something"
,
true
);
}
@Test
public
void
skipsDueToCucumber
()
{
testSkipStack
(
"cucumber.runtime.Runtime.run"
,
true
);
}
@Test
@Test
public
void
urlsCanBeRetrieved
()
{
public
void
urlsCanBeRetrieved
()
{
assertThat
(
new
DefaultRestartInitializer
().
getUrls
(
Thread
.
currentThread
()))
assertThat
(
new
DefaultRestartInitializer
().
getUrls
(
Thread
.
currentThread
()))
.
isNotEmpty
();
.
isNotEmpty
();
}
}
private
void
testSkipStack
(
String
className
,
boolean
expected
)
{
protected
void
testSkippedStacks
(
String
s
)
{
MockRestartInitializer
initializer
=
new
MockRestartInitializer
(
true
);
DefaultRestartInitializer
initializer
=
new
DefaultRestartInitializer
();
StackTraceElement
element
=
new
StackTraceElement
(
className
,
"someMethod"
,
ClassLoader
classLoader
=
new
MockAppClassLoader
(
getClass
().
getClassLoader
());
"someFile"
,
123
);
Thread
thread
=
mock
(
Thread
.
class
);
assertThat
(
initializer
.
isSkippedStackElement
(
element
)).
isEqualTo
(
expected
);
thread
.
setName
(
"main"
);
StackTraceElement
element
=
new
StackTraceElement
(
s
,
"someMethod"
,
"someFile"
,
123
);
given
(
thread
.
getStackTrace
()).
willReturn
(
new
StackTraceElement
[]
{
element
});
given
(
thread
.
getContextClassLoader
()).
willReturn
(
classLoader
);
assertThat
(
initializer
.
getInitialUrls
(
thread
)).
isEqualTo
(
null
);
}
}
private
static
class
MockAppClassLoader
extends
ClassLoader
{
private
static
class
MockAppClassLoader
extends
ClassLoader
{
...
@@ -115,27 +111,4 @@ public class DefaultRestartInitializerTests {
...
@@ -115,27 +111,4 @@ public class DefaultRestartInitializerTests {
}
}
private
static
class
MockRestartInitializer
extends
DefaultRestartInitializer
{
private
final
boolean
considerStackElements
;
MockRestartInitializer
(
boolean
considerStackElements
)
{
this
.
considerStackElements
=
considerStackElements
;
}
@Override
protected
boolean
isSkippedStackElement
(
StackTraceElement
element
)
{
if
(!
this
.
considerStackElements
)
{
return
false
;
}
return
true
;
}
@Override
protected
URL
[]
getUrls
(
Thread
thread
)
{
return
new
URL
[
0
];
}
}
}
}
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