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
ac644416
Commit
ac644416
authored
Mar 15, 2018
by
Brian Clozel
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12495 from dreis2211
* pr/12495: Use ApplicationContextRunner in tests
parents
19b72685
ca30739b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
34 deletions
+15
-34
ConditionalOnNotWebApplicationTests.java
...figure/condition/ConditionalOnNotWebApplicationTests.java
+15
-34
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnNotWebApplicationTests.java
View file @
ac644416
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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.
...
...
@@ -16,20 +16,17 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
condition
;
import
org.junit.After
;
import
org.junit.Test
;
import
reactor.core.publisher.Mono
;
import
org.springframework.boot.autoconfigure.web.reactive.MockReactiveWebServerFactory
;
import
org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.web.reactive.server.ReactiveWebServerFactory
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
org.springframework.mock.web.MockServletContext
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
entry
;
...
...
@@ -42,43 +39,27 @@ import static org.assertj.core.api.Assertions.entry;
*/
public
class
ConditionalOnNotWebApplicationTests
{
private
ConfigurableApplicationContext
context
;
@After
public
void
closeContext
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
testNotWebApplicationWithServletContext
()
{
AnnotationConfigWebApplicationContext
ctx
=
new
AnnotationConfigWebApplicationContext
();
ctx
.
register
(
NotWebApplicationConfiguration
.
class
);
ctx
.
setServletContext
(
new
MockServletContext
());
ctx
.
refresh
();
this
.
context
=
ctx
;
assertThat
(
this
.
context
.
getBeansOfType
(
String
.
class
)).
isEmpty
();
new
WebApplicationContextRunner
()
.
withUserConfiguration
(
NotWebApplicationConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
@Test
public
void
testNotWebApplicationWithReactiveContext
()
{
AnnotationConfigReactiveWebApplicationContext
context
=
new
AnnotationConfigReactiveWebApplicationContext
();
context
.
register
(
ReactiveApplicationConfig
.
class
,
NotWebApplicationConfiguration
.
class
);
context
.
refresh
();
this
.
context
=
context
;
assertThat
(
this
.
context
.
getBeansOfType
(
String
.
class
)).
isEmpty
();
new
ReactiveWebApplicationContextRunner
()
.
withUserConfiguration
(
ReactiveApplicationConfig
.
class
,
NotWebApplicationConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
String
.
class
));
}
@Test
public
void
testNotWebApplication
()
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
ctx
.
register
(
NotWebApplicationConfiguration
.
class
);
ctx
.
refresh
();
this
.
context
=
ctx
;
assertThat
(
this
.
context
.
getBeansOfType
(
String
.
class
))
.
containsExactly
(
entry
(
"none"
,
"none"
));
new
ApplicationContextRunner
()
.
withUserConfiguration
(
NotWebApplicationConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
getBeans
(
String
.
class
)
.
containsExactly
(
entry
(
"none"
,
"none"
)));
}
@Configuration
...
...
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