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
c28ff431
Commit
c28ff431
authored
Jan 04, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade to Mockito 2
Closes gh-7770
parent
ad2ff272
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
205 additions
and
65 deletions
+205
-65
MessageChannelMetricWriterTests.java
...tuate/metrics/writer/MessageChannelMetricWriterTests.java
+2
-2
AbstractHttpClientMockTests.java
...rk/boot/cli/command/init/AbstractHttpClientMockTests.java
+6
-8
GrapeRootRepositorySystemSessionAutoConfigurationTests.java
...apeRootRepositorySystemSessionAutoConfigurationTests.java
+3
-4
SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
...ingsXmlRepositorySystemSessionAutoConfigurationTests.java
+2
-2
pom.xml
spring-boot-dependencies/pom.xml
+1
-1
pom.xml
spring-boot-parent/pom.xml
+1
-1
checkstyle.xml
spring-boot-parent/src/checkstyle/checkstyle.xml
+1
-1
MockitoAopProxyTargetInterceptor.java
...t/test/mock/mockito/MockitoAopProxyTargetInterceptor.java
+3
-2
SpringBootMockUtil.java
...gframework/boot/test/mock/mockito/SpringBootMockUtil.java
+113
-24
Mockito110Tests.java
...ringframework/boot/test/mock/mockito/Mockito110Tests.java
+50
-0
SpyBeanOnTestFieldForMultipleExistingBeansIntegrationTests.java
...nOnTestFieldForMultipleExistingBeansIntegrationTests.java
+2
-2
SpringApplicationTests.java
...java/org/springframework/boot/SpringApplicationTests.java
+10
-7
MockEmbeddedServletContainerFactory.java
...context/embedded/MockEmbeddedServletContainerFactory.java
+7
-7
RootUriTemplateHandlerTests.java
...ramework/boot/web/client/RootUriTemplateHandlerTests.java
+4
-4
No files found.
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/writer/MessageChannelMetricWriterTests.java
View file @
c28ff431
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -56,7 +56,7 @@ public class MessageChannelMetricWriterTests {
@Override
public
Object
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
MessageChannelMetricWriterTests
.
this
.
handler
.
handleMessage
(
invocation
.
getArgument
At
(
0
,
Message
.
class
));
.
handleMessage
(
invocation
.
getArgument
(
0
));
return
true
;
}
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/AbstractHttpClientMockTests.java
View file @
c28ff431
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -27,7 +27,6 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.message.BasicHeader
;
import
org.hamcrest.Matcher
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.mockito.ArgumentMatcher
;
...
...
@@ -143,14 +142,14 @@ public abstract class AbstractHttpClientMockTests {
given
(
response
.
getFirstHeader
(
headerName
)).
willReturn
(
header
);
}
private
Matcher
<
HttpGet
>
getForMetadata
(
boolean
serviceCapabilities
)
{
private
Argument
Matcher
<
HttpGet
>
getForMetadata
(
boolean
serviceCapabilities
)
{
if
(!
serviceCapabilities
)
{
return
new
HasAcceptHeader
(
InitializrService
.
ACCEPT_META_DATA
,
true
);
}
return
new
HasAcceptHeader
(
InitializrService
.
ACCEPT_SERVICE_CAPABILITIES
,
true
);
}
private
Matcher
<
HttpGet
>
getForNonMetadata
()
{
private
Argument
Matcher
<
HttpGet
>
getForNonMetadata
()
{
return
new
HasAcceptHeader
(
InitializrService
.
ACCEPT_META_DATA
,
false
);
}
...
...
@@ -188,7 +187,7 @@ public abstract class AbstractHttpClientMockTests {
}
private
static
class
HasAcceptHeader
extend
s
ArgumentMatcher
<
HttpGet
>
{
private
static
class
HasAcceptHeader
implement
s
ArgumentMatcher
<
HttpGet
>
{
private
final
String
value
;
...
...
@@ -200,11 +199,10 @@ public abstract class AbstractHttpClientMockTests {
}
@Override
public
boolean
matches
(
Object
argumen
t
)
{
if
(
!(
argument
instanceof
HttpGet
)
)
{
public
boolean
matches
(
HttpGet
ge
t
)
{
if
(
get
==
null
)
{
return
false
;
}
HttpGet
get
=
(
HttpGet
)
argument
;
Header
acceptHeader
=
get
.
getFirstHeader
(
HttpHeaders
.
ACCEPT
);
if
(
this
.
shouldMatch
)
{
return
acceptHeader
!=
null
&&
this
.
value
.
equals
(
acceptHeader
.
getValue
());
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java
View file @
c28ff431
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -66,7 +66,7 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
public
LocalRepositoryManager
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
LocalRepository
localRepository
=
invocation
.
getArgument
At
(
1
,
LocalRepository
.
class
);
.
getArgument
(
1
);
return
new
SimpleLocalRepositoryManagerFactory
()
.
newInstance
(
GrapeRootRepositorySystemSessionAutoConfigurationTests
.
this
.
session
,
...
...
@@ -109,8 +109,7 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
@Override
public
LocalRepositoryManager
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
LocalRepository
localRepository
=
invocation
.
getArgumentAt
(
1
,
LocalRepository
.
class
);
LocalRepository
localRepository
=
invocation
.
getArgument
(
1
);
return
new
SimpleLocalRepositoryManagerFactory
().
newInstance
(
GrapeRootRepositorySystemSessionAutoConfigurationTests
.
this
.
session
,
localRepository
);
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
View file @
c28ff431
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -85,7 +85,7 @@ public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
public
LocalRepositoryManager
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
LocalRepository
localRepository
=
invocation
.
getArgument
At
(
1
,
LocalRepository
.
class
);
.
getArgument
(
1
);
return
new
SimpleLocalRepositoryManagerFactory
()
.
newInstance
(
session
,
localRepository
);
}
...
...
spring-boot-dependencies/pom.xml
View file @
c28ff431
...
...
@@ -129,7 +129,7 @@
<lombok.version>
1.16.12
</lombok.version>
<mariadb.version>
1.5.6
</mariadb.version>
<mssql-jdbc.version>
6.1.0.jre8
</mssql-jdbc.version>
<mockito.version>
1.10.19
</mockito.version>
<mockito.version>
2.5.4
</mockito.version>
<mongodb.version>
3.4.1
</mongodb.version>
<mysql.version>
5.1.40
</mysql.version>
<narayana.version>
5.5.0.Final
</narayana.version>
...
...
spring-boot-parent/pom.xml
View file @
c28ff431
...
...
@@ -81,7 +81,7 @@
<dependency>
<groupId>
net.bytebuddy
</groupId>
<artifactId>
byte-buddy
</artifactId>
<version>
1.
5.4
</version>
<version>
1.
6.0
</version>
</dependency>
<dependency>
<groupId>
net.sf.jopt-simple
</groupId>
...
...
spring-boot-parent/src/checkstyle/checkstyle.xml
View file @
c28ff431
...
...
@@ -70,7 +70,7 @@
<module
name=
"com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck"
/>
<module
name=
"com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck"
>
<property
name=
"excludes"
value=
"org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo, org.springframework.test.web.client.match.MockRestRequestMatchers.*, org.springframework.test.web.client.response.MockRestResponseCreators.*"
/>
value=
"org.assertj.core.api.Assertions.*, org.junit.Assert.*, org.junit.Assume.*, org.junit.internal.matchers.ThrowableMessageMatcher.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*, org.springframework.boot.configurationprocessor.TestCompiler.*, org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.
ArgumentMatchers.*, org.mockito.
Matchers.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*, org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*, org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo, org.springframework.test.web.client.match.MockRestRequestMatchers.*, org.springframework.test.web.client.response.MockRestResponseCreators.*"
/>
</module>
<module
name=
"com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck"
/>
<module
name=
"com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck"
/>
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoAopProxyTargetInterceptor.java
View file @
c28ff431
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -108,7 +108,8 @@ class MockitoAopProxyTargetInterceptor implements MethodInterceptor {
if
(
mode
instanceof
MockAwareVerificationMode
)
{
MockAwareVerificationMode
mockAwareMode
=
(
MockAwareVerificationMode
)
mode
;
if
(
mockAwareMode
.
getMock
()
==
source
)
{
mode
=
new
MockAwareVerificationMode
(
target
,
mockAwareMode
);
mode
=
SpringBootMockUtil
.
createMockAwareVerificationMode
(
target
,
mockAwareMode
);
}
}
resetVerificationStarted
(
mode
);
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/SpringBootMockUtil.java
View file @
c28ff431
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -16,17 +16,23 @@
package
org
.
springframework
.
boot
.
test
.
mock
.
mockito
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.Method
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Set
;
import
org.
mockito.Argument
Matcher
;
import
org.
hamcrest.
Matcher
;
import
org.mockito.internal.matchers.LocalizedMatcher
;
import
org.mockito.internal.progress.ArgumentMatcherStorage
;
import
org.mockito.internal.progress.MockingProgress
;
import
org.mockito.internal.progress.ThreadSafeMockingProgress
;
import
org.mockito.internal.util.MockUtil
;
import
org.mockito.internal.verification.MockAwareVerificationMode
;
import
org.mockito.mock.MockCreationSettings
;
import
org.mockito.verification.VerificationMode
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ReflectionUtils
;
...
...
@@ -35,18 +41,19 @@ import org.springframework.util.ReflectionUtils;
* and 2.
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
final
class
SpringBootMockUtil
{
private
static
final
MockUtilAdapter
adapter
;
static
{
if
(
ClassUtils
.
isPresent
(
"org.mockito.
quality.MockitoHint
"
,
if
(
ClassUtils
.
isPresent
(
"org.mockito.
ReturnValues
"
,
SpringBootMockUtil
.
class
.
getClassLoader
()))
{
adapter
=
new
Mockito
2
MockUtilAdapter
();
adapter
=
new
Mockito
1
MockUtilAdapter
();
}
else
{
adapter
=
new
Mockito
1
MockUtilAdapter
();
adapter
=
new
Mockito
2
MockUtilAdapter
();
}
}
...
...
@@ -67,6 +74,11 @@ final class SpringBootMockUtil {
adapter
.
reportMatchers
(
storage
,
matchers
);
}
static
MockAwareVerificationMode
createMockAwareVerificationMode
(
Object
mock
,
VerificationMode
mode
)
{
return
adapter
.
createMockAwareVerificationMode
(
mock
,
mode
);
}
private
interface
MockUtilAdapter
{
MockCreationSettings
<?>
getMockSettings
(
Object
mock
);
...
...
@@ -76,15 +88,53 @@ final class SpringBootMockUtil {
void
reportMatchers
(
ArgumentMatcherStorage
storage
,
List
<
LocalizedMatcher
>
matchers
);
MockAwareVerificationMode
createMockAwareVerificationMode
(
Object
mock
,
VerificationMode
mode
);
}
private
static
class
Mockito1MockUtilAdapter
implements
MockUtilAdapter
{
private
static
final
MockingProgress
mockingProgress
=
new
ThreadSafeMockingProgress
();
private
final
MockUtil
mockUtil
=
BeanUtils
.
instantiate
(
MockUtil
.
class
);
private
final
Method
getMockSettingsMethod
=
ReflectionUtils
.
findMethod
(
MockUtil
.
class
,
"getMockSettings"
,
Object
.
class
);
private
static
final
MockingProgress
mockingProgress
=
createThreadSafeMockingProgress
();
private
final
Method
reportMatcherMethod
=
ReflectionUtils
.
findMethod
(
ArgumentMatcherStorage
.
class
,
"reportMatcher"
,
Matcher
.
class
);
private
static
final
Constructor
<
MockAwareVerificationMode
>
mockAwareVerificationModeConstructor
=
getMockAwareVerificationModeConstructor
();
private
static
MockingProgress
createThreadSafeMockingProgress
()
{
try
{
Class
<?>
target
=
ClassUtils
.
forName
(
"org.mockito.internal.progress.ThreadSafeMockingProgress"
,
SpringBootMockUtil
.
class
.
getClassLoader
());
return
(
MockingProgress
)
BeanUtils
.
instantiateClass
(
target
);
}
catch
(
ClassNotFoundException
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
private
static
Constructor
<
MockAwareVerificationMode
>
getMockAwareVerificationModeConstructor
()
{
try
{
return
MockAwareVerificationMode
.
class
.
getConstructor
(
Object
.
class
,
VerificationMode
.
class
);
}
catch
(
NoSuchMethodException
ex
)
{
throw
new
IllegalStateException
(
ex
);
}
}
@Override
public
MockCreationSettings
<?>
getMockSettings
(
Object
mock
)
{
return
new
MockUtil
().
getMockSettings
(
mock
);
return
(
MockCreationSettings
<?>)
ReflectionUtils
.
invokeMethod
(
this
.
getMockSettingsMethod
,
this
.
mockUtil
,
mock
);
}
@Override
...
...
@@ -96,44 +146,83 @@ final class SpringBootMockUtil {
public
void
reportMatchers
(
ArgumentMatcherStorage
storage
,
List
<
LocalizedMatcher
>
matchers
)
{
for
(
LocalizedMatcher
matcher
:
matchers
)
{
storage
.
reportMatcher
(
matcher
);
ReflectionUtils
.
invokeMethod
(
this
.
reportMatcherMethod
,
storage
,
matcher
);
}
}
@Override
public
MockAwareVerificationMode
createMockAwareVerificationMode
(
Object
mock
,
VerificationMode
mode
)
{
return
BeanUtils
.
instantiateClass
(
mockAwareVerificationModeConstructor
,
mock
,
mode
);
}
}
private
static
class
Mockito2MockUtilAdapter
implements
MockUtilAdapter
{
private
final
Method
getMockSettingsMethod
=
ReflectionUtils
.
findMethod
(
MockUtil
.
class
,
"getMockSettings"
,
Object
.
class
);
private
final
Method
mockingProgressMethod
=
ReflectionUtils
.
findMethod
(
ThreadSafeMockingProgress
.
class
,
"mockingProgress"
);
private
final
Method
reportMatcherMethod
=
ReflectionUtils
.
findMethod
(
ArgumentMatcherStorage
.
class
,
"reportMatcher"
,
ArgumentMatcher
.
class
);
private
static
final
Constructor
<
MockAwareVerificationMode
>
mockAwareVerificationModeConstructor
;
private
static
final
boolean
mockAwareVerificationModeLegacy
;
private
final
Method
getMatcherMethod
=
ReflectionUtils
.
findMethod
(
LocalizedMatcher
.
class
,
"getMatcher"
);
static
{
Constructor
<
MockAwareVerificationMode
>
c
=
getMockAwareVerificationModeConstructor
();
if
(
c
!=
null
)
{
mockAwareVerificationModeConstructor
=
c
;
mockAwareVerificationModeLegacy
=
false
;
}
else
{
mockAwareVerificationModeConstructor
=
getMockAwareVerificationModeLegacyConstructor
();
mockAwareVerificationModeLegacy
=
true
;
}
}
@Override
public
MockCreationSettings
<?>
getMockSettings
(
Object
mock
)
{
return
(
MockCreationSettings
<?>)
ReflectionUtils
.
invokeMethod
(
this
.
getMockSettingsMethod
,
null
,
mock
);
return
MockUtil
.
getMockSettings
(
mock
);
}
@Override
public
MockingProgress
mockingProgress
()
{
return
(
MockingProgress
)
ReflectionUtils
.
invokeMethod
(
this
.
mockingProgressMethod
,
null
);
return
ThreadSafeMockingProgress
.
mockingProgress
();
}
@Override
public
void
reportMatchers
(
ArgumentMatcherStorage
storage
,
List
<
LocalizedMatcher
>
matchers
)
{
for
(
LocalizedMatcher
matcher
:
matchers
)
{
ReflectionUtils
.
invokeMethod
(
this
.
reportMatcherMethod
,
storage
,
ReflectionUtils
.
invokeMethod
(
this
.
getMatcherMethod
,
matcher
));
storage
.
reportMatcher
(
matcher
.
getMatcher
());
}
}
@Override
public
MockAwareVerificationMode
createMockAwareVerificationMode
(
Object
mock
,
VerificationMode
mode
)
{
if
(
mockAwareVerificationModeLegacy
)
{
return
BeanUtils
.
instantiateClass
(
mockAwareVerificationModeConstructor
,
mock
,
mode
);
}
else
{
return
BeanUtils
.
instantiateClass
(
mockAwareVerificationModeConstructor
,
mock
,
mode
,
Collections
.
emptySet
());
}
}
private
static
Constructor
<
MockAwareVerificationMode
>
getMockAwareVerificationModeLegacyConstructor
()
{
try
{
return
MockAwareVerificationMode
.
class
.
getConstructor
(
Object
.
class
,
VerificationMode
.
class
);
}
catch
(
NoSuchMethodException
ex
)
{
return
null
;
}
}
private
static
Constructor
<
MockAwareVerificationMode
>
getMockAwareVerificationModeConstructor
()
{
try
{
return
MockAwareVerificationMode
.
class
.
getConstructor
(
Object
.
class
,
VerificationMode
.
class
,
Set
.
class
);
}
catch
(
NoSuchMethodException
ex
)
{
return
null
;
}
}
...
...
spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/Mockito110Tests.java
0 → 100644
View file @
c28ff431
/*
* Copyright 2012-2017 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
.
mock
.
mockito
;
import
org.junit.Test
;
import
org.junit.runner.JUnitCore
;
import
org.junit.runner.Result
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.junit.runner.classpath.ClassPathOverrides
;
import
org.springframework.boot.junit.runner.classpath.ModifiedClassPathRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for compatibility with Mockito 1.10
*
* @author Andy Wilkinson
* @author Stephane Nicoll
*/
@RunWith
(
ModifiedClassPathRunner
.
class
)
@ClassPathOverrides
(
"org.mockito:mockito-core:1.10.19"
)
public
class
Mockito110Tests
{
@Test
public
void
spyBeanWithAopProxyTestsWithMockito1
()
{
runTests
(
SpyBeanWithAopProxyTests
.
class
);
}
private
void
runTests
(
Class
<?>
testClass
)
{
Result
result
=
new
JUnitCore
().
run
(
testClass
);
assertThat
(
result
.
getFailureCount
()).
isEqualTo
(
0
);
assertThat
(
result
.
getRunCount
()).
isGreaterThan
(
0
);
}
}
spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/SpyBeanOnTestFieldForMultipleExistingBeansIntegrationTests.java
View file @
c28ff431
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -49,7 +49,7 @@ public class SpyBeanOnTestFieldForMultipleExistingBeansIntegrationTests {
@Test
public
void
testSpying
()
throws
Exception
{
assertThat
(
this
.
caller
.
sayGreeting
()).
isEqualTo
(
"I say two"
);
assertThat
(
new
MockUtil
()
.
getMockName
(
this
.
spy
).
toString
()).
isEqualTo
(
"two"
);
assertThat
(
MockUtil
.
getMockName
(
this
.
spy
).
toString
()).
isEqualTo
(
"two"
);
verify
(
this
.
spy
).
greeting
();
}
...
...
spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java
View file @
c28ff431
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -34,6 +34,7 @@ import org.junit.Before;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.mockito.ArgumentCaptor
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
...
...
@@ -78,10 +79,8 @@ import org.springframework.util.StringUtils;
import
org.springframework.web.context.support.StandardServletEnvironment
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
hamcrest
.
CoreMatchers
.
isA
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
argThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
isA
;
import
static
org
.
mockito
.
Mockito
.
atLeastOnce
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
...
...
@@ -644,7 +643,11 @@ public class SpringApplicationTests {
}
catch
(
RuntimeException
ex
)
{
}
verify
(
handler
).
registerLoggedException
(
any
(
RefreshFailureException
.
class
));
ArgumentCaptor
<
RuntimeException
>
ac
=
ArgumentCaptor
.
forClass
(
RuntimeException
.
class
);
verify
(
handler
).
registerLoggedException
(
ac
.
capture
());
RuntimeException
exception
=
ac
.
getValue
();
assertThat
(
exception
).
hasCauseInstanceOf
(
RefreshFailureException
.
class
);
assertThat
(
this
.
output
.
toString
()).
doesNotContain
(
"NullPointerException"
);
}
...
...
@@ -722,8 +725,8 @@ public class SpringApplicationTests {
private
void
verifyTestListenerEvents
()
{
ApplicationListener
<
ApplicationEvent
>
listener
=
this
.
context
.
getBean
(
"testApplicationListener"
,
ApplicationListener
.
class
);
verify
(
listener
).
onApplicationEvent
(
argThat
(
isA
(
ContextRefreshedEvent
.
class
)
));
verify
(
listener
).
onApplicationEvent
(
argThat
(
isA
(
ApplicationReadyEvent
.
class
)
));
verify
(
listener
).
onApplicationEvent
(
isA
(
ContextRefreshedEvent
.
class
));
verify
(
listener
).
onApplicationEvent
(
isA
(
ApplicationReadyEvent
.
class
));
verifyNoMoreInteractions
(
listener
);
}
...
...
spring-boot/src/test/java/org/springframework/boot/context/embedded/MockEmbeddedServletContainerFactory.java
View file @
c28ff431
/*
* 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");
* you may not use this file except in compliance with the License.
...
...
@@ -37,8 +37,8 @@ import org.mockito.stubbing.Answer;
import
org.springframework.boot.web.servlet.ServletContextInitializer
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
spy
;
...
...
@@ -102,7 +102,7 @@ public class MockEmbeddedServletContainerFactory
private
void
initialize
()
{
try
{
this
.
servletContext
=
mock
(
ServletContext
.
class
);
given
(
this
.
servletContext
.
addServlet
(
anyString
(),
(
Servlet
)
any
Object
()))
given
(
this
.
servletContext
.
addServlet
(
anyString
(),
(
Servlet
)
any
()))
.
willAnswer
(
new
Answer
<
ServletRegistration
.
Dynamic
>()
{
@Override
public
ServletRegistration
.
Dynamic
answer
(
...
...
@@ -114,7 +114,7 @@ public class MockEmbeddedServletContainerFactory
return
registeredServlet
.
getRegistration
();
}
});
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
(
Filter
)
any
Object
()))
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
(
Filter
)
any
()))
.
willAnswer
(
new
Answer
<
FilterRegistration
.
Dynamic
>()
{
@Override
public
FilterRegistration
.
Dynamic
answer
(
...
...
@@ -133,8 +133,8 @@ public class MockEmbeddedServletContainerFactory
public
Void
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
initParameters
.
put
(
invocation
.
getArgument
At
(
0
,
String
.
class
),
invocation
.
getArgument
At
(
1
,
String
.
class
));
invocation
.
getArgument
(
0
),
invocation
.
getArgument
(
1
));
return
null
;
}
...
...
@@ -147,7 +147,7 @@ public class MockEmbeddedServletContainerFactory
public
String
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
return
initParameters
.
get
(
invocation
.
getArgument
At
(
0
,
String
.
class
));
.
get
(
invocation
.
getArgument
(
0
));
}
});
given
(
this
.
servletContext
.
getAttributeNames
()).
willReturn
(
...
...
spring-boot/src/test/java/org/springframework/boot/web/client/RootUriTemplateHandlerTests.java
View file @
c28ff431
...
...
@@ -19,6 +19,7 @@ package org.springframework.boot.web.client;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.junit.Before
;
import
org.junit.Rule
;
...
...
@@ -31,10 +32,9 @@ import org.springframework.web.client.RestTemplate;
import
org.springframework.web.util.UriTemplateHandler
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Matchers
.
anyMap
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Matchers
.
anyVararg
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
...
...
@@ -60,8 +60,8 @@ public class RootUriTemplateHandlerTests {
MockitoAnnotations
.
initMocks
(
this
);
this
.
uri
=
new
URI
(
"http://example.com/hello"
);
this
.
handler
=
new
RootUriTemplateHandler
(
"http://example.com"
,
this
.
delegate
);
given
(
this
.
delegate
.
expand
(
anyString
(),
any
Map
(
))).
willReturn
(
this
.
uri
);
given
(
this
.
delegate
.
expand
(
anyString
(),
(
Object
[])
any
Vararg
()))
given
(
this
.
delegate
.
expand
(
anyString
(),
any
(
Map
.
class
))).
willReturn
(
this
.
uri
);
given
(
this
.
delegate
.
expand
(
anyString
(),
(
Object
[])
any
()))
.
willReturn
(
this
.
uri
);
}
...
...
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