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
268b97bf
Commit
268b97bf
authored
Jan 05, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No-op ResetMocksTestExecutionListener when Mockito is not present
Closes gh-11508
parent
64101378
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
4 deletions
+13
-4
ResetMocksTestExecutionListener.java
...ot/test/mock/mockito/ResetMocksTestExecutionListener.java
+12
-3
SampleTestNoMockitoApplicationTests.java
...le/testnomockito/SampleTestNoMockitoApplicationTests.java
+1
-1
No files found.
spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java
View file @
268b97bf
/*
/*
* 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");
* 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.
...
@@ -30,6 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext;
...
@@ -30,6 +30,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.test.context.TestContext
;
import
org.springframework.test.context.TestContext
;
import
org.springframework.test.context.TestExecutionListener
;
import
org.springframework.test.context.TestExecutionListener
;
import
org.springframework.test.context.support.AbstractTestExecutionListener
;
import
org.springframework.test.context.support.AbstractTestExecutionListener
;
import
org.springframework.util.ClassUtils
;
/**
/**
* {@link TestExecutionListener} to reset any mock beans that have been marked with a
* {@link TestExecutionListener} to reset any mock beans that have been marked with a
...
@@ -40,15 +41,23 @@ import org.springframework.test.context.support.AbstractTestExecutionListener;
...
@@ -40,15 +41,23 @@ import org.springframework.test.context.support.AbstractTestExecutionListener;
*/
*/
public
class
ResetMocksTestExecutionListener
extends
AbstractTestExecutionListener
{
public
class
ResetMocksTestExecutionListener
extends
AbstractTestExecutionListener
{
private
static
final
boolean
MOCKITO_IS_PRESENT
=
ClassUtils
.
isPresent
(
"org.mockito.MockSettings"
,
ResetMocksTestExecutionListener
.
class
.
getClassLoader
());
@Override
@Override
public
void
beforeTestMethod
(
TestContext
testContext
)
throws
Exception
{
public
void
beforeTestMethod
(
TestContext
testContext
)
throws
Exception
{
if
(
MOCKITO_IS_PRESENT
)
{
resetMocks
(
testContext
.
getApplicationContext
(),
MockReset
.
BEFORE
);
resetMocks
(
testContext
.
getApplicationContext
(),
MockReset
.
BEFORE
);
}
}
}
@Override
@Override
public
void
afterTestMethod
(
TestContext
testContext
)
throws
Exception
{
public
void
afterTestMethod
(
TestContext
testContext
)
throws
Exception
{
if
(
MOCKITO_IS_PRESENT
)
{
resetMocks
(
testContext
.
getApplicationContext
(),
MockReset
.
AFTER
);
resetMocks
(
testContext
.
getApplicationContext
(),
MockReset
.
AFTER
);
}
}
}
private
void
resetMocks
(
ApplicationContext
applicationContext
,
MockReset
reset
)
{
private
void
resetMocks
(
ApplicationContext
applicationContext
,
MockReset
reset
)
{
if
(
applicationContext
instanceof
ConfigurableApplicationContext
)
{
if
(
applicationContext
instanceof
ConfigurableApplicationContext
)
{
...
...
spring-boot-samples/spring-boot-sample-test-nomockito/src/test/java/sample/testnomockito/SampleTestNoMockitoApplicationTest.java
→
spring-boot-samples/spring-boot-sample-test-nomockito/src/test/java/sample/testnomockito/SampleTestNoMockitoApplicationTest
s
.java
View file @
268b97bf
...
@@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
public
class
SampleTestNoMockitoApplicationTest
{
public
class
SampleTestNoMockitoApplicationTest
s
{
// gh-7065
// gh-7065
...
...
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