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
21a25ce8
Commit
21a25ce8
authored
Sep 14, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Fail fast if @WebAppConfiguration and @SpringBootTest are used together"
This reverts commit
c54cdd67
.
parent
a68cf773
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
128 deletions
+47
-128
SpringBootTestContextBootstrapper.java
.../boot/test/context/SpringBootTestContextBootstrapper.java
+0
-15
SpringBootTestContextBootstrapperExampleConfig.java
...strap/SpringBootTestContextBootstrapperExampleConfig.java
+1
-1
SpringBootTestContextBootstrapperIntegrationTests.java
...ap/SpringBootTestContextBootstrapperIntegrationTests.java
+0
-82
SpringBootTestContextBootstrapperTests.java
...ext/bootstrap/SpringBootTestContextBootstrapperTests.java
+46
-30
No files found.
spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextBootstrapper.java
View file @
21a25ce8
...
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
boot
.
test
.
context
;
import
java.lang.annotation.Annotation
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
...
...
@@ -73,7 +72,6 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
@Override
public
TestContext
buildTestContext
()
{
TestContext
context
=
super
.
buildTestContext
();
verifyConfiguration
(
context
.
getTestClass
());
WebEnvironment
webEnvironment
=
getWebEnvironment
(
context
.
getTestClass
());
if
(
webEnvironment
==
WebEnvironment
.
MOCK
&&
hasWebEnvironmentClasses
())
{
context
.
setAttribute
(
ACTIVATE_SERVLET_LISTENER
,
true
);
...
...
@@ -248,19 +246,6 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
return
AnnotatedElementUtils
.
getMergedAnnotation
(
testClass
,
SpringBootTest
.
class
);
}
protected
void
verifyConfiguration
(
Class
<?>
testClass
)
{
if
(
getAnnotation
(
testClass
)
!=
null
&&
getAnnotation
(
WebAppConfiguration
.
class
,
testClass
)
!=
null
)
{
throw
new
IllegalStateException
(
"@WebAppConfiguration is unnecessary when "
+
"using @SpringBootTest and should be removed"
);
}
}
private
<
T
extends
Annotation
>
T
getAnnotation
(
Class
<
T
>
annotationType
,
Class
<?>
testClass
)
{
return
AnnotatedElementUtils
.
getMergedAnnotation
(
testClass
,
annotationType
);
}
/**
* Create a new {@link MergedContextConfiguration} with different classes.
* @param mergedConfig the source config
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperExampleConfig.java
View file @
21a25ce8
...
...
@@ -19,7 +19,7 @@ package org.springframework.boot.test.context.bootstrap;
import
org.springframework.boot.SpringBootConfiguration
;
/**
* Example configuration used in {@link SpringBootTestContextBootstrapper
Integration
Tests}.
* Example configuration used in {@link SpringBootTestContextBootstrapperTests}.
*
* @author Phillip Webb
*/
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperIntegrationTests.java
deleted
100644 → 0
View file @
a68cf773
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
context
.
bootstrap
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
;
import
org.springframework.boot.test.context.TestConfiguration
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Component
;
import
org.springframework.test.context.BootstrapWith
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link SpringBootTestContextBootstrapper} (in its own package so
* we can test detection).
*
* @author Phillip Webb
*/
@RunWith
(
SpringRunner
.
class
)
@BootstrapWith
(
SpringBootTestContextBootstrapper
.
class
)
public
class
SpringBootTestContextBootstrapperIntegrationTests
{
@Autowired
private
ApplicationContext
context
;
@Autowired
private
SpringBootTestContextBootstrapperExampleConfig
config
;
@Test
public
void
findConfigAutomatically
()
throws
Exception
{
assertThat
(
this
.
config
).
isNotNull
();
}
@Test
public
void
contextWasCreatedViaSpringApplication
()
throws
Exception
{
assertThat
(
this
.
context
.
getId
()).
startsWith
(
"application:"
);
}
@Test
public
void
testConfigurationWasApplied
()
throws
Exception
{
assertThat
(
this
.
context
.
getBean
(
ExampleBean
.
class
)).
isNotNull
();
}
@TestConfiguration
static
class
TestConfig
{
@Bean
public
ExampleBean
exampleBean
()
{
return
new
ExampleBean
();
}
}
static
class
ExampleBean
{
}
@Component
static
class
ExampleTestComponent
{
}
}
spring-boot-test/src/test/java/org/springframework/boot/test/context/bootstrap/SpringBootTestContextBootstrapperTests.java
View file @
21a25ce8
...
...
@@ -16,51 +16,67 @@
package
org
.
springframework
.
boot
.
test
.
context
.
bootstrap
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.ru
les.ExpectedException
;
import
org.junit.ru
nner.RunWith
;
import
org.springframework.b
oot.test.context.SpringBootTest
;
import
org.springframework.b
eans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
;
import
org.springframework.test.context.BootstrapContext
;
import
org.springframework.test.context.CacheAwareContextLoaderDelegate
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.boot.test.context.TestConfiguration
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.stereotype.Component
;
import
org.springframework.test.context.BootstrapWith
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link SpringBootTestContextBootstrapper}.
* Tests for {@link SpringBootTestContextBootstrapper} (in its own package so we can test
* detection).
*
* @author
Andy Wilkinson
* @author
Phillip Webb
*/
@RunWith
(
SpringRunner
.
class
)
@BootstrapWith
(
SpringBootTestContextBootstrapper
.
class
)
public
class
SpringBootTestContextBootstrapperTests
{
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
@Autowired
private
ApplicationContext
context
;
@Autowired
private
SpringBootTestContextBootstrapperExampleConfig
config
;
@SuppressWarnings
(
"rawtypes"
)
@Test
public
void
failFastWhenSpringBootTestAndWebAppConfigurationAreUsedTogether
()
{
SpringBootTestContextBootstrapper
bootstrapper
=
new
SpringBootTestContextBootstrapper
();
BootstrapContext
bootstrapContext
=
mock
(
BootstrapContext
.
class
);
bootstrapper
.
setBootstrapContext
(
bootstrapContext
);
given
((
Class
)
bootstrapContext
.
getTestClass
())
.
willReturn
(
SpringBootTestAndWebAppConfiguration
.
class
);
CacheAwareContextLoaderDelegate
contextLoaderDeleagte
=
mock
(
CacheAwareContextLoaderDelegate
.
class
);
given
(
bootstrapContext
.
getCacheAwareContextLoaderDelegate
())
.
willReturn
(
contextLoaderDeleagte
);
this
.
thrown
.
expect
(
IllegalStateException
.
class
);
this
.
thrown
.
expectMessage
(
"@WebAppConfiguration is unnecessary when using "
+
"@SpringBootTest and should be removed"
);
bootstrapper
.
buildTestContext
();
public
void
findConfigAutomatically
()
throws
Exception
{
assertThat
(
this
.
config
).
isNotNull
();
}
@SpringBootTest
@WebAppConfiguration
private
static
class
SpringBootTestAndWebAppConfiguration
{
@Test
public
void
contextWasCreatedViaSpringApplication
()
throws
Exception
{
assertThat
(
this
.
context
.
getId
()).
startsWith
(
"application:"
);
}
@Test
public
void
testConfigurationWasApplied
()
throws
Exception
{
assertThat
(
this
.
context
.
getBean
(
ExampleBean
.
class
)).
isNotNull
();
}
@TestConfiguration
static
class
TestConfig
{
@Bean
public
ExampleBean
exampleBean
()
{
return
new
ExampleBean
();
}
}
static
class
ExampleBean
{
}
@Component
static
class
ExampleTestComponent
{
}
}
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