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
d6890e39
Commit
d6890e39
authored
Dec 16, 2020
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.3.x' into 2.4.x
Closes gh-24536
parents
dfcabe16
2cd1459a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
10 deletions
+28
-10
SpringBootTestContextBootstrapper.java
.../boot/test/context/SpringBootTestContextBootstrapper.java
+1
-1
SpringBootTestContextBootstrapperTests.java
...ext/bootstrap/SpringBootTestContextBootstrapperTests.java
+27
-9
No files found.
spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java
View file @
d6890e39
...
...
@@ -135,7 +135,7 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
}
private
void
addConfigAttributesClasses
(
ContextConfigurationAttributes
configAttributes
,
Class
<?>[]
classes
)
{
List
<
Class
<?>>
combined
=
new
ArrayLis
t
<>(
Arrays
.
asList
(
classes
));
Set
<
Class
<?>>
combined
=
new
LinkedHashSe
t
<>(
Arrays
.
asList
(
classes
));
if
(
configAttributes
.
getClasses
()
!=
null
)
{
combined
.
addAll
(
Arrays
.
asList
(
configAttributes
.
getClasses
()));
}
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperTests.java
View file @
d6890e39
...
...
@@ -23,6 +23,7 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
;
import
org.springframework.test.context.BootstrapContext
;
import
org.springframework.test.context.CacheAwareContextLoaderDelegate
;
import
org.springframework.test.context.MergedContextConfiguration
;
import
org.springframework.test.context.TestContext
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.test.util.ReflectionTestUtils
;
...
...
@@ -56,39 +57,47 @@ class SpringBootTestContextBootstrapperTests {
@Test
void
mergedContextConfigurationWhenArgsDifferentShouldNotBeConsideredEqual
()
{
TestContext
context
=
buildTestContext
(
SpringBootTestArgsConfiguration
.
class
);
Object
contextConfiguration
=
ReflectionTestUtils
.
getField
(
context
,
"mergedContextConfiguration"
);
MergedContextConfiguration
contextConfiguration
=
getMergedContextConfiguration
(
context
);
TestContext
otherContext2
=
buildTestContext
(
SpringBootTestOtherArgsConfiguration
.
class
);
Object
otherContextConfiguration
=
ReflectionTestUtils
.
getField
(
otherContext2
,
"mergedContextConfiguration"
);
MergedContextConfiguration
otherContextConfiguration
=
getMergedContextConfiguration
(
otherContext2
);
assertThat
(
contextConfiguration
).
isNotEqualTo
(
otherContextConfiguration
);
}
@Test
void
mergedContextConfigurationWhenArgsSameShouldBeConsideredEqual
()
{
TestContext
context
=
buildTestContext
(
SpringBootTestArgsConfiguration
.
class
);
Object
contextConfiguration
=
ReflectionTestUtils
.
getField
(
context
,
"mergedContextConfiguration"
);
MergedContextConfiguration
contextConfiguration
=
getMergedContextConfiguration
(
context
);
TestContext
otherContext2
=
buildTestContext
(
SpringBootTestSameArgsConfiguration
.
class
);
Object
otherContextConfiguration
=
ReflectionTestUtils
.
getField
(
otherContext2
,
"mergedContextConfiguration"
);
MergedContextConfiguration
otherContextConfiguration
=
getMergedContextConfiguration
(
otherContext2
);
assertThat
(
contextConfiguration
).
isEqualTo
(
otherContextConfiguration
);
}
@Test
void
mergedContextConfigurationWhenWebEnvironmentsDifferentShouldNotBeConsideredEqual
()
{
TestContext
context
=
buildTestContext
(
SpringBootTestMockWebEnvironmentConfiguration
.
class
);
Object
contextConfiguration
=
ReflectionTestUtils
.
getField
(
context
,
"mergedContextConfiguration"
);
MergedContextConfiguration
contextConfiguration
=
getMergedContextConfiguration
(
context
);
TestContext
otherContext
=
buildTestContext
(
SpringBootTestDefinedPortWebEnvironmentConfiguration
.
class
);
Object
otherContextConfiguration
=
ReflectionTestUtils
.
getField
(
otherContext
,
"mergedContextConfiguration"
);
MergedContextConfiguration
otherContextConfiguration
=
getMergedContextConfiguration
(
otherContext
);
assertThat
(
contextConfiguration
).
isNotEqualTo
(
otherContextConfiguration
);
}
@Test
void
mergedContextConfigurationWhenWebEnvironmentsSameShould
t
BeConsideredEqual
()
{
void
mergedContextConfigurationWhenWebEnvironmentsSameShouldBeConsideredEqual
()
{
TestContext
context
=
buildTestContext
(
SpringBootTestMockWebEnvironmentConfiguration
.
class
);
Object
contextConfiguration
=
ReflectionTestUtils
.
getField
(
context
,
"mergedContextConfiguration"
);
MergedContextConfiguration
contextConfiguration
=
getMergedContextConfiguration
(
context
);
TestContext
otherContext
=
buildTestContext
(
SpringBootTestAnotherMockWebEnvironmentConfiguration
.
class
);
Object
otherContextConfiguration
=
ReflectionTestUtils
.
getField
(
otherContext
,
"mergedContextConfiguration"
);
MergedContextConfiguration
otherContextConfiguration
=
getMergedContextConfiguration
(
otherContext
);
assertThat
(
contextConfiguration
).
isEqualTo
(
otherContextConfiguration
);
}
@Test
void
mergedContextConfigurationClassesShouldNotContainDuplicates
()
{
TestContext
context
=
buildTestContext
(
SpringBootTestClassesConfiguration
.
class
);
MergedContextConfiguration
contextConfiguration
=
getMergedContextConfiguration
(
context
);
Class
<?>[]
classes
=
contextConfiguration
.
getClasses
();
assertThat
(
classes
).
containsExactly
(
SpringBootTestContextBootstrapperExampleConfig
.
class
);
}
@SuppressWarnings
(
"rawtypes"
)
private
TestContext
buildTestContext
(
Class
<?>
testClass
)
{
SpringBootTestContextBootstrapper
bootstrapper
=
new
SpringBootTestContextBootstrapper
();
...
...
@@ -100,6 +109,10 @@ class SpringBootTestContextBootstrapperTests {
return
bootstrapper
.
buildTestContext
();
}
private
MergedContextConfiguration
getMergedContextConfiguration
(
TestContext
context
)
{
return
(
MergedContextConfiguration
)
ReflectionTestUtils
.
getField
(
context
,
"mergedContextConfiguration"
);
}
@SpringBootTest
(
webEnvironment
=
WebEnvironment
.
RANDOM_PORT
)
@WebAppConfiguration
static
class
SpringBootTestNonMockWebEnvironmentAndWebAppConfiguration
{
...
...
@@ -142,4 +155,9 @@ class SpringBootTestContextBootstrapperTests {
}
@SpringBootTest
(
classes
=
SpringBootTestContextBootstrapperExampleConfig
.
class
)
static
class
SpringBootTestClassesConfiguration
{
}
}
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