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
04448d6b
Commit
04448d6b
authored
Sep 17, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
6ec1ac0a
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
21 additions
and
24 deletions
+21
-24
Definition.java
...rg/springframework/boot/test/mock/mockito/Definition.java
+2
-1
DefinitionsParser.java
...ngframework/boot/test/mock/mockito/DefinitionsParser.java
+2
-3
MockBean.java
.../org/springframework/boot/test/mock/mockito/MockBean.java
+1
-2
MockDefinition.java
...pringframework/boot/test/mock/mockito/MockDefinition.java
+3
-2
SpyBean.java
...a/org/springframework/boot/test/mock/mockito/SpyBean.java
+1
-2
DefinitionsParserTests.java
...mework/boot/test/mock/mockito/DefinitionsParserTests.java
+2
-4
MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java
...estFieldForExistingBeanWithQualifierIntegrationTests.java
+4
-4
MockDefinitionTests.java
...framework/boot/test/mock/mockito/MockDefinitionTests.java
+2
-4
MockitoContextCustomizerTests.java
...boot/test/mock/mockito/MockitoContextCustomizerTests.java
+2
-1
SpyDefinitionTests.java
...gframework/boot/test/mock/mockito/SpyDefinitionTests.java
+2
-1
No files found.
spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/Definition.java
View file @
04448d6b
...
...
@@ -38,7 +38,8 @@ abstract class Definition {
private
final
boolean
proxyTargetAware
;
Definition
(
AnnotatedElement
element
,
String
name
,
MockReset
reset
,
boolean
proxyTargetAware
)
{
Definition
(
AnnotatedElement
element
,
String
name
,
MockReset
reset
,
boolean
proxyTargetAware
)
{
this
.
element
=
element
;
this
.
name
=
name
;
this
.
reset
=
(
reset
!=
null
?
reset
:
MockReset
.
AFTER
);
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/DefinitionsParser.java
View file @
04448d6b
...
...
@@ -92,7 +92,7 @@ class DefinitionsParser {
}
for
(
ResolvableType
typeToMock
:
typesToMock
)
{
MockDefinition
definition
=
new
MockDefinition
(
element
,
annotation
.
name
(),
typeToMock
,
annotation
.
extraInterfaces
(),
annotation
.
answer
(),
typeToMock
,
annotation
.
extraInterfaces
(),
annotation
.
answer
(),
annotation
.
serializable
(),
annotation
.
reset
());
addDefinition
(
definition
,
"mock"
);
}
...
...
@@ -113,8 +113,7 @@ class DefinitionsParser {
}
}
private
void
addDefinition
(
Definition
definition
,
String
type
)
{
private
void
addDefinition
(
Definition
definition
,
String
type
)
{
boolean
isNewDefinition
=
this
.
definitions
.
add
(
definition
);
Assert
.
state
(
isNewDefinition
,
"Duplicate "
+
type
+
" definition "
+
definition
);
AnnotatedElement
element
=
definition
.
getElement
();
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockBean.java
View file @
04448d6b
...
...
@@ -66,8 +66,7 @@ import org.springframework.test.context.junit4.SpringRunner;
*
*
* }
* </pre>
* If there is more than one bean of the requested type, qualifier metadata must be
* </pre> If there is more than one bean of the requested type, qualifier metadata must be
* specified at field level: <pre class="code">
* @RunWith(SpringRunner.class)
* public class ExampleTests {
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockDefinition.java
View file @
04448d6b
...
...
@@ -50,8 +50,9 @@ class MockDefinition extends Definition {
private
final
boolean
serializable
;
MockDefinition
(
AnnotatedElement
element
,
String
name
,
ResolvableType
typeToMock
,
Class
<?>[]
extraInterfaces
,
Answers
answer
,
boolean
serializable
,
MockReset
reset
)
{
MockDefinition
(
AnnotatedElement
element
,
String
name
,
ResolvableType
typeToMock
,
Class
<?>[]
extraInterfaces
,
Answers
answer
,
boolean
serializable
,
MockReset
reset
)
{
super
(
element
,
name
,
reset
,
false
);
Assert
.
notNull
(
typeToMock
,
"TypeToMock must not be null"
);
this
.
typeToMock
=
typeToMock
;
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/SpyBean.java
View file @
04448d6b
...
...
@@ -66,8 +66,7 @@ import org.springframework.test.context.junit4.SpringRunner;
*
*
* }
* </pre>
* If there is more than one bean of the requested type, qualifier metadata must be
* </pre> If there is more than one bean of the requested type, qualifier metadata must be
* specified at field level: <pre class="code">
* @RunWith(SpringRunner.class)
* public class ExampleTests {
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/DefinitionsParserTests.java
View file @
04448d6b
...
...
@@ -82,8 +82,7 @@ public class DefinitionsParserTests {
this
.
parser
.
parse
(
MockBeanOnClassAndField
.
class
);
assertThat
(
getDefinitions
()).
hasSize
(
2
);
MockDefinition
classDefinition
=
getMockDefinition
(
0
);
assertThat
(
classDefinition
.
getElement
())
.
isEqualTo
(
MockBeanOnClassAndField
.
class
);
assertThat
(
classDefinition
.
getElement
()).
isEqualTo
(
MockBeanOnClassAndField
.
class
);
assertThat
(
classDefinition
.
getTypeToMock
().
resolve
())
.
isEqualTo
(
ExampleService
.
class
);
MockDefinition
fieldDefinition
=
getMockDefinition
(
1
);
...
...
@@ -161,8 +160,7 @@ public class DefinitionsParserTests {
this
.
parser
.
parse
(
SpyBeanOnClassAndField
.
class
);
assertThat
(
getDefinitions
()).
hasSize
(
2
);
SpyDefinition
classDefinition
=
getSpyDefinition
(
0
);
assertThat
(
classDefinition
.
getElement
())
.
isEqualTo
(
SpyBeanOnClassAndField
.
class
);
assertThat
(
classDefinition
.
getElement
()).
isEqualTo
(
SpyBeanOnClassAndField
.
class
);
assertThat
(
classDefinition
.
getTypeToSpy
().
resolve
())
.
isEqualTo
(
RealExampleService
.
class
);
SpyDefinition
fieldDefinition
=
getSpyDefinition
(
1
);
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests.java
View file @
04448d6b
...
...
@@ -34,8 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
* Test {@link MockBean} on a test class field can be used to replace existing bean
*
while
preserving qualifiers.
* Test {@link MockBean} on a test class field can be used to replace existing bean
while
* preserving qualifiers.
*/
@RunWith
(
SpringRunner
.
class
)
public
class
MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests
{
...
...
@@ -59,8 +59,8 @@ public class MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
@Test
public
void
onlyQualifiedBeanIsReplaced
()
{
assertThat
(
this
.
applicationContext
.
getBean
(
"service"
)).
isSameAs
(
this
.
service
);
ExampleService
anotherService
=
this
.
applicationContext
.
getBean
(
"anotherService"
,
ExampleService
.
class
);
ExampleService
anotherService
=
this
.
applicationContext
.
getBean
(
"anotherService"
,
ExampleService
.
class
);
assertThat
(
anotherService
.
greeting
()).
isEqualTo
(
"Another"
);
}
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockDefinitionTests.java
View file @
04448d6b
...
...
@@ -65,8 +65,7 @@ public class MockDefinitionTests {
@Test
public
void
createExplicit
()
throws
Exception
{
MockDefinition
definition
=
new
MockDefinition
(
getClass
(),
"name"
,
EXAMPLE_SERVICE_TYPE
,
new
Class
<?>[]
{
ExampleExtraInterface
.
class
},
EXAMPLE_SERVICE_TYPE
,
new
Class
<?>[]
{
ExampleExtraInterface
.
class
},
Answers
.
RETURNS_SMART_NULLS
,
true
,
MockReset
.
BEFORE
);
assertThat
(
definition
.
getElement
()).
isEqualTo
(
getClass
());
assertThat
(
definition
.
getName
()).
isEqualTo
(
"name"
);
...
...
@@ -81,8 +80,7 @@ public class MockDefinitionTests {
@Test
public
void
createMock
()
throws
Exception
{
MockDefinition
definition
=
new
MockDefinition
(
null
,
"name"
,
EXAMPLE_SERVICE_TYPE
,
MockDefinition
definition
=
new
MockDefinition
(
null
,
"name"
,
EXAMPLE_SERVICE_TYPE
,
new
Class
<?>[]
{
ExampleExtraInterface
.
class
},
Answers
.
RETURNS_SMART_NULLS
,
true
,
MockReset
.
BEFORE
);
ExampleService
mock
=
definition
.
createMock
();
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoContextCustomizerTests.java
View file @
04448d6b
...
...
@@ -53,7 +53,8 @@ public class MockitoContextCustomizerTests {
}
private
MockDefinition
createTestMockDefinition
(
Class
<?>
typeToMock
)
{
return
new
MockDefinition
(
null
,
null
,
ResolvableType
.
forClass
(
typeToMock
),
null
,
null
,
false
,
null
);
return
new
MockDefinition
(
null
,
null
,
ResolvableType
.
forClass
(
typeToMock
),
null
,
null
,
false
,
null
);
}
}
spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyDefinitionTests.java
View file @
04448d6b
...
...
@@ -52,7 +52,8 @@ public class SpyDefinitionTests {
@Test
public
void
createWithDefaults
()
throws
Exception
{
SpyDefinition
definition
=
new
SpyDefinition
(
null
,
null
,
REAL_SERVICE_TYPE
,
null
,
true
);
SpyDefinition
definition
=
new
SpyDefinition
(
null
,
null
,
REAL_SERVICE_TYPE
,
null
,
true
);
assertThat
(
definition
.
getElement
()).
isNull
();
assertThat
(
definition
.
getName
()).
isNull
();
assertThat
(
definition
.
getTypeToSpy
()).
isEqualTo
(
REAL_SERVICE_TYPE
);
...
...
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