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
b7080dde
Commit
b7080dde
authored
Jul 24, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Ensure SpringBootDITEL fails with the original failure"
parent
2c480876
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
11 deletions
+33
-11
SpringBootDependencyInjectionTestExecutionListener.java
...e/SpringBootDependencyInjectionTestExecutionListener.java
+16
-11
SpringBootDependencyInjectionTestExecutionListenerTests.java
...ingBootDependencyInjectionTestExecutionListenerTests.java
+17
-0
No files found.
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListener.java
View file @
b7080dde
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -44,20 +44,25 @@ public class SpringBootDependencyInjectionTestExecutionListener
...
@@ -44,20 +44,25 @@ public class SpringBootDependencyInjectionTestExecutionListener
super
.
prepareTestInstance
(
testContext
);
super
.
prepareTestInstance
(
testContext
);
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
try
{
outputConditionEvaluationReport
(
testContext
);
ApplicationContext
context
=
testContext
.
getApplicationContext
();
if
(
context
instanceof
ConfigurableApplicationContext
)
{
ConditionEvaluationReport
report
=
ConditionEvaluationReport
.
get
(((
ConfigurableApplicationContext
)
context
).
getBeanFactory
());
System
.
err
.
println
(
new
ConditionEvaluationReportMessage
(
report
));
}
}
catch
(
Exception
ignore
)
{
}
throw
ex
;
throw
ex
;
}
}
}
}
private
void
outputConditionEvaluationReport
(
TestContext
testContext
)
{
try
{
ApplicationContext
context
=
testContext
.
getApplicationContext
();
if
(
context
instanceof
ConfigurableApplicationContext
)
{
ConditionEvaluationReport
report
=
ConditionEvaluationReport
.
get
(((
ConfigurableApplicationContext
)
context
).
getBeanFactory
());
System
.
err
.
println
(
new
ConditionEvaluationReportMessage
(
report
));
}
}
catch
(
Exception
ex
)
{
// Allow original failure to be reported
}
}
static
class
PostProcessor
implements
DefaultTestExecutionListenersPostProcessor
{
static
class
PostProcessor
implements
DefaultTestExecutionListenersPostProcessor
{
@Override
@Override
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/SpringBootDependencyInjectionTestExecutionListenerTests.java
View file @
b7080dde
...
@@ -18,6 +18,7 @@ package org.springframework.boot.test.autoconfigure;
...
@@ -18,6 +18,7 @@ package org.springframework.boot.test.autoconfigure;
import
org.junit.Rule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
...
@@ -30,6 +31,7 @@ import org.springframework.test.context.TestContext;
...
@@ -30,6 +31,7 @@ import org.springframework.test.context.TestContext;
import
org.springframework.test.context.support.DependencyInjectionTestExecutionListener
;
import
org.springframework.test.context.support.DependencyInjectionTestExecutionListener
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
@@ -44,6 +46,9 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
...
@@ -44,6 +46,9 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
@Rule
@Rule
public
OutputCapture
out
=
new
OutputCapture
();
public
OutputCapture
out
=
new
OutputCapture
();
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
private
SpringBootDependencyInjectionTestExecutionListener
reportListener
=
new
SpringBootDependencyInjectionTestExecutionListener
();
private
SpringBootDependencyInjectionTestExecutionListener
reportListener
=
new
SpringBootDependencyInjectionTestExecutionListener
();
@Test
@Test
...
@@ -73,6 +78,18 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
...
@@ -73,6 +78,18 @@ public class SpringBootDependencyInjectionTestExecutionListenerTests {
this
.
out
.
expect
(
containsString
(
"Negative matches"
));
this
.
out
.
expect
(
containsString
(
"Negative matches"
));
}
}
@Test
public
void
originalFailureIsThrownWhenReportGenerationFails
()
throws
Exception
{
TestContext
testContext
=
mock
(
TestContext
.
class
);
IllegalStateException
originalFailure
=
new
IllegalStateException
();
given
(
testContext
.
getTestInstance
()).
willThrow
(
originalFailure
);
SpringApplication
application
=
new
SpringApplication
(
Config
.
class
);
application
.
setWebEnvironment
(
false
);
given
(
testContext
.
getApplicationContext
()).
willThrow
(
new
RuntimeException
());
this
.
thrown
.
expect
(
is
(
originalFailure
));
this
.
reportListener
.
prepareTestInstance
(
testContext
);
}
@Configuration
@Configuration
@ImportAutoConfiguration
(
JacksonAutoConfiguration
.
class
)
@ImportAutoConfiguration
(
JacksonAutoConfiguration
.
class
)
static
class
Config
{
static
class
Config
{
...
...
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