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
969dd35e
Commit
969dd35e
authored
Aug 08, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade to Mockito 3.4.6
Closes gh-22838
parent
f2a52a87
Changes
79
Hide whitespace changes
Inline
Side-by-side
Showing
79 changed files
with
444 additions
and
443 deletions
+444
-443
build.gradle
...t-project/spring-boot-actuator-autoconfigure/build.gradle
+1
-0
ReactiveCloudFoundrySecurityInterceptorTests.java
...eactive/ReactiveCloudFoundrySecurityInterceptorTests.java
+4
-3
ReactiveTokenValidatorTests.java
...re/cloudfoundry/reactive/ReactiveTokenValidatorTests.java
+4
-4
CloudFoundrySecurityInterceptorTests.java
...foundry/servlet/CloudFoundrySecurityInterceptorTests.java
+4
-3
TokenValidatorTests.java
...toconfigure/cloudfoundry/servlet/TokenValidatorTests.java
+4
-5
IncludeExcludeEndpointFilterTests.java
...re/endpoint/expose/IncludeExcludeEndpointFilterTests.java
+11
-9
AutoConfiguredHealthEndpointGroupTests.java
...figure/health/AutoConfiguredHealthEndpointGroupTests.java
+8
-12
MeterRegistryConfigurerTests.java
...e/autoconfigure/metrics/MeterRegistryConfigurerTests.java
+12
-11
RabbitHealthIndicatorTests.java
...amework/boot/actuate/amqp/RabbitHealthIndicatorTests.java
+13
-12
AvailabilityStateHealthIndicatorTests.java
...e/availability/AvailabilityStateHealthIndicatorTests.java
+3
-7
CachingOperationInvokerAdvisorTests.java
...nt/invoker/cache/CachingOperationInvokerAdvisorTests.java
+4
-3
JmxEndpointExporterTests.java
...k/boot/actuate/endpoint/jmx/JmxEndpointExporterTests.java
+7
-5
ServletEndpointRegistrarTests.java
...t/actuate/endpoint/web/ServletEndpointRegistrarTests.java
+8
-9
PrometheusPushGatewayManagerTests.java
.../export/prometheus/PrometheusPushGatewayManagerTests.java
+18
-13
DiskSpaceHealthIndicatorTests.java
...rk/boot/actuate/system/DiskSpaceHealthIndicatorTests.java
+5
-3
build.gradle
spring-boot-project/spring-boot-autoconfigure/build.gradle
+1
-0
ConditionEvaluationReportTests.java
...toconfigure/condition/ConditionEvaluationReportTests.java
+4
-3
HibernatePropertiesTests.java
.../boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java
+4
-8
TemplateAvailabilityProvidersTests.java
...onfigure/template/TemplateAvailabilityProvidersTests.java
+4
-3
NettyWebServerFactoryCustomizerTests.java
...re/web/embedded/NettyWebServerFactoryCustomizerTests.java
+3
-2
DefaultErrorViewResolverTests.java
...gure/web/servlet/error/DefaultErrorViewResolverTests.java
+11
-5
build.gradle
spring-boot-project/spring-boot-cli/build.gradle
+1
-0
CommandRunnerTests.java
.../springframework/boot/cli/command/CommandRunnerTests.java
+7
-6
EncodePasswordCommandTests.java
...li/command/encodepassword/EncodePasswordCommandTests.java
+4
-3
InitCommandTests.java
...ringframework/boot/cli/command/init/InitCommandTests.java
+4
-8
DependencyCustomizerTests.java
...ramework/boot/cli/compiler/DependencyCustomizerTests.java
+12
-5
CompositeDependencyManagementTests.java
...iler/dependencies/CompositeDependencyManagementTests.java
+4
-10
GrapeRootRepositorySystemSessionAutoConfigurationTests.java
...apeRootRepositorySystemSessionAutoConfigurationTests.java
+4
-14
SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
...ingsXmlRepositorySystemSessionAutoConfigurationTests.java
+4
-8
build.gradle
spring-boot-project/spring-boot-dependencies/build.gradle
+1
-1
build.gradle
spring-boot-project/spring-boot-devtools/build.gradle
+1
-0
ClassPathFileChangeListenerTests.java
.../devtools/classpath/ClassPathFileChangeListenerTests.java
+3
-7
DelayedLiveReloadTriggerTests.java
...devtools/remote/client/DelayedLiveReloadTriggerTests.java
+8
-7
HttpHeaderInterceptorTests.java
...ot/devtools/remote/client/HttpHeaderInterceptorTests.java
+5
-4
DispatcherFilterTests.java
...rk/boot/devtools/remote/server/DispatcherFilterTests.java
+4
-3
DispatcherTests.java
...ramework/boot/devtools/remote/server/DispatcherTests.java
+7
-17
HttpRestartServerTests.java
.../boot/devtools/restart/server/HttpRestartServerTests.java
+3
-2
HttpTunnelConnectionTests.java
...oot/devtools/tunnel/client/HttpTunnelConnectionTests.java
+3
-4
HttpTunnelServerTests.java
...rk/boot/devtools/tunnel/server/HttpTunnelServerTests.java
+24
-8
build.gradle
...-boot-project/spring-boot-test-autoconfigure/build.gradle
+1
-0
TestEntityManagerTests.java
...ot/test/autoconfigure/orm/jpa/TestEntityManagerTests.java
+10
-4
build.gradle
spring-boot-project/spring-boot-test/build.gradle
+1
-0
MockitoTestExecutionListener.java
.../boot/test/mock/mockito/MockitoTestExecutionListener.java
+13
-3
ApplicationContextAssertProviderTests.java
...ontext/assertj/ApplicationContextAssertProviderTests.java
+4
-3
MockitoTestExecutionListenerTests.java
.../test/mock/mockito/MockitoTestExecutionListenerTests.java
+11
-13
QualifierDefinitionTests.java
...work/boot/test/mock/mockito/QualifierDefinitionTests.java
+4
-8
RootUriRequestExpectationManagerTests.java
...est/web/client/RootUriRequestExpectationManagerTests.java
+4
-3
LocalHostWebClientTests.java
...ework/boot/test/web/htmlunit/LocalHostWebClientTests.java
+4
-6
LocalHostWebConnectionHtmlUnitDriverTests.java
.../webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java
+7
-6
DockerApiTests.java
...mework/boot/buildpack/platform/docker/DockerApiTests.java
+3
-5
HttpClientTransportTests.java
...k/platform/docker/transport/HttpClientTransportTests.java
+19
-6
build.gradle
...ng-boot-tools/spring-boot-jarmode-layertools/build.gradle
+1
-0
ExtractCommandTests.java
...ramework/boot/jarmode/layertools/ExtractCommandTests.java
+8
-4
ListCommandTests.java
...ngframework/boot/jarmode/layertools/ListCommandTests.java
+7
-6
build.gradle
...t/spring-boot-tools/spring-boot-maven-plugin/build.gradle
+1
-0
ArtifactsLibrariesTests.java
...g/springframework/boot/maven/ArtifactsLibrariesTests.java
+8
-9
MockServletWebServer.java
...rk/boot/testsupport/web/servlet/MockServletWebServer.java
+10
-11
build.gradle
spring-boot-project/spring-boot/build.gradle
+1
-0
BannerTests.java
...t/src/test/java/org/springframework/boot/BannerTests.java
+3
-9
ConfigDataEnvironmentContributorsTests.java
...ontext/config/ConfigDataEnvironmentContributorsTests.java
+3
-2
ConfigDataEnvironmentPostProcessorTests.java
...ntext/config/ConfigDataEnvironmentPostProcessorTests.java
+8
-12
ConfigDataImporterTests.java
...ramework/boot/context/config/ConfigDataImporterTests.java
+3
-2
ConfigDataLocationResolversTests.java
...boot/context/config/ConfigDataLocationResolversTests.java
+3
-7
BindConverterTests.java
...work/boot/context/properties/bind/BindConverterTests.java
+4
-8
BindResultTests.java
...amework/boot/context/properties/bind/BindResultTests.java
+3
-7
BoundPropertiesTrackingBindHandlerTests.java
...perties/bind/BoundPropertiesTrackingBindHandlerTests.java
+4
-3
DefaultPropertiesPropertySourceTests.java
...mework/boot/env/DefaultPropertiesPropertySourceTests.java
+3
-7
CompositeDataSourcePoolMetadataProviderTests.java
...etadata/CompositeDataSourcePoolMetadataProviderTests.java
+4
-3
RestTemplateBuilderTests.java
...ngframework/boot/web/client/RestTemplateBuilderTests.java
+3
-7
RootUriTemplateHandlerTests.java
...ramework/boot/web/client/RootUriTemplateHandlerTests.java
+11
-6
WebServerFactoryCustomizerBeanPostProcessorTests.java
...ver/WebServerFactoryCustomizerBeanPostProcessorTests.java
+4
-6
AbstractFilterRegistrationBeanTests.java
...boot/web/servlet/AbstractFilterRegistrationBeanTests.java
+10
-9
FilterRegistrationBeanTests.java
...amework/boot/web/servlet/FilterRegistrationBeanTests.java
+4
-0
ServletListenerRegistrationBeanTests.java
...oot/web/servlet/ServletListenerRegistrationBeanTests.java
+4
-8
ServletRegistrationBeanTests.java
...mework/boot/web/servlet/ServletRegistrationBeanTests.java
+8
-11
ServletWebServerApplicationContextTests.java
...vlet/context/ServletWebServerApplicationContextTests.java
+3
-10
WebServiceTemplateBuilderTests.java
...ot/webservices/client/WebServiceTemplateBuilderTests.java
+4
-8
build.gradle
...boot-smoke-tests/spring-boot-smoke-test-test/build.gradle
+2
-1
UserVehicleServiceTests.java
...test/java/smoketest/test/web/UserVehicleServiceTests.java
+4
-3
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle
View file @
969dd35e
...
@@ -129,6 +129,7 @@ dependencies {
...
@@ -129,6 +129,7 @@ dependencies {
testImplementation
(
"org.hsqldb:hsqldb"
)
testImplementation
(
"org.hsqldb:hsqldb"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.skyscreamer:jsonassert"
)
testImplementation
(
"org.skyscreamer:jsonassert"
)
testImplementation
(
"org.springframework:spring-orm"
)
testImplementation
(
"org.springframework:spring-orm"
)
testImplementation
(
"org.springframework.data:spring-data-elasticsearch"
)
{
testImplementation
(
"org.springframework.data:spring-data-elasticsearch"
)
{
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityInterceptorTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -18,8 +18,9 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive;
...
@@ -18,8 +18,9 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
import
reactor.test.StepVerifier
;
import
reactor.test.StepVerifier
;
...
@@ -41,6 +42,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -41,6 +42,7 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ReactiveCloudFoundrySecurityInterceptorTests
{
class
ReactiveCloudFoundrySecurityInterceptorTests
{
@Mock
@Mock
...
@@ -53,7 +55,6 @@ class ReactiveCloudFoundrySecurityInterceptorTests {
...
@@ -53,7 +55,6 @@ class ReactiveCloudFoundrySecurityInterceptorTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
interceptor
=
new
CloudFoundrySecurityInterceptor
(
this
.
tokenValidator
,
this
.
securityService
,
"my-app-id"
);
this
.
interceptor
=
new
CloudFoundrySecurityInterceptor
(
this
.
tokenValidator
,
this
.
securityService
,
"my-app-id"
);
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveTokenValidatorTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -31,8 +31,9 @@ import java.util.concurrent.ConcurrentHashMap;
...
@@ -31,8 +31,9 @@ import java.util.concurrent.ConcurrentHashMap;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
import
reactor.test.StepVerifier
;
import
reactor.test.StepVerifier
;
import
reactor.test.publisher.PublisherProbe
;
import
reactor.test.publisher.PublisherProbe
;
...
@@ -52,6 +53,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -52,6 +53,7 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ReactiveTokenValidatorTests
{
class
ReactiveTokenValidatorTests
{
private
static
final
byte
[]
DOT
=
"."
.
getBytes
();
private
static
final
byte
[]
DOT
=
"."
.
getBytes
();
...
@@ -85,7 +87,6 @@ class ReactiveTokenValidatorTests {
...
@@ -85,7 +87,6 @@ class ReactiveTokenValidatorTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
VALID_KEYS
.
put
(
"valid-key"
,
VALID_KEY
);
VALID_KEYS
.
put
(
"valid-key"
,
VALID_KEY
);
INVALID_KEYS
.
put
(
"invalid-key"
,
INVALID_KEY
);
INVALID_KEYS
.
put
(
"invalid-key"
,
INVALID_KEY
);
this
.
tokenValidator
=
new
ReactiveTokenValidator
(
this
.
securityService
);
this
.
tokenValidator
=
new
ReactiveTokenValidator
(
this
.
securityService
);
...
@@ -159,7 +160,6 @@ class ReactiveTokenValidatorTests {
...
@@ -159,7 +160,6 @@ class ReactiveTokenValidatorTests {
void
validateTokenWhenCacheValidShouldNotFetchTokenKeys
()
throws
Exception
{
void
validateTokenWhenCacheValidShouldNotFetchTokenKeys
()
throws
Exception
{
PublisherProbe
<
Map
<
String
,
String
>>
fetchTokenKeys
=
PublisherProbe
.
empty
();
PublisherProbe
<
Map
<
String
,
String
>>
fetchTokenKeys
=
PublisherProbe
.
empty
();
ReflectionTestUtils
.
setField
(
this
.
tokenValidator
,
"cachedTokenKeys"
,
VALID_KEYS
);
ReflectionTestUtils
.
setField
(
this
.
tokenValidator
,
"cachedTokenKeys"
,
VALID_KEYS
);
given
(
this
.
securityService
.
fetchTokenKeys
()).
willReturn
(
fetchTokenKeys
.
mono
());
given
(
this
.
securityService
.
getUaaUrl
()).
willReturn
(
Mono
.
just
(
"http://localhost:8080/uaa"
));
given
(
this
.
securityService
.
getUaaUrl
()).
willReturn
(
Mono
.
just
(
"http://localhost:8080/uaa"
));
String
header
=
"{\"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}"
;
String
header
=
"{\"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}"
;
String
claims
=
"{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"
;
String
claims
=
"{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"
;
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundrySecurityInterceptorTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -18,9 +18,10 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
...
@@ -18,9 +18,10 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel
;
import
org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel
;
import
org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason
;
import
org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason
;
...
@@ -41,6 +42,7 @@ import static org.mockito.Mockito.verify;
...
@@ -41,6 +42,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
CloudFoundrySecurityInterceptorTests
{
class
CloudFoundrySecurityInterceptorTests
{
@Mock
@Mock
...
@@ -55,7 +57,6 @@ class CloudFoundrySecurityInterceptorTests {
...
@@ -55,7 +57,6 @@ class CloudFoundrySecurityInterceptorTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
interceptor
=
new
CloudFoundrySecurityInterceptor
(
this
.
tokenValidator
,
this
.
securityService
,
"my-app-id"
);
this
.
interceptor
=
new
CloudFoundrySecurityInterceptor
(
this
.
tokenValidator
,
this
.
securityService
,
"my-app-id"
);
this
.
request
=
new
MockHttpServletRequest
();
this
.
request
=
new
MockHttpServletRequest
();
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/TokenValidatorTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -31,9 +31,10 @@ import java.util.function.Consumer;
...
@@ -31,9 +31,10 @@ import java.util.function.Consumer;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.Mockito
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException
;
import
org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException
;
import
org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason
;
import
org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason
;
...
@@ -52,6 +53,7 @@ import static org.mockito.Mockito.verify;
...
@@ -52,6 +53,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
TokenValidatorTests
{
class
TokenValidatorTests
{
private
static
final
byte
[]
DOT
=
"."
.
getBytes
();
private
static
final
byte
[]
DOT
=
"."
.
getBytes
();
...
@@ -85,7 +87,6 @@ class TokenValidatorTests {
...
@@ -85,7 +87,6 @@ class TokenValidatorTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
tokenValidator
=
new
TokenValidator
(
this
.
securityService
);
this
.
tokenValidator
=
new
TokenValidator
(
this
.
securityService
);
}
}
...
@@ -135,7 +136,6 @@ class TokenValidatorTests {
...
@@ -135,7 +136,6 @@ class TokenValidatorTests {
void
validateTokenWhenSignatureInvalidShouldThrowException
()
throws
Exception
{
void
validateTokenWhenSignatureInvalidShouldThrowException
()
throws
Exception
{
ReflectionTestUtils
.
setField
(
this
.
tokenValidator
,
"tokenKeys"
,
ReflectionTestUtils
.
setField
(
this
.
tokenValidator
,
"tokenKeys"
,
Collections
.
singletonMap
(
"valid-key"
,
INVALID_KEY
));
Collections
.
singletonMap
(
"valid-key"
,
INVALID_KEY
));
given
(
this
.
securityService
.
getUaaUrl
()).
willReturn
(
"http://localhost:8080/uaa"
);
String
header
=
"{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}"
;
String
header
=
"{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}"
;
String
claims
=
"{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"
;
String
claims
=
"{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"
;
assertThatExceptionOfType
(
CloudFoundryAuthorizationException
.
class
).
isThrownBy
(
assertThatExceptionOfType
(
CloudFoundryAuthorizationException
.
class
).
isThrownBy
(
...
@@ -145,7 +145,6 @@ class TokenValidatorTests {
...
@@ -145,7 +145,6 @@ class TokenValidatorTests {
@Test
@Test
void
validateTokenWhenTokenAlgorithmIsNotRS256ShouldThrowException
()
throws
Exception
{
void
validateTokenWhenTokenAlgorithmIsNotRS256ShouldThrowException
()
throws
Exception
{
given
(
this
.
securityService
.
fetchTokenKeys
()).
willReturn
(
VALID_KEYS
);
String
header
=
"{ \"alg\": \"HS256\", \"typ\": \"JWT\"}"
;
String
header
=
"{ \"alg\": \"HS256\", \"typ\": \"JWT\"}"
;
String
claims
=
"{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"
;
String
claims
=
"{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}"
;
assertThatExceptionOfType
(
CloudFoundryAuthorizationException
.
class
).
isThrownBy
(
assertThatExceptionOfType
(
CloudFoundryAuthorizationException
.
class
).
isThrownBy
(
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/IncludeExcludeEndpointFilterTests.java
View file @
969dd35e
...
@@ -16,9 +16,9 @@
...
@@ -16,9 +16,9 @@
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
endpoint
.
expose
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
endpoint
.
expose
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.MockitoAnnotations
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.endpoint.EndpointFilter
;
import
org.springframework.boot.actuate.endpoint.EndpointFilter
;
import
org.springframework.boot.actuate.endpoint.EndpointId
;
import
org.springframework.boot.actuate.endpoint.EndpointId
;
...
@@ -36,15 +36,11 @@ import static org.mockito.Mockito.mock;
...
@@ -36,15 +36,11 @@ import static org.mockito.Mockito.mock;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
IncludeExcludeEndpointFilterTests
{
class
IncludeExcludeEndpointFilterTests
{
private
IncludeExcludeEndpointFilter
<?>
filter
;
private
IncludeExcludeEndpointFilter
<?>
filter
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
createWhenEndpointTypeIsNullShouldThrowException
()
{
void
createWhenEndpointTypeIsNullShouldThrowException
()
{
assertThatIllegalArgumentException
()
assertThatIllegalArgumentException
()
...
@@ -123,7 +119,7 @@ class IncludeExcludeEndpointFilterTests {
...
@@ -123,7 +119,7 @@ class IncludeExcludeEndpointFilterTests {
environment
.
setProperty
(
"foo.include"
,
"bar"
);
environment
.
setProperty
(
"foo.include"
,
"bar"
);
environment
.
setProperty
(
"foo.exclude"
,
""
);
environment
.
setProperty
(
"foo.exclude"
,
""
);
this
.
filter
=
new
IncludeExcludeEndpointFilter
<>(
DifferentTestExposableWebEndpoint
.
class
,
environment
,
"foo"
);
this
.
filter
=
new
IncludeExcludeEndpointFilter
<>(
DifferentTestExposableWebEndpoint
.
class
,
environment
,
"foo"
);
assertThat
(
match
(
EndpointId
.
of
(
"baz"
)
)).
isTrue
();
assertThat
(
match
()).
isTrue
();
}
}
@Test
@Test
...
@@ -161,10 +157,16 @@ class IncludeExcludeEndpointFilterTests {
...
@@ -161,10 +157,16 @@ class IncludeExcludeEndpointFilterTests {
this
.
filter
=
new
IncludeExcludeEndpointFilter
<>(
TestExposableWebEndpoint
.
class
,
environment
,
"foo"
,
"def"
);
this
.
filter
=
new
IncludeExcludeEndpointFilter
<>(
TestExposableWebEndpoint
.
class
,
environment
,
"foo"
,
"def"
);
}
}
private
boolean
match
()
{
return
match
(
null
);
}
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
private
boolean
match
(
EndpointId
id
)
{
private
boolean
match
(
EndpointId
id
)
{
ExposableEndpoint
<?>
endpoint
=
mock
(
TestExposableWebEndpoint
.
class
);
ExposableEndpoint
<?>
endpoint
=
mock
(
TestExposableWebEndpoint
.
class
);
given
(
endpoint
.
getEndpointId
()).
willReturn
(
id
);
if
(
id
!=
null
)
{
given
(
endpoint
.
getEndpointId
()).
willReturn
(
id
);
}
return
((
EndpointFilter
)
this
.
filter
).
match
(
endpoint
);
return
((
EndpointFilter
)
this
.
filter
).
match
(
endpoint
);
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupTests.java
View file @
969dd35e
...
@@ -20,10 +20,10 @@ import java.security.Principal;
...
@@ -20,10 +20,10 @@ import java.security.Principal;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Show
;
import
org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Show
;
import
org.springframework.boot.actuate.endpoint.SecurityContext
;
import
org.springframework.boot.actuate.endpoint.SecurityContext
;
...
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.mock;
...
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.mock;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
AutoConfiguredHealthEndpointGroupTests
{
class
AutoConfiguredHealthEndpointGroupTests
{
@Mock
@Mock
...
@@ -55,11 +56,6 @@ class AutoConfiguredHealthEndpointGroupTests {
...
@@ -55,11 +56,6 @@ class AutoConfiguredHealthEndpointGroupTests {
@Mock
@Mock
private
Principal
principal
;
private
Principal
principal
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
isMemberWhenMemberPredicateMatchesAcceptsTrue
()
{
void
isMemberWhenMemberPredicateMatchesAcceptsTrue
()
{
AutoConfiguredHealthEndpointGroup
group
=
new
AutoConfiguredHealthEndpointGroup
((
name
)
->
name
.
startsWith
(
"a"
),
AutoConfiguredHealthEndpointGroup
group
=
new
AutoConfiguredHealthEndpointGroup
((
name
)
->
name
.
startsWith
(
"a"
),
...
@@ -112,17 +108,17 @@ class AutoConfiguredHealthEndpointGroupTests {
...
@@ -112,17 +108,17 @@ class AutoConfiguredHealthEndpointGroupTests {
this
.
statusAggregator
,
this
.
httpCodeStatusMapper
,
null
,
Show
.
WHEN_AUTHORIZED
,
this
.
statusAggregator
,
this
.
httpCodeStatusMapper
,
null
,
Show
.
WHEN_AUTHORIZED
,
Arrays
.
asList
(
"admin"
,
"root"
,
"bossmode"
));
Arrays
.
asList
(
"admin"
,
"root"
,
"bossmode"
));
given
(
this
.
securityContext
.
getPrincipal
()).
willReturn
(
this
.
principal
);
given
(
this
.
securityContext
.
getPrincipal
()).
willReturn
(
this
.
principal
);
given
(
this
.
securityContext
.
isUserInRole
(
"admin"
)).
willReturn
(
false
);
given
(
this
.
securityContext
.
isUserInRole
(
"root"
)).
willReturn
(
true
);
given
(
this
.
securityContext
.
isUserInRole
(
"root"
)).
willReturn
(
true
);
assertThat
(
group
.
showDetails
(
this
.
securityContext
)).
isTrue
();
assertThat
(
group
.
showDetails
(
this
.
securityContext
)).
isTrue
();
}
}
@Test
@Test
void
showDetailsWhenShowDetailsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse
()
{
void
showDetailsWhenShowDetailsIsWhenAuthorizedAndUse
r
IsNotInRoleReturnsFalse
()
{
AutoConfiguredHealthEndpointGroup
group
=
new
AutoConfiguredHealthEndpointGroup
((
name
)
->
true
,
AutoConfiguredHealthEndpointGroup
group
=
new
AutoConfiguredHealthEndpointGroup
((
name
)
->
true
,
this
.
statusAggregator
,
this
.
httpCodeStatusMapper
,
null
,
Show
.
WHEN_AUTHORIZED
,
this
.
statusAggregator
,
this
.
httpCodeStatusMapper
,
null
,
Show
.
WHEN_AUTHORIZED
,
Arrays
.
asList
(
"admin"
,
"rot"
,
"bossmode"
));
Arrays
.
asList
(
"admin"
,
"ro
o
t"
,
"bossmode"
));
given
(
this
.
securityContext
.
getPrincipal
()).
willReturn
(
this
.
principal
);
given
(
this
.
securityContext
.
getPrincipal
()).
willReturn
(
this
.
principal
);
given
(
this
.
securityContext
.
isUserInRole
(
"root"
)).
willReturn
(
true
);
assertThat
(
group
.
showDetails
(
this
.
securityContext
)).
isFalse
();
assertThat
(
group
.
showDetails
(
this
.
securityContext
)).
isFalse
();
}
}
...
@@ -198,17 +194,17 @@ class AutoConfiguredHealthEndpointGroupTests {
...
@@ -198,17 +194,17 @@ class AutoConfiguredHealthEndpointGroupTests {
this
.
statusAggregator
,
this
.
httpCodeStatusMapper
,
Show
.
WHEN_AUTHORIZED
,
Show
.
NEVER
,
this
.
statusAggregator
,
this
.
httpCodeStatusMapper
,
Show
.
WHEN_AUTHORIZED
,
Show
.
NEVER
,
Arrays
.
asList
(
"admin"
,
"root"
,
"bossmode"
));
Arrays
.
asList
(
"admin"
,
"root"
,
"bossmode"
));
given
(
this
.
securityContext
.
getPrincipal
()).
willReturn
(
this
.
principal
);
given
(
this
.
securityContext
.
getPrincipal
()).
willReturn
(
this
.
principal
);
given
(
this
.
securityContext
.
isUserInRole
(
"admin"
)).
willReturn
(
false
);
given
(
this
.
securityContext
.
isUserInRole
(
"root"
)).
willReturn
(
true
);
given
(
this
.
securityContext
.
isUserInRole
(
"root"
)).
willReturn
(
true
);
assertThat
(
group
.
showComponents
(
this
.
securityContext
)).
isTrue
();
assertThat
(
group
.
showComponents
(
this
.
securityContext
)).
isTrue
();
}
}
@Test
@Test
void
showComponentsWhenShowComponentsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse
()
{
void
showComponentsWhenShowComponentsIsWhenAuthorizedAndUse
r
IsNotInRoleReturnsFalse
()
{
AutoConfiguredHealthEndpointGroup
group
=
new
AutoConfiguredHealthEndpointGroup
((
name
)
->
true
,
AutoConfiguredHealthEndpointGroup
group
=
new
AutoConfiguredHealthEndpointGroup
((
name
)
->
true
,
this
.
statusAggregator
,
this
.
httpCodeStatusMapper
,
Show
.
WHEN_AUTHORIZED
,
Show
.
NEVER
,
this
.
statusAggregator
,
this
.
httpCodeStatusMapper
,
Show
.
WHEN_AUTHORIZED
,
Show
.
NEVER
,
Arrays
.
asList
(
"admin"
,
"rot"
,
"bossmode"
));
Arrays
.
asList
(
"admin"
,
"rot"
,
"bossmode"
));
given
(
this
.
securityContext
.
getPrincipal
()).
willReturn
(
this
.
principal
);
given
(
this
.
securityContext
.
getPrincipal
()).
willReturn
(
this
.
principal
);
given
(
this
.
securityContext
.
isUserInRole
(
"root"
)).
willReturn
(
true
);
assertThat
(
group
.
showComponents
(
this
.
securityContext
)).
isFalse
();
assertThat
(
group
.
showComponents
(
this
.
securityContext
)).
isFalse
();
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryConfigurerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -25,11 +25,11 @@ import io.micrometer.core.instrument.Metrics;
...
@@ -25,11 +25,11 @@ import io.micrometer.core.instrument.Metrics;
import
io.micrometer.core.instrument.binder.MeterBinder
;
import
io.micrometer.core.instrument.binder.MeterBinder
;
import
io.micrometer.core.instrument.composite.CompositeMeterRegistry
;
import
io.micrometer.core.instrument.composite.CompositeMeterRegistry
;
import
io.micrometer.core.instrument.config.MeterFilter
;
import
io.micrometer.core.instrument.config.MeterFilter
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.InOrder
;
import
org.mockito.InOrder
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.beans.factory.ObjectProvider
;
import
org.springframework.beans.factory.ObjectProvider
;
...
@@ -46,6 +46,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
...
@@ -46,6 +46,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
MeterRegistryConfigurerTests
{
class
MeterRegistryConfigurerTests
{
private
List
<
MeterBinder
>
binders
=
new
ArrayList
<>();
private
List
<
MeterBinder
>
binders
=
new
ArrayList
<>();
...
@@ -69,12 +70,6 @@ class MeterRegistryConfigurerTests {
...
@@ -69,12 +70,6 @@ class MeterRegistryConfigurerTests {
@Mock
@Mock
private
Config
mockConfig
;
private
Config
mockConfig
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
mockRegistry
.
config
()).
willReturn
(
this
.
mockConfig
);
}
@Test
@Test
void
configureWhenCompositeShouldApplyCustomizer
()
{
void
configureWhenCompositeShouldApplyCustomizer
()
{
this
.
customizers
.
add
(
this
.
mockCustomizer
);
this
.
customizers
.
add
(
this
.
mockCustomizer
);
...
@@ -87,6 +82,7 @@ class MeterRegistryConfigurerTests {
...
@@ -87,6 +82,7 @@ class MeterRegistryConfigurerTests {
@Test
@Test
void
configureShouldApplyCustomizer
()
{
void
configureShouldApplyCustomizer
()
{
given
(
this
.
mockRegistry
.
config
()).
willReturn
(
this
.
mockConfig
);
this
.
customizers
.
add
(
this
.
mockCustomizer
);
this
.
customizers
.
add
(
this
.
mockCustomizer
);
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
false
,
false
);
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
false
,
false
);
...
@@ -96,6 +92,7 @@ class MeterRegistryConfigurerTests {
...
@@ -96,6 +92,7 @@ class MeterRegistryConfigurerTests {
@Test
@Test
void
configureShouldApplyFilter
()
{
void
configureShouldApplyFilter
()
{
given
(
this
.
mockRegistry
.
config
()).
willReturn
(
this
.
mockConfig
);
this
.
filters
.
add
(
this
.
mockFilter
);
this
.
filters
.
add
(
this
.
mockFilter
);
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
false
,
false
);
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
false
,
false
);
...
@@ -105,6 +102,7 @@ class MeterRegistryConfigurerTests {
...
@@ -105,6 +102,7 @@ class MeterRegistryConfigurerTests {
@Test
@Test
void
configureShouldApplyBinder
()
{
void
configureShouldApplyBinder
()
{
given
(
this
.
mockRegistry
.
config
()).
willReturn
(
this
.
mockConfig
);
this
.
binders
.
add
(
this
.
mockBinder
);
this
.
binders
.
add
(
this
.
mockBinder
);
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
false
,
false
);
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
false
,
false
);
...
@@ -124,15 +122,16 @@ class MeterRegistryConfigurerTests {
...
@@ -124,15 +122,16 @@ class MeterRegistryConfigurerTests {
@Test
@Test
void
configureShouldNotApplyBinderWhenCompositeExists
()
{
void
configureShouldNotApplyBinderWhenCompositeExists
()
{
this
.
binders
.
add
(
this
.
mockBinder
);
given
(
this
.
mockRegistry
.
config
()).
willReturn
(
this
.
mockConfig
);
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
)
,
false
,
true
);
createObjectProvider
(
this
.
filters
),
null
,
false
,
true
);
configurer
.
configure
(
this
.
mockRegistry
);
configurer
.
configure
(
this
.
mockRegistry
);
verifyNoInteractions
(
this
.
mockBinder
);
verifyNoInteractions
(
this
.
mockBinder
);
}
}
@Test
@Test
void
configureShouldBeCalledInOrderCustomizerFilterBinder
()
{
void
configureShouldBeCalledInOrderCustomizerFilterBinder
()
{
given
(
this
.
mockRegistry
.
config
()).
willReturn
(
this
.
mockConfig
);
this
.
customizers
.
add
(
this
.
mockCustomizer
);
this
.
customizers
.
add
(
this
.
mockCustomizer
);
this
.
filters
.
add
(
this
.
mockFilter
);
this
.
filters
.
add
(
this
.
mockFilter
);
this
.
binders
.
add
(
this
.
mockBinder
);
this
.
binders
.
add
(
this
.
mockBinder
);
...
@@ -147,6 +146,7 @@ class MeterRegistryConfigurerTests {
...
@@ -147,6 +146,7 @@ class MeterRegistryConfigurerTests {
@Test
@Test
void
configureWhenAddToGlobalRegistryShouldAddToGlobalRegistry
()
{
void
configureWhenAddToGlobalRegistryShouldAddToGlobalRegistry
()
{
given
(
this
.
mockRegistry
.
config
()).
willReturn
(
this
.
mockConfig
);
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
true
,
false
);
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
true
,
false
);
try
{
try
{
...
@@ -160,6 +160,7 @@ class MeterRegistryConfigurerTests {
...
@@ -160,6 +160,7 @@ class MeterRegistryConfigurerTests {
@Test
@Test
void
configureWhenNotAddToGlobalRegistryShouldAddToGlobalRegistry
()
{
void
configureWhenNotAddToGlobalRegistryShouldAddToGlobalRegistry
()
{
given
(
this
.
mockRegistry
.
config
()).
willReturn
(
this
.
mockConfig
);
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
MeterRegistryConfigurer
configurer
=
new
MeterRegistryConfigurer
(
createObjectProvider
(
this
.
customizers
),
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
false
,
false
);
createObjectProvider
(
this
.
filters
),
createObjectProvider
(
this
.
binders
),
false
,
false
);
configurer
.
configure
(
this
.
mockRegistry
);
configurer
.
configure
(
this
.
mockRegistry
);
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/amqp/RabbitHealthIndicatorTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -20,10 +20,10 @@ import java.util.Collections;
...
@@ -20,10 +20,10 @@ import java.util.Collections;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Channel
;
import
com.rabbitmq.client.Connection
;
import
com.rabbitmq.client.Connection
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.amqp.rabbit.core.ChannelCallback
;
import
org.springframework.amqp.rabbit.core.ChannelCallback
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
...
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.mock;
...
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.mock;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
RabbitHealthIndicatorTests
{
class
RabbitHealthIndicatorTests
{
@Mock
@Mock
...
@@ -49,15 +50,6 @@ class RabbitHealthIndicatorTests {
...
@@ -49,15 +50,6 @@ class RabbitHealthIndicatorTests {
@Mock
@Mock
private
Channel
channel
;
private
Channel
channel
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
rabbitTemplate
.
execute
(
any
())).
willAnswer
((
invocation
)
->
{
ChannelCallback
<?>
callback
=
invocation
.
getArgument
(
0
);
return
callback
.
doInRabbit
(
this
.
channel
);
});
}
@Test
@Test
void
createWhenRabbitTemplateIsNullShouldThrowException
()
{
void
createWhenRabbitTemplateIsNullShouldThrowException
()
{
assertThatIllegalArgumentException
().
isThrownBy
(()
->
new
RabbitHealthIndicator
(
null
))
assertThatIllegalArgumentException
().
isThrownBy
(()
->
new
RabbitHealthIndicator
(
null
))
...
@@ -66,6 +58,7 @@ class RabbitHealthIndicatorTests {
...
@@ -66,6 +58,7 @@ class RabbitHealthIndicatorTests {
@Test
@Test
void
healthWhenConnectionSucceedsShouldReturnUpWithVersion
()
{
void
healthWhenConnectionSucceedsShouldReturnUpWithVersion
()
{
givenTemplateExecutionWillInvokeCallback
();
Connection
connection
=
mock
(
Connection
.
class
);
Connection
connection
=
mock
(
Connection
.
class
);
given
(
this
.
channel
.
getConnection
()).
willReturn
(
connection
);
given
(
this
.
channel
.
getConnection
()).
willReturn
(
connection
);
given
(
connection
.
getServerProperties
()).
willReturn
(
Collections
.
singletonMap
(
"version"
,
"123"
));
given
(
connection
.
getServerProperties
()).
willReturn
(
Collections
.
singletonMap
(
"version"
,
"123"
));
...
@@ -76,9 +69,17 @@ class RabbitHealthIndicatorTests {
...
@@ -76,9 +69,17 @@ class RabbitHealthIndicatorTests {
@Test
@Test
void
healthWhenConnectionFailsShouldReturnDown
()
{
void
healthWhenConnectionFailsShouldReturnDown
()
{
givenTemplateExecutionWillInvokeCallback
();
given
(
this
.
channel
.
getConnection
()).
willThrow
(
new
RuntimeException
());
given
(
this
.
channel
.
getConnection
()).
willThrow
(
new
RuntimeException
());
Health
health
=
new
RabbitHealthIndicator
(
this
.
rabbitTemplate
).
health
();
Health
health
=
new
RabbitHealthIndicator
(
this
.
rabbitTemplate
).
health
();
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
assertThat
(
health
.
getStatus
()).
isEqualTo
(
Status
.
DOWN
);
}
}
private
void
givenTemplateExecutionWillInvokeCallback
()
{
given
(
this
.
rabbitTemplate
.
execute
(
any
())).
willAnswer
((
invocation
)
->
{
ChannelCallback
<?>
callback
=
invocation
.
getArgument
(
0
);
return
callback
.
doInRabbit
(
this
.
channel
);
});
}
}
}
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/availability/AvailabilityStateHealthIndicatorTests.java
View file @
969dd35e
...
@@ -16,10 +16,10 @@
...
@@ -16,10 +16,10 @@
package
org
.
springframework
.
boot
.
actuate
.
availability
;
package
org
.
springframework
.
boot
.
actuate
.
availability
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.health.Status
;
import
org.springframework.boot.actuate.health.Status
;
import
org.springframework.boot.availability.ApplicationAvailability
;
import
org.springframework.boot.availability.ApplicationAvailability
;
...
@@ -35,16 +35,12 @@ import static org.mockito.BDDMockito.given;
...
@@ -35,16 +35,12 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
AvailabilityStateHealthIndicatorTests
{
class
AvailabilityStateHealthIndicatorTests
{
@Mock
@Mock
private
ApplicationAvailability
applicationAvailability
;
private
ApplicationAvailability
applicationAvailability
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
createWhenApplicationAvailabilityIsNullThrowsException
()
{
void
createWhenApplicationAvailabilityIsNullThrowsException
()
{
assertThatIllegalArgumentException
()
assertThatIllegalArgumentException
()
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/invoker/cache/CachingOperationInvokerAdvisorTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -21,8 +21,9 @@ import java.util.function.Function;
...
@@ -21,8 +21,9 @@ import java.util.function.Function;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.endpoint.EndpointId
;
import
org.springframework.boot.actuate.endpoint.EndpointId
;
import
org.springframework.boot.actuate.endpoint.OperationType
;
import
org.springframework.boot.actuate.endpoint.OperationType
;
...
@@ -45,6 +46,7 @@ import static org.mockito.Mockito.verify;
...
@@ -45,6 +46,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
CachingOperationInvokerAdvisorTests
{
class
CachingOperationInvokerAdvisorTests
{
@Mock
@Mock
...
@@ -57,7 +59,6 @@ class CachingOperationInvokerAdvisorTests {
...
@@ -57,7 +59,6 @@ class CachingOperationInvokerAdvisorTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
advisor
=
new
CachingOperationInvokerAdvisor
(
this
.
timeToLive
);
this
.
advisor
=
new
CachingOperationInvokerAdvisor
(
this
.
timeToLive
);
}
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JmxEndpointExporterTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -27,10 +27,12 @@ import javax.management.ObjectName;
...
@@ -27,10 +27,12 @@ import javax.management.ObjectName;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.mockito.Spy
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.springframework.jmx.JmxException
;
import
org.springframework.jmx.JmxException
;
import
org.springframework.jmx.export.MBeanExportException
;
import
org.springframework.jmx.export.MBeanExportException
;
...
@@ -42,7 +44,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
...
@@ -42,7 +44,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
/**
...
@@ -51,12 +52,14 @@ import static org.mockito.Mockito.verify;
...
@@ -51,12 +52,14 @@ import static org.mockito.Mockito.verify;
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
JmxEndpointExporterTests
{
class
JmxEndpointExporterTests
{
@Mock
@Mock
private
MBeanServer
mBeanServer
;
private
MBeanServer
mBeanServer
;
private
EndpointObjectNameFactory
objectNameFactory
=
spy
(
new
TestEndpointObjectNameFactory
());
@Spy
private
EndpointObjectNameFactory
objectNameFactory
=
new
TestEndpointObjectNameFactory
();
private
JmxOperationResponseMapper
responseMapper
=
new
TestJmxOperationResponseMapper
();
private
JmxOperationResponseMapper
responseMapper
=
new
TestJmxOperationResponseMapper
();
...
@@ -72,7 +75,6 @@ class JmxEndpointExporterTests {
...
@@ -72,7 +75,6 @@ class JmxEndpointExporterTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
exporter
=
new
JmxEndpointExporter
(
this
.
mBeanServer
,
this
.
objectNameFactory
,
this
.
responseMapper
,
this
.
exporter
=
new
JmxEndpointExporter
(
this
.
mBeanServer
,
this
.
objectNameFactory
,
this
.
responseMapper
,
this
.
endpoints
);
this
.
endpoints
);
}
}
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/ServletEndpointRegistrarTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -26,12 +26,12 @@ import javax.servlet.ServletRegistration.Dynamic;
...
@@ -26,12 +26,12 @@ import javax.servlet.ServletRegistration.Dynamic;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.ServletResponse
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.endpoint.EndpointId
;
import
org.springframework.boot.actuate.endpoint.EndpointId
;
...
@@ -49,6 +49,7 @@ import static org.mockito.Mockito.verify;
...
@@ -49,6 +49,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ServletEndpointRegistrarTests
{
class
ServletEndpointRegistrarTests
{
@Mock
@Mock
...
@@ -60,12 +61,6 @@ class ServletEndpointRegistrarTests {
...
@@ -60,12 +61,6 @@ class ServletEndpointRegistrarTests {
@Captor
@Captor
private
ArgumentCaptor
<
Servlet
>
servlet
;
private
ArgumentCaptor
<
Servlet
>
servlet
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
servletContext
.
addServlet
(
any
(
String
.
class
),
any
(
Servlet
.
class
))).
willReturn
(
this
.
dynamic
);
}
@Test
@Test
void
createWhenServletEndpointsIsNullShouldThrowException
()
{
void
createWhenServletEndpointsIsNullShouldThrowException
()
{
assertThatIllegalArgumentException
().
isThrownBy
(()
->
new
ServletEndpointRegistrar
(
null
,
null
))
assertThatIllegalArgumentException
().
isThrownBy
(()
->
new
ServletEndpointRegistrar
(
null
,
null
))
...
@@ -93,6 +88,7 @@ class ServletEndpointRegistrarTests {
...
@@ -93,6 +88,7 @@ class ServletEndpointRegistrarTests {
}
}
private
void
assertBasePath
(
String
basePath
,
String
expectedMapping
)
throws
ServletException
{
private
void
assertBasePath
(
String
basePath
,
String
expectedMapping
)
throws
ServletException
{
given
(
this
.
servletContext
.
addServlet
(
any
(
String
.
class
),
any
(
Servlet
.
class
))).
willReturn
(
this
.
dynamic
);
ExposableServletEndpoint
endpoint
=
mockEndpoint
(
new
EndpointServlet
(
TestServlet
.
class
));
ExposableServletEndpoint
endpoint
=
mockEndpoint
(
new
EndpointServlet
(
TestServlet
.
class
));
ServletEndpointRegistrar
registrar
=
new
ServletEndpointRegistrar
(
basePath
,
Collections
.
singleton
(
endpoint
));
ServletEndpointRegistrar
registrar
=
new
ServletEndpointRegistrar
(
basePath
,
Collections
.
singleton
(
endpoint
));
registrar
.
onStartup
(
this
.
servletContext
);
registrar
.
onStartup
(
this
.
servletContext
);
...
@@ -103,6 +99,7 @@ class ServletEndpointRegistrarTests {
...
@@ -103,6 +99,7 @@ class ServletEndpointRegistrarTests {
@Test
@Test
void
onStartupWhenHasInitParametersShouldRegisterInitParameters
()
throws
Exception
{
void
onStartupWhenHasInitParametersShouldRegisterInitParameters
()
throws
Exception
{
given
(
this
.
servletContext
.
addServlet
(
any
(
String
.
class
),
any
(
Servlet
.
class
))).
willReturn
(
this
.
dynamic
);
ExposableServletEndpoint
endpoint
=
mockEndpoint
(
ExposableServletEndpoint
endpoint
=
mockEndpoint
(
new
EndpointServlet
(
TestServlet
.
class
).
withInitParameter
(
"a"
,
"b"
));
new
EndpointServlet
(
TestServlet
.
class
).
withInitParameter
(
"a"
,
"b"
));
ServletEndpointRegistrar
registrar
=
new
ServletEndpointRegistrar
(
"/actuator"
,
Collections
.
singleton
(
endpoint
));
ServletEndpointRegistrar
registrar
=
new
ServletEndpointRegistrar
(
"/actuator"
,
Collections
.
singleton
(
endpoint
));
...
@@ -112,6 +109,7 @@ class ServletEndpointRegistrarTests {
...
@@ -112,6 +109,7 @@ class ServletEndpointRegistrarTests {
@Test
@Test
void
onStartupWhenHasLoadOnStartupShouldRegisterLoadOnStartup
()
throws
Exception
{
void
onStartupWhenHasLoadOnStartupShouldRegisterLoadOnStartup
()
throws
Exception
{
given
(
this
.
servletContext
.
addServlet
(
any
(
String
.
class
),
any
(
Servlet
.
class
))).
willReturn
(
this
.
dynamic
);
ExposableServletEndpoint
endpoint
=
mockEndpoint
(
new
EndpointServlet
(
TestServlet
.
class
).
withLoadOnStartup
(
7
));
ExposableServletEndpoint
endpoint
=
mockEndpoint
(
new
EndpointServlet
(
TestServlet
.
class
).
withLoadOnStartup
(
7
));
ServletEndpointRegistrar
registrar
=
new
ServletEndpointRegistrar
(
"/actuator"
,
Collections
.
singleton
(
endpoint
));
ServletEndpointRegistrar
registrar
=
new
ServletEndpointRegistrar
(
"/actuator"
,
Collections
.
singleton
(
endpoint
));
registrar
.
onStartup
(
this
.
servletContext
);
registrar
.
onStartup
(
this
.
servletContext
);
...
@@ -120,6 +118,7 @@ class ServletEndpointRegistrarTests {
...
@@ -120,6 +118,7 @@ class ServletEndpointRegistrarTests {
@Test
@Test
void
onStartupWhenHasNotLoadOnStartupShouldRegisterDefaultValue
()
throws
Exception
{
void
onStartupWhenHasNotLoadOnStartupShouldRegisterDefaultValue
()
throws
Exception
{
given
(
this
.
servletContext
.
addServlet
(
any
(
String
.
class
),
any
(
Servlet
.
class
))).
willReturn
(
this
.
dynamic
);
ExposableServletEndpoint
endpoint
=
mockEndpoint
(
new
EndpointServlet
(
TestServlet
.
class
));
ExposableServletEndpoint
endpoint
=
mockEndpoint
(
new
EndpointServlet
(
TestServlet
.
class
));
ServletEndpointRegistrar
registrar
=
new
ServletEndpointRegistrar
(
"/actuator"
,
Collections
.
singleton
(
endpoint
));
ServletEndpointRegistrar
registrar
=
new
ServletEndpointRegistrar
(
"/actuator"
,
Collections
.
singleton
(
endpoint
));
registrar
.
onStartup
(
this
.
servletContext
);
registrar
.
onStartup
(
this
.
servletContext
);
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/export/prometheus/PrometheusPushGatewayManagerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -24,12 +24,12 @@ import java.util.concurrent.ScheduledFuture;
...
@@ -24,12 +24,12 @@ import java.util.concurrent.ScheduledFuture;
import
io.prometheus.client.CollectorRegistry
;
import
io.prometheus.client.CollectorRegistry
;
import
io.prometheus.client.exporter.PushGateway
;
import
io.prometheus.client.exporter.PushGateway
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager.PushGatewayTaskScheduler
;
import
org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager.PushGatewayTaskScheduler
;
import
org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager.ShutdownOperation
;
import
org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager.ShutdownOperation
;
...
@@ -51,6 +51,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
...
@@ -51,6 +51,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
PrometheusPushGatewayManagerTests
{
class
PrometheusPushGatewayManagerTests
{
@Mock
@Mock
...
@@ -59,6 +60,7 @@ class PrometheusPushGatewayManagerTests {
...
@@ -59,6 +60,7 @@ class PrometheusPushGatewayManagerTests {
@Mock
@Mock
private
CollectorRegistry
registry
;
private
CollectorRegistry
registry
;
@Mock
private
TaskScheduler
scheduler
;
private
TaskScheduler
scheduler
;
private
Duration
pushRate
=
Duration
.
ofSeconds
(
1
);
private
Duration
pushRate
=
Duration
.
ofSeconds
(
1
);
...
@@ -71,12 +73,6 @@ class PrometheusPushGatewayManagerTests {
...
@@ -71,12 +73,6 @@ class PrometheusPushGatewayManagerTests {
@Mock
@Mock
private
ScheduledFuture
<
Object
>
future
;
private
ScheduledFuture
<
Object
>
future
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
scheduler
=
mockScheduler
(
TaskScheduler
.
class
);
}
@Test
@Test
void
createWhenPushGatewayIsNullThrowsException
()
{
void
createWhenPushGatewayIsNullThrowsException
()
{
assertThatIllegalArgumentException
().
isThrownBy
(()
->
new
PrometheusPushGatewayManager
(
null
,
this
.
registry
,
assertThatIllegalArgumentException
().
isThrownBy
(()
->
new
PrometheusPushGatewayManager
(
null
,
this
.
registry
,
...
@@ -122,7 +118,8 @@ class PrometheusPushGatewayManagerTests {
...
@@ -122,7 +118,8 @@ class PrometheusPushGatewayManagerTests {
@Test
@Test
void
shutdownWhenOwnsSchedulerDoesShutdownScheduler
()
{
void
shutdownWhenOwnsSchedulerDoesShutdownScheduler
()
{
PushGatewayTaskScheduler
ownedScheduler
=
mockScheduler
(
PushGatewayTaskScheduler
.
class
);
PushGatewayTaskScheduler
ownedScheduler
=
givenScheduleAtFixedRateWillReturnFuture
(
mock
(
PushGatewayTaskScheduler
.
class
));
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
ownedScheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
null
);
ownedScheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
null
);
manager
.
shutdown
();
manager
.
shutdown
();
...
@@ -131,7 +128,8 @@ class PrometheusPushGatewayManagerTests {
...
@@ -131,7 +128,8 @@ class PrometheusPushGatewayManagerTests {
@Test
@Test
void
shutdownWhenDoesNotOwnSchedulerDoesNotShutdownScheduler
()
{
void
shutdownWhenDoesNotOwnSchedulerDoesNotShutdownScheduler
()
{
ThreadPoolTaskScheduler
otherScheduler
=
mockScheduler
(
ThreadPoolTaskScheduler
.
class
);
ThreadPoolTaskScheduler
otherScheduler
=
givenScheduleAtFixedRateWillReturnFuture
(
mock
(
ThreadPoolTaskScheduler
.
class
));
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
otherScheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
null
);
otherScheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
null
);
manager
.
shutdown
();
manager
.
shutdown
();
...
@@ -140,6 +138,7 @@ class PrometheusPushGatewayManagerTests {
...
@@ -140,6 +138,7 @@ class PrometheusPushGatewayManagerTests {
@Test
@Test
void
shutdownWhenShutdownOperationIsPushPerformsPushOnShutdown
()
throws
Exception
{
void
shutdownWhenShutdownOperationIsPushPerformsPushOnShutdown
()
throws
Exception
{
givenScheduleAtFixedRateWithReturnFuture
();
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
this
.
scheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
ShutdownOperation
.
PUSH
);
this
.
scheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
ShutdownOperation
.
PUSH
);
manager
.
shutdown
();
manager
.
shutdown
();
...
@@ -149,6 +148,7 @@ class PrometheusPushGatewayManagerTests {
...
@@ -149,6 +148,7 @@ class PrometheusPushGatewayManagerTests {
@Test
@Test
void
shutdownWhenShutdownOperationIsDeletePerformsDeleteOnShutdown
()
throws
Exception
{
void
shutdownWhenShutdownOperationIsDeletePerformsDeleteOnShutdown
()
throws
Exception
{
givenScheduleAtFixedRateWithReturnFuture
();
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
this
.
scheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
ShutdownOperation
.
DELETE
);
this
.
scheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
ShutdownOperation
.
DELETE
);
manager
.
shutdown
();
manager
.
shutdown
();
...
@@ -158,6 +158,7 @@ class PrometheusPushGatewayManagerTests {
...
@@ -158,6 +158,7 @@ class PrometheusPushGatewayManagerTests {
@Test
@Test
void
shutdownWhenShutdownOperationIsNoneDoesNothing
()
{
void
shutdownWhenShutdownOperationIsNoneDoesNothing
()
{
givenScheduleAtFixedRateWithReturnFuture
();
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
PrometheusPushGatewayManager
manager
=
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
this
.
scheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
ShutdownOperation
.
NONE
);
this
.
scheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
ShutdownOperation
.
NONE
);
manager
.
shutdown
();
manager
.
shutdown
();
...
@@ -167,6 +168,7 @@ class PrometheusPushGatewayManagerTests {
...
@@ -167,6 +168,7 @@ class PrometheusPushGatewayManagerTests {
@Test
@Test
void
pushWhenUnknownHostExceptionIsThrownDoesShutdown
()
throws
Exception
{
void
pushWhenUnknownHostExceptionIsThrownDoesShutdown
()
throws
Exception
{
givenScheduleAtFixedRateWithReturnFuture
();
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
this
.
scheduler
,
this
.
pushRate
,
"job"
,
new
PrometheusPushGatewayManager
(
this
.
pushGateway
,
this
.
registry
,
this
.
scheduler
,
this
.
pushRate
,
"job"
,
this
.
groupingKey
,
null
);
this
.
groupingKey
,
null
);
verify
(
this
.
scheduler
).
scheduleAtFixedRate
(
this
.
task
.
capture
(),
eq
(
this
.
pushRate
));
verify
(
this
.
scheduler
).
scheduleAtFixedRate
(
this
.
task
.
capture
(),
eq
(
this
.
pushRate
));
...
@@ -185,9 +187,12 @@ class PrometheusPushGatewayManagerTests {
...
@@ -185,9 +187,12 @@ class PrometheusPushGatewayManagerTests {
this
.
task
.
getValue
().
run
();
this
.
task
.
getValue
().
run
();
}
}
private
void
givenScheduleAtFixedRateWithReturnFuture
()
{
givenScheduleAtFixedRateWillReturnFuture
(
this
.
scheduler
);
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
private
<
T
extends
TaskScheduler
>
T
mockScheduler
(
Class
<
T
>
type
)
{
private
<
T
extends
TaskScheduler
>
T
givenScheduleAtFixedRateWillReturnFuture
(
T
scheduler
)
{
T
scheduler
=
mock
(
type
);
given
(
scheduler
.
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
isA
(
Duration
.
class
)))
given
(
scheduler
.
scheduleAtFixedRate
(
isA
(
Runnable
.
class
),
isA
(
Duration
.
class
)))
.
willReturn
((
ScheduledFuture
)
this
.
future
);
.
willReturn
((
ScheduledFuture
)
this
.
future
);
return
scheduler
;
return
scheduler
;
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/system/DiskSpaceHealthIndicatorTests.java
View file @
969dd35e
...
@@ -20,8 +20,9 @@ import java.io.File;
...
@@ -20,8 +20,9 @@ import java.io.File;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
...
@@ -37,6 +38,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -37,6 +38,7 @@ import static org.mockito.BDDMockito.given;
* @author Mattias Severson
* @author Mattias Severson
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
DiskSpaceHealthIndicatorTests
{
class
DiskSpaceHealthIndicatorTests
{
private
static
final
DataSize
THRESHOLD
=
DataSize
.
ofKilobytes
(
1
);
private
static
final
DataSize
THRESHOLD
=
DataSize
.
ofKilobytes
(
1
);
...
@@ -50,13 +52,12 @@ class DiskSpaceHealthIndicatorTests {
...
@@ -50,13 +52,12 @@ class DiskSpaceHealthIndicatorTests {
@BeforeEach
@BeforeEach
void
setUp
()
{
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
fileMock
.
exists
()).
willReturn
(
true
);
this
.
healthIndicator
=
new
DiskSpaceHealthIndicator
(
this
.
fileMock
,
THRESHOLD
);
this
.
healthIndicator
=
new
DiskSpaceHealthIndicator
(
this
.
fileMock
,
THRESHOLD
);
}
}
@Test
@Test
void
diskSpaceIsUp
()
{
void
diskSpaceIsUp
()
{
given
(
this
.
fileMock
.
exists
()).
willReturn
(
true
);
long
freeSpace
=
THRESHOLD
.
toBytes
()
+
10
;
long
freeSpace
=
THRESHOLD
.
toBytes
()
+
10
;
given
(
this
.
fileMock
.
getUsableSpace
()).
willReturn
(
freeSpace
);
given
(
this
.
fileMock
.
getUsableSpace
()).
willReturn
(
freeSpace
);
given
(
this
.
fileMock
.
getTotalSpace
()).
willReturn
(
TOTAL_SPACE
.
toBytes
());
given
(
this
.
fileMock
.
getTotalSpace
()).
willReturn
(
TOTAL_SPACE
.
toBytes
());
...
@@ -70,6 +71,7 @@ class DiskSpaceHealthIndicatorTests {
...
@@ -70,6 +71,7 @@ class DiskSpaceHealthIndicatorTests {
@Test
@Test
void
diskSpaceIsDown
()
{
void
diskSpaceIsDown
()
{
given
(
this
.
fileMock
.
exists
()).
willReturn
(
true
);
long
freeSpace
=
THRESHOLD
.
toBytes
()
-
10
;
long
freeSpace
=
THRESHOLD
.
toBytes
()
-
10
;
given
(
this
.
fileMock
.
getUsableSpace
()).
willReturn
(
freeSpace
);
given
(
this
.
fileMock
.
getUsableSpace
()).
willReturn
(
freeSpace
);
given
(
this
.
fileMock
.
getTotalSpace
()).
willReturn
(
TOTAL_SPACE
.
toBytes
());
given
(
this
.
fileMock
.
getTotalSpace
()).
willReturn
(
TOTAL_SPACE
.
toBytes
());
...
...
spring-boot-project/spring-boot-autoconfigure/build.gradle
View file @
969dd35e
...
@@ -171,6 +171,7 @@ dependencies {
...
@@ -171,6 +171,7 @@ dependencies {
testImplementation
(
"org.jetbrains.kotlin:kotlin-stdlib-jdk8"
)
testImplementation
(
"org.jetbrains.kotlin:kotlin-stdlib-jdk8"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.springframework:spring-test"
)
testImplementation
(
"org.springframework:spring-test"
)
testImplementation
(
"org.springframework.kafka:spring-kafka-test"
)
testImplementation
(
"org.springframework.kafka:spring-kafka-test"
)
testImplementation
(
"org.springframework.security:spring-security-test"
)
testImplementation
(
"org.springframework.security:spring-security-test"
)
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -23,8 +23,9 @@ import java.util.Map;
...
@@ -23,8 +23,9 @@ import java.util.Map;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
...
@@ -53,6 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -53,6 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Greg Turnquist
* @author Greg Turnquist
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ConditionEvaluationReportTests
{
class
ConditionEvaluationReportTests
{
private
DefaultListableBeanFactory
beanFactory
;
private
DefaultListableBeanFactory
beanFactory
;
...
@@ -76,7 +78,6 @@ class ConditionEvaluationReportTests {
...
@@ -76,7 +78,6 @@ class ConditionEvaluationReportTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
beanFactory
=
new
DefaultListableBeanFactory
();
this
.
beanFactory
=
new
DefaultListableBeanFactory
();
this
.
report
=
ConditionEvaluationReport
.
get
(
this
.
beanFactory
);
this
.
report
=
ConditionEvaluationReport
.
get
(
this
.
beanFactory
);
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -21,10 +21,10 @@ import java.util.function.Consumer;
...
@@ -21,10 +21,10 @@ import java.util.function.Consumer;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
org.hibernate.cfg.AvailableSettings
;
import
org.hibernate.cfg.AvailableSettings
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
;
import
org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
;
...
@@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify;
...
@@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify;
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Artsiom Yudovin
* @author Artsiom Yudovin
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
HibernatePropertiesTests
{
class
HibernatePropertiesTests
{
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
...
@@ -53,11 +54,6 @@ class HibernatePropertiesTests {
...
@@ -53,11 +54,6 @@ class HibernatePropertiesTests {
@Mock
@Mock
private
Supplier
<
String
>
ddlAutoSupplier
;
private
Supplier
<
String
>
ddlAutoSupplier
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
noCustomNamingStrategy
()
{
void
noCustomNamingStrategy
()
{
this
.
contextRunner
.
run
(
assertHibernateProperties
((
hibernateProperties
)
->
{
this
.
contextRunner
.
run
(
assertHibernateProperties
((
hibernateProperties
)
->
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProvidersTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -21,8 +21,9 @@ import java.util.Collections;
...
@@ -21,8 +21,9 @@ import java.util.Collections;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.core.io.ResourceLoader
;
...
@@ -40,6 +41,7 @@ import static org.mockito.Mockito.verify;
...
@@ -40,6 +41,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
TemplateAvailabilityProvidersTests
{
class
TemplateAvailabilityProvidersTests
{
private
TemplateAvailabilityProviders
providers
;
private
TemplateAvailabilityProviders
providers
;
...
@@ -58,7 +60,6 @@ class TemplateAvailabilityProvidersTests {
...
@@ -58,7 +60,6 @@ class TemplateAvailabilityProvidersTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
providers
=
new
TemplateAvailabilityProviders
(
Collections
.
singleton
(
this
.
provider
));
this
.
providers
=
new
TemplateAvailabilityProviders
(
Collections
.
singleton
(
this
.
provider
));
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java
View file @
969dd35e
...
@@ -22,9 +22,10 @@ import java.util.Map;
...
@@ -22,9 +22,10 @@ import java.util.Map;
import
io.netty.channel.ChannelOption
;
import
io.netty.channel.ChannelOption
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
reactor.netty.http.server.HttpRequestDecoderSpec
;
import
reactor.netty.http.server.HttpRequestDecoderSpec
;
import
reactor.netty.http.server.HttpServer
;
import
reactor.netty.http.server.HttpServer
;
...
@@ -49,6 +50,7 @@ import static org.mockito.Mockito.verify;
...
@@ -49,6 +50,7 @@ import static org.mockito.Mockito.verify;
* @author Brian Clozel
* @author Brian Clozel
* @author Artsiom Yudovin
* @author Artsiom Yudovin
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
NettyWebServerFactoryCustomizerTests
{
class
NettyWebServerFactoryCustomizerTests
{
private
MockEnvironment
environment
;
private
MockEnvironment
environment
;
...
@@ -62,7 +64,6 @@ class NettyWebServerFactoryCustomizerTests {
...
@@ -62,7 +64,6 @@ class NettyWebServerFactoryCustomizerTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
environment
=
new
MockEnvironment
();
this
.
environment
=
new
MockEnvironment
();
this
.
serverProperties
=
new
ServerProperties
();
this
.
serverProperties
=
new
ServerProperties
();
ConfigurationPropertySources
.
attach
(
this
.
environment
);
ConfigurationPropertySources
.
attach
(
this
.
environment
);
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/DefaultErrorViewResolverTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -24,8 +24,9 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -24,8 +24,9 @@ import javax.servlet.http.HttpServletRequest;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider
;
import
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider
;
import
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders
;
import
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders
;
...
@@ -56,6 +57,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
...
@@ -56,6 +57,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
DefaultErrorViewResolverTests
{
class
DefaultErrorViewResolverTests
{
private
DefaultErrorViewResolver
resolver
;
private
DefaultErrorViewResolver
resolver
;
...
@@ -71,7 +73,6 @@ class DefaultErrorViewResolverTests {
...
@@ -71,7 +73,6 @@ class DefaultErrorViewResolverTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
AnnotationConfigApplicationContext
applicationContext
=
new
AnnotationConfigApplicationContext
();
AnnotationConfigApplicationContext
applicationContext
=
new
AnnotationConfigApplicationContext
();
applicationContext
.
refresh
();
applicationContext
.
refresh
();
this
.
resourceProperties
=
new
ResourceProperties
();
this
.
resourceProperties
=
new
ResourceProperties
();
...
@@ -115,6 +116,8 @@ class DefaultErrorViewResolverTests {
...
@@ -115,6 +116,8 @@ class DefaultErrorViewResolverTests {
@Test
@Test
void
resolveWhenSeries5xxTemplateMatchShouldReturnTemplate
()
{
void
resolveWhenSeries5xxTemplateMatchShouldReturnTemplate
()
{
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/503"
),
any
(
Environment
.
class
),
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
false
);
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/5xx"
),
any
(
Environment
.
class
),
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/5xx"
),
any
(
Environment
.
class
),
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
true
);
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
true
);
ModelAndView
resolved
=
this
.
resolver
.
resolveErrorView
(
this
.
request
,
HttpStatus
.
SERVICE_UNAVAILABLE
,
ModelAndView
resolved
=
this
.
resolver
.
resolveErrorView
(
this
.
request
,
HttpStatus
.
SERVICE_UNAVAILABLE
,
...
@@ -124,6 +127,8 @@ class DefaultErrorViewResolverTests {
...
@@ -124,6 +127,8 @@ class DefaultErrorViewResolverTests {
@Test
@Test
void
resolveWhenSeries4xxTemplateMatchShouldReturnTemplate
()
{
void
resolveWhenSeries4xxTemplateMatchShouldReturnTemplate
()
{
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/404"
),
any
(
Environment
.
class
),
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
false
);
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/4xx"
),
any
(
Environment
.
class
),
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/4xx"
),
any
(
Environment
.
class
),
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
true
);
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
true
);
ModelAndView
resolved
=
this
.
resolver
.
resolveErrorView
(
this
.
request
,
HttpStatus
.
NOT_FOUND
,
this
.
model
);
ModelAndView
resolved
=
this
.
resolver
.
resolveErrorView
(
this
.
request
,
HttpStatus
.
NOT_FOUND
,
this
.
model
);
...
@@ -170,9 +175,10 @@ class DefaultErrorViewResolverTests {
...
@@ -170,9 +175,10 @@ class DefaultErrorViewResolverTests {
@Test
@Test
void
resolveWhenExactResourceMatchAndSeriesTemplateMatchShouldFavorResource
()
throws
Exception
{
void
resolveWhenExactResourceMatchAndSeriesTemplateMatchShouldFavorResource
()
throws
Exception
{
setResourceLocation
(
"/exact"
);
setResourceLocation
(
"/exact"
);
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/4
xx
"
),
any
(
Environment
.
class
),
given
(
this
.
templateAvailabilityProvider
.
isTemplateAvailable
(
eq
(
"error/4
04
"
),
any
(
Environment
.
class
),
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
tru
e
);
any
(
ClassLoader
.
class
),
any
(
ResourceLoader
.
class
))).
willReturn
(
fals
e
);
ModelAndView
resolved
=
this
.
resolver
.
resolveErrorView
(
this
.
request
,
HttpStatus
.
NOT_FOUND
,
this
.
model
);
ModelAndView
resolved
=
this
.
resolver
.
resolveErrorView
(
this
.
request
,
HttpStatus
.
NOT_FOUND
,
this
.
model
);
verifyNoMoreInteractions
(
this
.
templateAvailabilityProvider
);
MockHttpServletResponse
response
=
render
(
resolved
);
MockHttpServletResponse
response
=
render
(
resolved
);
assertThat
(
response
.
getContentAsString
().
trim
()).
isEqualTo
(
"exact/404"
);
assertThat
(
response
.
getContentAsString
().
trim
()).
isEqualTo
(
"exact/404"
);
assertThat
(
response
.
getContentType
()).
isEqualTo
(
MediaType
.
TEXT_HTML_VALUE
);
assertThat
(
response
.
getContentType
()).
isEqualTo
(
MediaType
.
TEXT_HTML_VALUE
);
...
...
spring-boot-project/spring-boot-cli/build.gradle
View file @
969dd35e
...
@@ -63,6 +63,7 @@ dependencies {
...
@@ -63,6 +63,7 @@ dependencies {
testImplementation
(
"org.codehaus.groovy:groovy-templates"
)
testImplementation
(
"org.codehaus.groovy:groovy-templates"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.springframework:spring-test"
)
testImplementation
(
"org.springframework:spring-test"
)
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"
,
configuration:
"mavenRepository"
))
testRepository
(
project
(
path:
":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"
,
configuration:
"mavenRepository"
))
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/CommandRunnerTests.java
View file @
969dd35e
...
@@ -22,16 +22,17 @@ import java.util.Set;
...
@@ -22,16 +22,17 @@ import java.util.Set;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.cli.command.core.HelpCommand
;
import
org.springframework.boot.cli.command.core.HelpCommand
;
import
org.springframework.boot.cli.command.core.HintCommand
;
import
org.springframework.boot.cli.command.core.HintCommand
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
Mockito
.
lenient
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
/**
...
@@ -40,6 +41,7 @@ import static org.mockito.Mockito.verify;
...
@@ -40,6 +41,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
* @author Dave Syer
* @author Dave Syer
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
CommandRunnerTests
{
class
CommandRunnerTests
{
private
CommandRunner
commandRunner
;
private
CommandRunner
commandRunner
;
...
@@ -63,7 +65,6 @@ class CommandRunnerTests {
...
@@ -63,7 +65,6 @@ class CommandRunnerTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
this
.
loader
=
Thread
.
currentThread
().
getContextClassLoader
();
this
.
loader
=
Thread
.
currentThread
().
getContextClassLoader
();
MockitoAnnotations
.
initMocks
(
this
);
this
.
commandRunner
=
new
CommandRunner
(
"spring"
)
{
this
.
commandRunner
=
new
CommandRunner
(
"spring"
)
{
@Override
@Override
...
@@ -84,9 +85,9 @@ class CommandRunnerTests {
...
@@ -84,9 +85,9 @@ class CommandRunnerTests {
super
.
printStackTrace
(
ex
);
super
.
printStackTrace
(
ex
);
}
}
};
};
given
(
this
.
anotherCommand
.
getName
()).
willReturn
(
"another"
);
lenient
().
doReturn
(
"another"
).
when
(
this
.
anotherCommand
).
getName
(
);
given
(
this
.
regularCommand
.
getName
()).
willReturn
(
"command"
);
lenient
().
doReturn
(
"command"
).
when
(
this
.
regularCommand
).
getName
(
);
given
(
this
.
regularCommand
.
getDescription
()).
willReturn
(
"A regular command"
);
lenient
().
doReturn
(
"A regular command"
).
when
(
this
.
regularCommand
).
getDescription
(
);
this
.
commandRunner
.
addCommand
(
this
.
regularCommand
);
this
.
commandRunner
.
addCommand
(
this
.
regularCommand
);
this
.
commandRunner
.
addCommand
(
new
HelpCommand
(
this
.
commandRunner
));
this
.
commandRunner
.
addCommand
(
new
HelpCommand
(
this
.
commandRunner
));
this
.
commandRunner
.
addCommand
(
new
HintCommand
(
this
.
commandRunner
));
this
.
commandRunner
.
addCommand
(
new
HintCommand
(
this
.
commandRunner
));
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/encodepassword/EncodePasswordCommandTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -19,9 +19,10 @@ package org.springframework.boot.cli.command.encodepassword;
...
@@ -19,9 +19,10 @@ package org.springframework.boot.cli.command.encodepassword;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.cli.command.status.ExitStatus
;
import
org.springframework.boot.cli.command.status.ExitStatus
;
import
org.springframework.boot.cli.util.MockLog
;
import
org.springframework.boot.cli.util.MockLog
;
...
@@ -37,6 +38,7 @@ import static org.mockito.Mockito.verify;
...
@@ -37,6 +38,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
EncodePasswordCommandTests
{
class
EncodePasswordCommandTests
{
private
MockLog
log
;
private
MockLog
log
;
...
@@ -46,7 +48,6 @@ class EncodePasswordCommandTests {
...
@@ -46,7 +48,6 @@ class EncodePasswordCommandTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
log
=
MockLog
.
attach
();
this
.
log
=
MockLog
.
attach
();
}
}
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/init/InitCommandTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -27,12 +27,12 @@ import java.util.zip.ZipOutputStream;
...
@@ -27,12 +27,12 @@ import java.util.zip.ZipOutputStream;
import
joptsimple.OptionSet
;
import
joptsimple.OptionSet
;
import
org.apache.http.Header
;
import
org.apache.http.Header
;
import
org.apache.http.client.methods.HttpUriRequest
;
import
org.apache.http.client.methods.HttpUriRequest
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.cli.command.status.ExitStatus
;
import
org.springframework.boot.cli.command.status.ExitStatus
;
...
@@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify;
...
@@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify;
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Eddú Meléndez
* @author Eddú Meléndez
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
InitCommandTests
extends
AbstractHttpClientMockTests
{
class
InitCommandTests
extends
AbstractHttpClientMockTests
{
private
final
TestableInitCommandOptionHandler
handler
;
private
final
TestableInitCommandOptionHandler
handler
;
...
@@ -54,11 +55,6 @@ class InitCommandTests extends AbstractHttpClientMockTests {
...
@@ -54,11 +55,6 @@ class InitCommandTests extends AbstractHttpClientMockTests {
@Captor
@Captor
private
ArgumentCaptor
<
HttpUriRequest
>
requestCaptor
;
private
ArgumentCaptor
<
HttpUriRequest
>
requestCaptor
;
@BeforeEach
void
setupMocks
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
InitCommandTests
()
{
InitCommandTests
()
{
InitializrService
initializrService
=
new
InitializrService
(
this
.
http
);
InitializrService
initializrService
=
new
InitializrService
(
this
.
http
);
this
.
handler
=
new
TestableInitCommandOptionHandler
(
initializrService
);
this
.
handler
=
new
TestableInitCommandOptionHandler
(
initializrService
);
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java
View file @
969dd35e
...
@@ -27,8 +27,9 @@ import org.codehaus.groovy.ast.expr.ConstantExpression;
...
@@ -27,8 +27,9 @@ import org.codehaus.groovy.ast.expr.ConstantExpression;
import
org.codehaus.groovy.control.SourceUnit
;
import
org.codehaus.groovy.control.SourceUnit
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver
;
import
org.springframework.boot.cli.compiler.dependencies.ArtifactCoordinatesResolver
;
import
org.springframework.boot.cli.compiler.grape.DependencyResolutionContext
;
import
org.springframework.boot.cli.compiler.grape.DependencyResolutionContext
;
...
@@ -41,6 +42,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -41,6 +42,7 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
DependencyCustomizerTests
{
class
DependencyCustomizerTests
{
private
final
ModuleNode
moduleNode
=
new
ModuleNode
((
SourceUnit
)
null
);
private
final
ModuleNode
moduleNode
=
new
ModuleNode
((
SourceUnit
)
null
);
...
@@ -54,10 +56,6 @@ class DependencyCustomizerTests {
...
@@ -54,10 +56,6 @@ class DependencyCustomizerTests {
@BeforeEach
@BeforeEach
void
setUp
()
{
void
setUp
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
resolver
.
getGroupId
(
"spring-boot-starter-logging"
)).
willReturn
(
"org.springframework.boot"
);
given
(
this
.
resolver
.
getArtifactId
(
"spring-boot-starter-logging"
)).
willReturn
(
"spring-boot-starter-logging"
);
given
(
this
.
resolver
.
getVersion
(
"spring-boot-starter-logging"
)).
willReturn
(
"1.2.3"
);
this
.
moduleNode
.
addClass
(
this
.
classNode
);
this
.
moduleNode
.
addClass
(
this
.
classNode
);
this
.
dependencyCustomizer
=
new
DependencyCustomizer
(
new
GroovyClassLoader
(
getClass
().
getClassLoader
()),
this
.
dependencyCustomizer
=
new
DependencyCustomizer
(
new
GroovyClassLoader
(
getClass
().
getClassLoader
()),
this
.
moduleNode
,
new
DependencyResolutionContext
()
{
this
.
moduleNode
,
new
DependencyResolutionContext
()
{
...
@@ -72,6 +70,9 @@ class DependencyCustomizerTests {
...
@@ -72,6 +70,9 @@ class DependencyCustomizerTests {
@Test
@Test
void
basicAdd
()
{
void
basicAdd
()
{
given
(
this
.
resolver
.
getGroupId
(
"spring-boot-starter-logging"
)).
willReturn
(
"org.springframework.boot"
);
given
(
this
.
resolver
.
getArtifactId
(
"spring-boot-starter-logging"
)).
willReturn
(
"spring-boot-starter-logging"
);
given
(
this
.
resolver
.
getVersion
(
"spring-boot-starter-logging"
)).
willReturn
(
"1.2.3"
);
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
);
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assertThat
(
grabAnnotations
).
hasSize
(
1
);
assertThat
(
grabAnnotations
).
hasSize
(
1
);
...
@@ -82,6 +83,9 @@ class DependencyCustomizerTests {
...
@@ -82,6 +83,9 @@ class DependencyCustomizerTests {
@Test
@Test
void
nonTransitiveAdd
()
{
void
nonTransitiveAdd
()
{
given
(
this
.
resolver
.
getGroupId
(
"spring-boot-starter-logging"
)).
willReturn
(
"org.springframework.boot"
);
given
(
this
.
resolver
.
getArtifactId
(
"spring-boot-starter-logging"
)).
willReturn
(
"spring-boot-starter-logging"
);
given
(
this
.
resolver
.
getVersion
(
"spring-boot-starter-logging"
)).
willReturn
(
"1.2.3"
);
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
false
);
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
false
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assertThat
(
grabAnnotations
).
hasSize
(
1
);
assertThat
(
grabAnnotations
).
hasSize
(
1
);
...
@@ -92,6 +96,9 @@ class DependencyCustomizerTests {
...
@@ -92,6 +96,9 @@ class DependencyCustomizerTests {
@Test
@Test
void
fullyCustomized
()
{
void
fullyCustomized
()
{
given
(
this
.
resolver
.
getGroupId
(
"spring-boot-starter-logging"
)).
willReturn
(
"org.springframework.boot"
);
given
(
this
.
resolver
.
getArtifactId
(
"spring-boot-starter-logging"
)).
willReturn
(
"spring-boot-starter-logging"
);
given
(
this
.
resolver
.
getVersion
(
"spring-boot-starter-logging"
)).
willReturn
(
"1.2.3"
);
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
"my-classifier"
,
"my-type"
,
false
);
this
.
dependencyCustomizer
.
add
(
"spring-boot-starter-logging"
,
"my-classifier"
,
"my-type"
,
false
);
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
List
<
AnnotationNode
>
grabAnnotations
=
this
.
classNode
.
getAnnotations
(
new
ClassNode
(
Grab
.
class
));
assertThat
(
grabAnnotations
).
hasSize
(
1
);
assertThat
(
grabAnnotations
).
hasSize
(
1
);
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/dependencies/CompositeDependencyManagementTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -18,10 +18,10 @@ package org.springframework.boot.cli.compiler.dependencies;
...
@@ -18,10 +18,10 @@ package org.springframework.boot.cli.compiler.dependencies;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
...
@@ -31,6 +31,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -31,6 +31,7 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
CompositeDependencyManagementTests
{
class
CompositeDependencyManagementTests
{
@Mock
@Mock
...
@@ -39,11 +40,6 @@ class CompositeDependencyManagementTests {
...
@@ -39,11 +40,6 @@ class CompositeDependencyManagementTests {
@Mock
@Mock
private
DependencyManagement
dependencyManagement2
;
private
DependencyManagement
dependencyManagement2
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
unknownSpringBootVersion
()
{
void
unknownSpringBootVersion
()
{
given
(
this
.
dependencyManagement1
.
getSpringBootVersion
()).
willReturn
(
null
);
given
(
this
.
dependencyManagement1
.
getSpringBootVersion
()).
willReturn
(
null
);
...
@@ -55,7 +51,6 @@ class CompositeDependencyManagementTests {
...
@@ -55,7 +51,6 @@ class CompositeDependencyManagementTests {
@Test
@Test
void
knownSpringBootVersion
()
{
void
knownSpringBootVersion
()
{
given
(
this
.
dependencyManagement1
.
getSpringBootVersion
()).
willReturn
(
"1.2.3"
);
given
(
this
.
dependencyManagement1
.
getSpringBootVersion
()).
willReturn
(
"1.2.3"
);
given
(
this
.
dependencyManagement2
.
getSpringBootVersion
()).
willReturn
(
"1.2.4"
);
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
)
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
)
.
getSpringBootVersion
()).
isEqualTo
(
"1.2.3"
);
.
getSpringBootVersion
()).
isEqualTo
(
"1.2.3"
);
}
}
...
@@ -71,7 +66,6 @@ class CompositeDependencyManagementTests {
...
@@ -71,7 +66,6 @@ class CompositeDependencyManagementTests {
@Test
@Test
void
knownDependency
()
{
void
knownDependency
()
{
given
(
this
.
dependencyManagement1
.
find
(
"artifact"
)).
willReturn
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
));
given
(
this
.
dependencyManagement1
.
find
(
"artifact"
)).
willReturn
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
));
given
(
this
.
dependencyManagement2
.
find
(
"artifact"
)).
willReturn
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.4"
));
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
)
assertThat
(
new
CompositeDependencyManagement
(
this
.
dependencyManagement1
,
this
.
dependencyManagement2
)
.
find
(
"artifact"
)).
isEqualTo
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
));
.
find
(
"artifact"
)).
isEqualTo
(
new
Dependency
(
"test"
,
"artifact"
,
"1.2.3"
));
}
}
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/GrapeRootRepositorySystemSessionAutoConfigurationTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -24,11 +24,11 @@ import org.eclipse.aether.RepositorySystem;
...
@@ -24,11 +24,11 @@ import org.eclipse.aether.RepositorySystem;
import
org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory
;
import
org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory
;
import
org.eclipse.aether.repository.LocalRepository
;
import
org.eclipse.aether.repository.LocalRepository
;
import
org.eclipse.aether.repository.LocalRepositoryManager
;
import
org.eclipse.aether.repository.LocalRepositoryManager
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.mockito.stubbing.Answer
;
import
org.mockito.stubbing.Answer
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.verify;
...
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
GrapeRootRepositorySystemSessionAutoConfigurationTests
{
class
GrapeRootRepositorySystemSessionAutoConfigurationTests
{
private
DefaultRepositorySystemSession
session
=
MavenRepositorySystemUtils
.
newSession
();
private
DefaultRepositorySystemSession
session
=
MavenRepositorySystemUtils
.
newSession
();
...
@@ -51,19 +52,8 @@ class GrapeRootRepositorySystemSessionAutoConfigurationTests {
...
@@ -51,19 +52,8 @@ class GrapeRootRepositorySystemSessionAutoConfigurationTests {
@Mock
@Mock
private
RepositorySystem
repositorySystem
;
private
RepositorySystem
repositorySystem
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
noLocalRepositoryWhenNoGrapeRoot
()
{
void
noLocalRepositoryWhenNoGrapeRoot
()
{
given
(
this
.
repositorySystem
.
newLocalRepositoryManager
(
eq
(
this
.
session
),
any
(
LocalRepository
.
class
)))
.
willAnswer
((
invocation
)
->
{
LocalRepository
localRepository
=
invocation
.
getArgument
(
1
);
return
new
SimpleLocalRepositoryManagerFactory
().
newInstance
(
GrapeRootRepositorySystemSessionAutoConfigurationTests
.
this
.
session
,
localRepository
);
});
new
GrapeRootRepositorySystemSessionAutoConfiguration
().
apply
(
this
.
session
,
this
.
repositorySystem
);
new
GrapeRootRepositorySystemSessionAutoConfiguration
().
apply
(
this
.
session
,
this
.
repositorySystem
);
verify
(
this
.
repositorySystem
,
never
()).
newLocalRepositoryManager
(
eq
(
this
.
session
),
any
(
LocalRepository
.
class
));
verify
(
this
.
repositorySystem
,
never
()).
newLocalRepositoryManager
(
eq
(
this
.
session
),
any
(
LocalRepository
.
class
));
assertThat
(
this
.
session
.
getLocalRepository
()).
isNull
();
assertThat
(
this
.
session
.
getLocalRepository
()).
isNull
();
...
...
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -27,10 +27,10 @@ import org.eclipse.aether.repository.AuthenticationContext;
...
@@ -27,10 +27,10 @@ import org.eclipse.aether.repository.AuthenticationContext;
import
org.eclipse.aether.repository.LocalRepository
;
import
org.eclipse.aether.repository.LocalRepository
;
import
org.eclipse.aether.repository.Proxy
;
import
org.eclipse.aether.repository.Proxy
;
import
org.eclipse.aether.repository.RemoteRepository
;
import
org.eclipse.aether.repository.RemoteRepository
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.test.util.TestPropertyValues
;
...
@@ -44,16 +44,12 @@ import static org.mockito.BDDMockito.given;
...
@@ -44,16 +44,12 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
SettingsXmlRepositorySystemSessionAutoConfigurationTests
{
class
SettingsXmlRepositorySystemSessionAutoConfigurationTests
{
@Mock
@Mock
private
RepositorySystem
repositorySystem
;
private
RepositorySystem
repositorySystem
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
basicSessionCustomization
()
{
void
basicSessionCustomization
()
{
assertSessionCustomization
(
"src/test/resources/maven-settings/basic"
);
assertSessionCustomization
(
"src/test/resources/maven-settings/basic"
);
...
...
spring-boot-project/spring-boot-dependencies/build.gradle
View file @
969dd35e
...
@@ -1127,7 +1127,7 @@ bom {
...
@@ -1127,7 +1127,7 @@ bom {
]
]
}
}
}
}
library
(
"Mockito"
,
"3.
3.3
"
)
{
library
(
"Mockito"
,
"3.
4.6
"
)
{
group
(
"org.mockito"
)
{
group
(
"org.mockito"
)
{
modules
=
[
modules
=
[
"mockito-core"
,
"mockito-core"
,
...
...
spring-boot-project/spring-boot-devtools/build.gradle
View file @
969dd35e
...
@@ -59,6 +59,7 @@ dependencies {
...
@@ -59,6 +59,7 @@ dependencies {
testImplementation
(
"org.hsqldb:hsqldb"
)
testImplementation
(
"org.hsqldb:hsqldb"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.postgresql:postgresql"
)
testImplementation
(
"org.postgresql:postgresql"
)
testImplementation
(
"org.springframework:spring-test"
)
testImplementation
(
"org.springframework:spring-test"
)
testImplementation
(
"org.springframework:spring-webmvc"
)
testImplementation
(
"org.springframework:spring-webmvc"
)
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileChangeListenerTests.java
View file @
969dd35e
...
@@ -21,12 +21,12 @@ import java.util.Collections;
...
@@ -21,12 +21,12 @@ import java.util.Collections;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.Set
;
import
java.util.Set
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.devtools.filewatch.ChangedFile
;
import
org.springframework.boot.devtools.filewatch.ChangedFile
;
import
org.springframework.boot.devtools.filewatch.ChangedFiles
;
import
org.springframework.boot.devtools.filewatch.ChangedFiles
;
...
@@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify;
...
@@ -45,6 +45,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ClassPathFileChangeListenerTests
{
class
ClassPathFileChangeListenerTests
{
@Mock
@Mock
...
@@ -59,11 +60,6 @@ class ClassPathFileChangeListenerTests {
...
@@ -59,11 +60,6 @@ class ClassPathFileChangeListenerTests {
@Captor
@Captor
private
ArgumentCaptor
<
ApplicationEvent
>
eventCaptor
;
private
ArgumentCaptor
<
ApplicationEvent
>
eventCaptor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
eventPublisherMustNotBeNull
()
{
void
eventPublisherMustNotBeNull
()
{
assertThatIllegalArgumentException
()
assertThatIllegalArgumentException
()
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/DelayedLiveReloadTriggerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -21,8 +21,9 @@ import java.net.URI;
...
@@ -21,8 +21,9 @@ import java.net.URI;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.devtools.autoconfigure.OptionalLiveReloadServer
;
import
org.springframework.boot.devtools.autoconfigure.OptionalLiveReloadServer
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpMethod
;
...
@@ -42,6 +43,7 @@ import static org.mockito.Mockito.verify;
...
@@ -42,6 +43,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
DelayedLiveReloadTriggerTests
{
class
DelayedLiveReloadTriggerTests
{
private
static
final
String
URL
=
"http://localhost:8080"
;
private
static
final
String
URL
=
"http://localhost:8080"
;
...
@@ -68,11 +70,6 @@ class DelayedLiveReloadTriggerTests {
...
@@ -68,11 +70,6 @@ class DelayedLiveReloadTriggerTests {
@BeforeEach
@BeforeEach
void
setup
()
throws
IOException
{
void
setup
()
throws
IOException
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
errorRequest
.
execute
()).
willReturn
(
this
.
errorResponse
);
given
(
this
.
okRequest
.
execute
()).
willReturn
(
this
.
okResponse
);
given
(
this
.
errorResponse
.
getStatusCode
()).
willReturn
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
given
(
this
.
okResponse
.
getStatusCode
()).
willReturn
(
HttpStatus
.
OK
);
this
.
trigger
=
new
DelayedLiveReloadTrigger
(
this
.
liveReloadServer
,
this
.
requestFactory
,
URL
);
this
.
trigger
=
new
DelayedLiveReloadTrigger
(
this
.
liveReloadServer
,
this
.
requestFactory
,
URL
);
}
}
...
@@ -106,6 +103,10 @@ class DelayedLiveReloadTriggerTests {
...
@@ -106,6 +103,10 @@ class DelayedLiveReloadTriggerTests {
@Test
@Test
void
triggerReloadOnStatus
()
throws
Exception
{
void
triggerReloadOnStatus
()
throws
Exception
{
given
(
this
.
errorRequest
.
execute
()).
willReturn
(
this
.
errorResponse
);
given
(
this
.
okRequest
.
execute
()).
willReturn
(
this
.
okResponse
);
given
(
this
.
errorResponse
.
getStatusCode
()).
willReturn
(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
given
(
this
.
okResponse
.
getStatusCode
()).
willReturn
(
HttpStatus
.
OK
);
given
(
this
.
requestFactory
.
createRequest
(
new
URI
(
URL
),
HttpMethod
.
GET
)).
willThrow
(
new
IOException
())
given
(
this
.
requestFactory
.
createRequest
(
new
URI
(
URL
),
HttpMethod
.
GET
)).
willThrow
(
new
IOException
())
.
willReturn
(
this
.
errorRequest
,
this
.
okRequest
);
.
willReturn
(
this
.
errorRequest
,
this
.
okRequest
);
long
startTime
=
System
.
currentTimeMillis
();
long
startTime
=
System
.
currentTimeMillis
();
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/HttpHeaderInterceptorTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -20,8 +20,9 @@ import java.io.IOException;
...
@@ -20,8 +20,9 @@ import java.io.IOException;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.http.HttpRequest
;
import
org.springframework.http.client.ClientHttpRequestExecution
;
import
org.springframework.http.client.ClientHttpRequestExecution
;
...
@@ -39,6 +40,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -39,6 +40,7 @@ import static org.mockito.BDDMockito.given;
* @author Rob Winch
* @author Rob Winch
* @since 1.3.0
* @since 1.3.0
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
HttpHeaderInterceptorTests
{
class
HttpHeaderInterceptorTests
{
private
String
name
;
private
String
name
;
...
@@ -61,13 +63,11 @@ class HttpHeaderInterceptorTests {
...
@@ -61,13 +63,11 @@ class HttpHeaderInterceptorTests {
@BeforeEach
@BeforeEach
void
setup
()
throws
Exception
{
void
setup
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
body
=
new
byte
[]
{};
this
.
body
=
new
byte
[]
{};
this
.
httpRequest
=
new
MockHttpServletRequest
();
this
.
httpRequest
=
new
MockHttpServletRequest
();
this
.
request
=
new
ServletServerHttpRequest
(
this
.
httpRequest
);
this
.
request
=
new
ServletServerHttpRequest
(
this
.
httpRequest
);
this
.
name
=
"X-AUTH-TOKEN"
;
this
.
name
=
"X-AUTH-TOKEN"
;
this
.
value
=
"secret"
;
this
.
value
=
"secret"
;
given
(
this
.
execution
.
execute
(
this
.
request
,
this
.
body
)).
willReturn
(
this
.
response
);
this
.
interceptor
=
new
HttpHeaderInterceptor
(
this
.
name
,
this
.
value
);
this
.
interceptor
=
new
HttpHeaderInterceptor
(
this
.
name
,
this
.
value
);
}
}
...
@@ -97,6 +97,7 @@ class HttpHeaderInterceptorTests {
...
@@ -97,6 +97,7 @@ class HttpHeaderInterceptorTests {
@Test
@Test
void
intercept
()
throws
IOException
{
void
intercept
()
throws
IOException
{
given
(
this
.
execution
.
execute
(
this
.
request
,
this
.
body
)).
willReturn
(
this
.
response
);
ClientHttpResponse
result
=
this
.
interceptor
.
intercept
(
this
.
request
,
this
.
body
,
this
.
execution
);
ClientHttpResponse
result
=
this
.
interceptor
.
intercept
(
this
.
request
,
this
.
body
,
this
.
execution
);
assertThat
(
this
.
request
.
getHeaders
().
getFirst
(
this
.
name
)).
isEqualTo
(
this
.
value
);
assertThat
(
this
.
request
.
getHeaders
().
getFirst
(
this
.
name
)).
isEqualTo
(
this
.
value
);
assertThat
(
result
).
isEqualTo
(
this
.
response
);
assertThat
(
result
).
isEqualTo
(
this
.
response
);
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherFilterTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -24,10 +24,11 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -24,10 +24,11 @@ import javax.servlet.http.HttpServletResponse;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.http.server.ServerHttpRequest
;
import
org.springframework.http.server.ServerHttpRequest
;
import
org.springframework.http.server.ServerHttpResponse
;
import
org.springframework.http.server.ServerHttpResponse
;
...
@@ -49,6 +50,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
...
@@ -49,6 +50,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
DispatcherFilterTests
{
class
DispatcherFilterTests
{
@Mock
@Mock
...
@@ -67,7 +69,6 @@ class DispatcherFilterTests {
...
@@ -67,7 +69,6 @@ class DispatcherFilterTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
filter
=
new
DispatcherFilter
(
this
.
dispatcher
);
this
.
filter
=
new
DispatcherFilter
(
this
.
dispatcher
);
}
}
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/server/DispatcherTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -20,11 +20,11 @@ import java.util.Arrays;
...
@@ -20,11 +20,11 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.InOrder
;
import
org.mockito.InOrder
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.Ordered
;
import
org.springframework.http.server.ServerHttpRequest
;
import
org.springframework.http.server.ServerHttpRequest
;
...
@@ -49,27 +49,17 @@ import static org.mockito.Mockito.withSettings;
...
@@ -49,27 +49,17 @@ import static org.mockito.Mockito.withSettings;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
DispatcherTests
{
class
DispatcherTests
{
@Mock
@Mock
private
AccessManager
accessManager
;
private
AccessManager
accessManager
;
private
MockHttpServletRe
quest
request
;
private
MockHttpServletRe
sponse
response
=
new
MockHttpServletResponse
()
;
private
MockHttpServletResponse
response
;
private
ServerHttpRequest
serverRequest
=
new
ServletServerHttpRequest
(
new
MockHttpServletRequest
())
;
private
ServerHttpRequest
serverRequest
;
private
ServerHttpResponse
serverResponse
=
new
ServletServerHttpResponse
(
this
.
response
);
private
ServerHttpResponse
serverResponse
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
request
=
new
MockHttpServletRequest
();
this
.
response
=
new
MockHttpServletResponse
();
this
.
serverRequest
=
new
ServletServerHttpRequest
(
this
.
request
);
this
.
serverResponse
=
new
ServletServerHttpResponse
(
this
.
response
);
}
@Test
@Test
void
accessManagerMustNotBeNull
()
{
void
accessManagerMustNotBeNull
()
{
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/server/HttpRestartServerTests.java
View file @
969dd35e
...
@@ -22,10 +22,11 @@ import java.io.ObjectOutputStream;
...
@@ -22,10 +22,11 @@ import java.io.ObjectOutputStream;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.devtools.restart.classloader.ClassLoaderFile
;
import
org.springframework.boot.devtools.restart.classloader.ClassLoaderFile
;
import
org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind
;
import
org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind
;
...
@@ -45,6 +46,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
...
@@ -45,6 +46,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
HttpRestartServerTests
{
class
HttpRestartServerTests
{
@Mock
@Mock
...
@@ -57,7 +59,6 @@ class HttpRestartServerTests {
...
@@ -57,7 +59,6 @@ class HttpRestartServerTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
server
=
new
HttpRestartServer
(
this
.
delegate
);
this
.
server
=
new
HttpRestartServer
(
this
.
delegate
);
}
}
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/client/HttpTunnelConnectionTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -29,7 +29,7 @@ import org.junit.jupiter.api.BeforeEach;
...
@@ -29,7 +29,7 @@ import org.junit.jupiter.api.BeforeEach;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.devtools.test.MockClientHttpRequestFactory
;
import
org.springframework.boot.devtools.test.MockClientHttpRequestFactory
;
import
org.springframework.boot.devtools.tunnel.client.HttpTunnelConnection.TunnelChannel
;
import
org.springframework.boot.devtools.tunnel.client.HttpTunnelConnection.TunnelChannel
;
...
@@ -50,7 +50,7 @@ import static org.mockito.Mockito.verify;
...
@@ -50,7 +50,7 @@ import static org.mockito.Mockito.verify;
* @author Rob Winch
* @author Rob Winch
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
@ExtendWith
(
OutputCaptureExtension
.
class
)
@ExtendWith
(
{
OutputCaptureExtension
.
class
,
MockitoExtension
.
class
}
)
class
HttpTunnelConnectionTests
{
class
HttpTunnelConnectionTests
{
private
String
url
;
private
String
url
;
...
@@ -66,7 +66,6 @@ class HttpTunnelConnectionTests {
...
@@ -66,7 +66,6 @@ class HttpTunnelConnectionTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
url
=
"http://localhost:12345"
;
this
.
url
=
"http://localhost:12345"
;
this
.
incomingData
=
new
ByteArrayOutputStream
();
this
.
incomingData
=
new
ByteArrayOutputStream
();
this
.
incomingChannel
=
Channels
.
newChannel
(
this
.
incomingData
);
this
.
incomingChannel
=
Channels
.
newChannel
(
this
.
incomingData
);
...
...
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -29,8 +29,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
...
@@ -29,8 +29,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.devtools.tunnel.payload.HttpTunnelPayload
;
import
org.springframework.boot.devtools.tunnel.payload.HttpTunnelPayload
;
import
org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection
;
import
org.springframework.boot.devtools.tunnel.server.HttpTunnelServer.HttpConnection
;
...
@@ -57,6 +58,7 @@ import static org.mockito.Mockito.verify;
...
@@ -57,6 +58,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
HttpTunnelServerTests
{
class
HttpTunnelServerTests
{
private
static
final
int
DEFAULT_LONG_POLL_TIMEOUT
=
10000
;
private
static
final
int
DEFAULT_LONG_POLL_TIMEOUT
=
10000
;
...
@@ -82,13 +84,7 @@ class HttpTunnelServerTests {
...
@@ -82,13 +84,7 @@ class HttpTunnelServerTests {
@BeforeEach
@BeforeEach
void
setup
()
throws
Exception
{
void
setup
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
server
=
new
HttpTunnelServer
(
this
.
serverConnection
);
this
.
server
=
new
HttpTunnelServer
(
this
.
serverConnection
);
given
(
this
.
serverConnection
.
open
(
anyInt
())).
willAnswer
((
invocation
)
->
{
MockServerChannel
channel
=
HttpTunnelServerTests
.
this
.
serverChannel
;
channel
.
setTimeout
(
invocation
.
getArgument
(
0
));
return
channel
;
});
this
.
servletRequest
=
new
MockHttpServletRequest
();
this
.
servletRequest
=
new
MockHttpServletRequest
();
this
.
servletRequest
.
setAsyncSupported
(
true
);
this
.
servletRequest
.
setAsyncSupported
(
true
);
this
.
servletResponse
=
new
MockHttpServletResponse
();
this
.
servletResponse
=
new
MockHttpServletResponse
();
...
@@ -106,12 +102,14 @@ class HttpTunnelServerTests {
...
@@ -106,12 +102,14 @@ class HttpTunnelServerTests {
@Test
@Test
void
serverConnectedOnFirstRequest
()
throws
Exception
{
void
serverConnectedOnFirstRequest
()
throws
Exception
{
verify
(
this
.
serverConnection
,
never
()).
open
(
anyInt
());
verify
(
this
.
serverConnection
,
never
()).
open
(
anyInt
());
givenServerConnectionOpenWillAnswerWithServerChannel
();
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
verify
(
this
.
serverConnection
,
times
(
1
)).
open
(
DEFAULT_LONG_POLL_TIMEOUT
);
verify
(
this
.
serverConnection
,
times
(
1
)).
open
(
DEFAULT_LONG_POLL_TIMEOUT
);
}
}
@Test
@Test
void
longPollTimeout
()
throws
Exception
{
void
longPollTimeout
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
this
.
server
.
setLongPollTimeout
(
800
);
this
.
server
.
setLongPollTimeout
(
800
);
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
verify
(
this
.
serverConnection
,
times
(
1
)).
open
(
800
);
verify
(
this
.
serverConnection
,
times
(
1
)).
open
(
800
);
...
@@ -125,6 +123,7 @@ class HttpTunnelServerTests {
...
@@ -125,6 +123,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
initialRequestIsSentToServer
()
throws
Exception
{
void
initialRequestIsSentToServer
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
this
.
servletRequest
.
addHeader
(
SEQ_HEADER
,
"1"
);
this
.
servletRequest
.
addHeader
(
SEQ_HEADER
,
"1"
);
this
.
servletRequest
.
setContent
(
"hello"
.
getBytes
());
this
.
servletRequest
.
setContent
(
"hello"
.
getBytes
());
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
...
@@ -135,6 +134,7 @@ class HttpTunnelServerTests {
...
@@ -135,6 +134,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
initialRequestIsUsedForFirstServerResponse
()
throws
Exception
{
void
initialRequestIsUsedForFirstServerResponse
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
this
.
servletRequest
.
addHeader
(
SEQ_HEADER
,
"1"
);
this
.
servletRequest
.
addHeader
(
SEQ_HEADER
,
"1"
);
this
.
servletRequest
.
setContent
(
"hello"
.
getBytes
());
this
.
servletRequest
.
setContent
(
"hello"
.
getBytes
());
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
...
@@ -148,6 +148,7 @@ class HttpTunnelServerTests {
...
@@ -148,6 +148,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
initialRequestHasNoPayload
()
throws
Exception
{
void
initialRequestHasNoPayload
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
this
.
server
.
handle
(
this
.
request
,
this
.
response
);
this
.
serverChannel
.
disconnect
();
this
.
serverChannel
.
disconnect
();
this
.
server
.
getServerThread
().
join
();
this
.
server
.
getServerThread
().
join
();
...
@@ -156,6 +157,7 @@ class HttpTunnelServerTests {
...
@@ -156,6 +157,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
typicalRequestResponseTraffic
()
throws
Exception
{
void
typicalRequestResponseTraffic
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
this
.
server
.
handle
(
h1
);
this
.
server
.
handle
(
h1
);
MockHttpConnection
h2
=
new
MockHttpConnection
(
"hello server"
,
1
);
MockHttpConnection
h2
=
new
MockHttpConnection
(
"hello server"
,
1
);
...
@@ -177,6 +179,7 @@ class HttpTunnelServerTests {
...
@@ -177,6 +179,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
clientIsAwareOfServerClose
()
throws
Exception
{
void
clientIsAwareOfServerClose
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
MockHttpConnection
h1
=
new
MockHttpConnection
(
"1"
,
1
);
MockHttpConnection
h1
=
new
MockHttpConnection
(
"1"
,
1
);
this
.
server
.
handle
(
h1
);
this
.
server
.
handle
(
h1
);
this
.
serverChannel
.
disconnect
();
this
.
serverChannel
.
disconnect
();
...
@@ -186,6 +189,7 @@ class HttpTunnelServerTests {
...
@@ -186,6 +189,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
clientCanCloseServer
()
throws
Exception
{
void
clientCanCloseServer
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
this
.
server
.
handle
(
h1
);
this
.
server
.
handle
(
h1
);
MockHttpConnection
h2
=
new
MockHttpConnection
(
"DISCONNECT"
,
1
);
MockHttpConnection
h2
=
new
MockHttpConnection
(
"DISCONNECT"
,
1
);
...
@@ -198,6 +202,7 @@ class HttpTunnelServerTests {
...
@@ -198,6 +202,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
neverMoreThanTwoHttpConnections
()
throws
Exception
{
void
neverMoreThanTwoHttpConnections
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
this
.
server
.
handle
(
h1
);
this
.
server
.
handle
(
h1
);
MockHttpConnection
h2
=
new
MockHttpConnection
(
"1"
,
2
);
MockHttpConnection
h2
=
new
MockHttpConnection
(
"1"
,
2
);
...
@@ -212,6 +217,7 @@ class HttpTunnelServerTests {
...
@@ -212,6 +217,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
requestReceivedOutOfOrder
()
throws
Exception
{
void
requestReceivedOutOfOrder
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
MockHttpConnection
h2
=
new
MockHttpConnection
(
"1+2"
,
1
);
MockHttpConnection
h2
=
new
MockHttpConnection
(
"1+2"
,
1
);
MockHttpConnection
h3
=
new
MockHttpConnection
(
"+3"
,
2
);
MockHttpConnection
h3
=
new
MockHttpConnection
(
"+3"
,
2
);
...
@@ -225,6 +231,7 @@ class HttpTunnelServerTests {
...
@@ -225,6 +231,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
httpConnectionsAreClosedAfterLongPollTimeout
()
throws
Exception
{
void
httpConnectionsAreClosedAfterLongPollTimeout
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
this
.
server
.
setDisconnectTimeout
(
1000
);
this
.
server
.
setDisconnectTimeout
(
1000
);
this
.
server
.
setLongPollTimeout
(
100
);
this
.
server
.
setLongPollTimeout
(
100
);
MockHttpConnection
h1
=
new
MockHttpConnection
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
...
@@ -240,6 +247,7 @@ class HttpTunnelServerTests {
...
@@ -240,6 +247,7 @@ class HttpTunnelServerTests {
@Test
@Test
void
disconnectTimeout
()
throws
Exception
{
void
disconnectTimeout
()
throws
Exception
{
givenServerConnectionOpenWillAnswerWithServerChannel
();
this
.
server
.
setDisconnectTimeout
(
100
);
this
.
server
.
setDisconnectTimeout
(
100
);
this
.
server
.
setLongPollTimeout
(
100
);
this
.
server
.
setLongPollTimeout
(
100
);
MockHttpConnection
h1
=
new
MockHttpConnection
();
MockHttpConnection
h1
=
new
MockHttpConnection
();
...
@@ -317,6 +325,14 @@ class HttpTunnelServerTests {
...
@@ -317,6 +325,14 @@ class HttpTunnelServerTests {
assertThat
(
connection
.
isOlderThan
(
100
)).
isTrue
();
assertThat
(
connection
.
isOlderThan
(
100
)).
isTrue
();
}
}
private
void
givenServerConnectionOpenWillAnswerWithServerChannel
()
throws
IOException
{
given
(
this
.
serverConnection
.
open
(
anyInt
())).
willAnswer
((
invocation
)
->
{
MockServerChannel
channel
=
HttpTunnelServerTests
.
this
.
serverChannel
;
channel
.
setTimeout
(
invocation
.
getArgument
(
0
));
return
channel
;
});
}
/**
/**
* Mock {@link ByteChannel} used to simulate the server connection.
* Mock {@link ByteChannel} used to simulate the server connection.
*/
*/
...
...
spring-boot-project/spring-boot-test-autoconfigure/build.gradle
View file @
969dd35e
...
@@ -76,6 +76,7 @@ dependencies {
...
@@ -76,6 +76,7 @@ dependencies {
testImplementation
(
"org.junit.platform:junit-platform-engine"
)
testImplementation
(
"org.junit.platform:junit-platform-engine"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.skyscreamer:jsonassert"
)
testImplementation
(
"org.skyscreamer:jsonassert"
)
testImplementation
(
"org.springframework.hateoas:spring-hateoas"
)
testImplementation
(
"org.springframework.hateoas:spring-hateoas"
)
testImplementation
(
"org.springframework.plugin:spring-plugin-core"
)
testImplementation
(
"org.springframework.plugin:spring-plugin-core"
)
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManagerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -22,8 +22,9 @@ import javax.persistence.PersistenceUnitUtil;
...
@@ -22,8 +22,9 @@ import javax.persistence.PersistenceUnitUtil;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.orm.jpa.EntityManagerHolder
;
import
org.springframework.orm.jpa.EntityManagerHolder
;
import
org.springframework.transaction.support.TransactionSynchronizationManager
;
import
org.springframework.transaction.support.TransactionSynchronizationManager
;
...
@@ -39,6 +40,7 @@ import static org.mockito.Mockito.verify;
...
@@ -39,6 +40,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
TestEntityManagerTests
{
class
TestEntityManagerTests
{
@Mock
@Mock
...
@@ -54,9 +56,7 @@ class TestEntityManagerTests {
...
@@ -54,9 +56,7 @@ class TestEntityManagerTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
testEntityManager
=
new
TestEntityManager
(
this
.
entityManagerFactory
);
this
.
testEntityManager
=
new
TestEntityManager
(
this
.
entityManagerFactory
);
given
(
this
.
entityManagerFactory
.
getPersistenceUnitUtil
()).
willReturn
(
this
.
persistenceUnitUtil
);
}
}
@Test
@Test
...
@@ -69,6 +69,7 @@ class TestEntityManagerTests {
...
@@ -69,6 +69,7 @@ class TestEntityManagerTests {
void
persistAndGetIdShouldPersistAndGetId
()
{
void
persistAndGetIdShouldPersistAndGetId
()
{
bindEntityManager
();
bindEntityManager
();
TestEntity
entity
=
new
TestEntity
();
TestEntity
entity
=
new
TestEntity
();
given
(
this
.
entityManagerFactory
.
getPersistenceUnitUtil
()).
willReturn
(
this
.
persistenceUnitUtil
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
Object
result
=
this
.
testEntityManager
.
persistAndGetId
(
entity
);
Object
result
=
this
.
testEntityManager
.
persistAndGetId
(
entity
);
verify
(
this
.
entityManager
).
persist
(
entity
);
verify
(
this
.
entityManager
).
persist
(
entity
);
...
@@ -79,6 +80,7 @@ class TestEntityManagerTests {
...
@@ -79,6 +80,7 @@ class TestEntityManagerTests {
void
persistAndGetIdForTypeShouldPersistAndGetId
()
{
void
persistAndGetIdForTypeShouldPersistAndGetId
()
{
bindEntityManager
();
bindEntityManager
();
TestEntity
entity
=
new
TestEntity
();
TestEntity
entity
=
new
TestEntity
();
given
(
this
.
entityManagerFactory
.
getPersistenceUnitUtil
()).
willReturn
(
this
.
persistenceUnitUtil
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
Integer
result
=
this
.
testEntityManager
.
persistAndGetId
(
entity
,
Integer
.
class
);
Integer
result
=
this
.
testEntityManager
.
persistAndGetId
(
entity
,
Integer
.
class
);
verify
(
this
.
entityManager
).
persist
(
entity
);
verify
(
this
.
entityManager
).
persist
(
entity
);
...
@@ -109,6 +111,7 @@ class TestEntityManagerTests {
...
@@ -109,6 +111,7 @@ class TestEntityManagerTests {
bindEntityManager
();
bindEntityManager
();
TestEntity
entity
=
new
TestEntity
();
TestEntity
entity
=
new
TestEntity
();
TestEntity
found
=
new
TestEntity
();
TestEntity
found
=
new
TestEntity
();
given
(
this
.
entityManagerFactory
.
getPersistenceUnitUtil
()).
willReturn
(
this
.
persistenceUnitUtil
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
given
(
this
.
entityManager
.
find
(
TestEntity
.
class
,
123
)).
willReturn
(
found
);
given
(
this
.
entityManager
.
find
(
TestEntity
.
class
,
123
)).
willReturn
(
found
);
TestEntity
result
=
this
.
testEntityManager
.
persistFlushFind
(
entity
);
TestEntity
result
=
this
.
testEntityManager
.
persistFlushFind
(
entity
);
...
@@ -177,6 +180,7 @@ class TestEntityManagerTests {
...
@@ -177,6 +180,7 @@ class TestEntityManagerTests {
@Test
@Test
void
getIdForTypeShouldGetId
()
{
void
getIdForTypeShouldGetId
()
{
TestEntity
entity
=
new
TestEntity
();
TestEntity
entity
=
new
TestEntity
();
given
(
this
.
entityManagerFactory
.
getPersistenceUnitUtil
()).
willReturn
(
this
.
persistenceUnitUtil
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
Integer
result
=
this
.
testEntityManager
.
getId
(
entity
,
Integer
.
class
);
Integer
result
=
this
.
testEntityManager
.
getId
(
entity
,
Integer
.
class
);
assertThat
(
result
).
isEqualTo
(
123
);
assertThat
(
result
).
isEqualTo
(
123
);
...
@@ -185,6 +189,7 @@ class TestEntityManagerTests {
...
@@ -185,6 +189,7 @@ class TestEntityManagerTests {
@Test
@Test
void
getIdForTypeWhenTypeIsWrongShouldThrowException
()
{
void
getIdForTypeWhenTypeIsWrongShouldThrowException
()
{
TestEntity
entity
=
new
TestEntity
();
TestEntity
entity
=
new
TestEntity
();
given
(
this
.
entityManagerFactory
.
getPersistenceUnitUtil
()).
willReturn
(
this
.
persistenceUnitUtil
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
assertThatIllegalArgumentException
().
isThrownBy
(()
->
this
.
testEntityManager
.
getId
(
entity
,
Long
.
class
))
assertThatIllegalArgumentException
().
isThrownBy
(()
->
this
.
testEntityManager
.
getId
(
entity
,
Long
.
class
))
.
withMessageContaining
(
"ID mismatch: Object of class [java.lang.Integer] "
.
withMessageContaining
(
"ID mismatch: Object of class [java.lang.Integer] "
...
@@ -194,6 +199,7 @@ class TestEntityManagerTests {
...
@@ -194,6 +199,7 @@ class TestEntityManagerTests {
@Test
@Test
void
getIdShouldGetId
()
{
void
getIdShouldGetId
()
{
TestEntity
entity
=
new
TestEntity
();
TestEntity
entity
=
new
TestEntity
();
given
(
this
.
entityManagerFactory
.
getPersistenceUnitUtil
()).
willReturn
(
this
.
persistenceUnitUtil
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
given
(
this
.
persistenceUnitUtil
.
getIdentifier
(
entity
)).
willReturn
(
123
);
Object
result
=
this
.
testEntityManager
.
getId
(
entity
);
Object
result
=
this
.
testEntityManager
.
getId
(
entity
);
assertThat
(
result
).
isEqualTo
(
123
);
assertThat
(
result
).
isEqualTo
(
123
);
...
...
spring-boot-project/spring-boot-test/build.gradle
View file @
969dd35e
...
@@ -43,6 +43,7 @@ dependencies {
...
@@ -43,6 +43,7 @@ dependencies {
testImplementation
(
"org.codehaus.groovy:groovy-xml"
)
testImplementation
(
"org.codehaus.groovy:groovy-xml"
)
testImplementation
(
"org.apache.johnzon:johnzon-jsonb"
)
testImplementation
(
"org.apache.johnzon:johnzon-jsonb"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.slf4j:slf4j-api"
)
testImplementation
(
"org.slf4j:slf4j-api"
)
testImplementation
(
"org.spockframework:spock-core"
)
testImplementation
(
"org.spockframework:spock-core"
)
testImplementation
(
"org.springframework:spring-webmvc"
)
testImplementation
(
"org.springframework:spring-webmvc"
)
...
...
spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListener.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -33,7 +33,7 @@ import org.springframework.util.ReflectionUtils;
...
@@ -33,7 +33,7 @@ import org.springframework.util.ReflectionUtils;
import
org.springframework.util.ReflectionUtils.FieldCallback
;
import
org.springframework.util.ReflectionUtils.FieldCallback
;
/**
/**
* {@link TestExecutionListener} to trigger {@link MockitoAnnotations#
init
Mocks(Object)}
* {@link TestExecutionListener} to trigger {@link MockitoAnnotations#
open
Mocks(Object)}
* when {@link MockBean @MockBean} annotations are used. Primarily to allow
* when {@link MockBean @MockBean} annotations are used. Primarily to allow
* {@link Captor @Captor} annotations.
* {@link Captor @Captor} annotations.
*
*
...
@@ -43,6 +43,8 @@ import org.springframework.util.ReflectionUtils.FieldCallback;
...
@@ -43,6 +43,8 @@ import org.springframework.util.ReflectionUtils.FieldCallback;
*/
*/
public
class
MockitoTestExecutionListener
extends
AbstractTestExecutionListener
{
public
class
MockitoTestExecutionListener
extends
AbstractTestExecutionListener
{
private
static
final
String
MOCKS_ATTRIBUTE_NAME
=
MockitoTestExecutionListener
.
class
.
getName
()
+
".mocks"
;
@Override
@Override
public
final
int
getOrder
()
{
public
final
int
getOrder
()
{
return
1950
;
return
1950
;
...
@@ -63,9 +65,17 @@ public class MockitoTestExecutionListener extends AbstractTestExecutionListener
...
@@ -63,9 +65,17 @@ public class MockitoTestExecutionListener extends AbstractTestExecutionListener
}
}
}
}
@Override
public
void
afterTestMethod
(
TestContext
testContext
)
throws
Exception
{
Object
mocks
=
testContext
.
getAttribute
(
MOCKS_ATTRIBUTE_NAME
);
if
(
mocks
instanceof
AutoCloseable
)
{
((
AutoCloseable
)
mocks
).
close
();
}
}
private
void
initMocks
(
TestContext
testContext
)
{
private
void
initMocks
(
TestContext
testContext
)
{
if
(
hasMockitoAnnotations
(
testContext
))
{
if
(
hasMockitoAnnotations
(
testContext
))
{
MockitoAnnotations
.
initMocks
(
testContext
.
getTestInstance
(
));
testContext
.
setAttribute
(
MOCKS_ATTRIBUTE_NAME
,
MockitoAnnotations
.
openMocks
(
testContext
.
getTestInstance
()
));
}
}
}
}
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -20,8 +20,9 @@ import java.util.function.Supplier;
...
@@ -20,8 +20,9 @@ import java.util.function.Supplier;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
@@ -38,6 +39,7 @@ import static org.mockito.Mockito.verify;
...
@@ -38,6 +39,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ApplicationContextAssertProviderTests
{
class
ApplicationContextAssertProviderTests
{
@Mock
@Mock
...
@@ -51,7 +53,6 @@ class ApplicationContextAssertProviderTests {
...
@@ -51,7 +53,6 @@ class ApplicationContextAssertProviderTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
startupFailure
=
new
RuntimeException
();
this
.
startupFailure
=
new
RuntimeException
();
this
.
mockContextSupplier
=
()
->
this
.
mockContext
;
this
.
mockContextSupplier
=
()
->
this
.
mockContext
;
this
.
startupFailureSupplier
=
()
->
{
this
.
startupFailureSupplier
=
()
->
{
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/MockitoTestExecutionListenerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -19,12 +19,12 @@ package org.springframework.boot.test.mock.mockito;
...
@@ -19,12 +19,12 @@ package org.springframework.boot.test.mock.mockito;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.TestContext
;
import
org.springframework.test.context.TestContext
;
...
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
...
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
MockitoTestExecutionListenerTests
{
class
MockitoTestExecutionListenerTests
{
private
MockitoTestExecutionListener
listener
=
new
MockitoTestExecutionListener
();
private
MockitoTestExecutionListener
listener
=
new
MockitoTestExecutionListener
();
...
@@ -56,12 +57,6 @@ class MockitoTestExecutionListenerTests {
...
@@ -56,12 +57,6 @@ class MockitoTestExecutionListenerTests {
@Captor
@Captor
private
ArgumentCaptor
<
Field
>
fieldCaptor
;
private
ArgumentCaptor
<
Field
>
fieldCaptor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
applicationContext
.
getBean
(
MockitoPostProcessor
.
class
)).
willReturn
(
this
.
postProcessor
);
}
@Test
@Test
void
prepareTestInstanceShouldInitMockitoAnnotations
()
throws
Exception
{
void
prepareTestInstanceShouldInitMockitoAnnotations
()
throws
Exception
{
WithMockitoAnnotations
instance
=
new
WithMockitoAnnotations
();
WithMockitoAnnotations
instance
=
new
WithMockitoAnnotations
();
...
@@ -72,23 +67,27 @@ class MockitoTestExecutionListenerTests {
...
@@ -72,23 +67,27 @@ class MockitoTestExecutionListenerTests {
@Test
@Test
void
prepareTestInstanceShouldInjectMockBean
()
throws
Exception
{
void
prepareTestInstanceShouldInjectMockBean
()
throws
Exception
{
given
(
this
.
applicationContext
.
getBean
(
MockitoPostProcessor
.
class
)).
willReturn
(
this
.
postProcessor
);
WithMockBean
instance
=
new
WithMockBean
();
WithMockBean
instance
=
new
WithMockBean
();
this
.
listener
.
prepareTestInstance
(
mockTestContext
(
instance
));
TestContext
testContext
=
mockTestContext
(
instance
);
given
(
testContext
.
getApplicationContext
()).
willReturn
(
this
.
applicationContext
);
this
.
listener
.
prepareTestInstance
(
testContext
);
verify
(
this
.
postProcessor
).
inject
(
this
.
fieldCaptor
.
capture
(),
eq
(
instance
),
any
(
MockDefinition
.
class
));
verify
(
this
.
postProcessor
).
inject
(
this
.
fieldCaptor
.
capture
(),
eq
(
instance
),
any
(
MockDefinition
.
class
));
assertThat
(
this
.
fieldCaptor
.
getValue
().
getName
()).
isEqualTo
(
"mockBean"
);
assertThat
(
this
.
fieldCaptor
.
getValue
().
getName
()).
isEqualTo
(
"mockBean"
);
}
}
@Test
@Test
void
beforeTestMethodShouldDoNothingWhenDirtiesContextAttributeIsNotSet
()
throws
Exception
{
void
beforeTestMethodShouldDoNothingWhenDirtiesContextAttributeIsNotSet
()
throws
Exception
{
WithMockBean
instance
=
new
WithMockBean
();
this
.
listener
.
beforeTestMethod
(
mock
(
TestContext
.
class
));
this
.
listener
.
beforeTestMethod
(
mockTestContext
(
instance
));
verifyNoMoreInteractions
(
this
.
postProcessor
);
verifyNoMoreInteractions
(
this
.
postProcessor
);
}
}
@Test
@Test
void
beforeTestMethodShouldInjectMockBeanWhenDirtiesContextAttributeIsSet
()
throws
Exception
{
void
beforeTestMethodShouldInjectMockBeanWhenDirtiesContextAttributeIsSet
()
throws
Exception
{
given
(
this
.
applicationContext
.
getBean
(
MockitoPostProcessor
.
class
)).
willReturn
(
this
.
postProcessor
);
WithMockBean
instance
=
new
WithMockBean
();
WithMockBean
instance
=
new
WithMockBean
();
TestContext
mockTestContext
=
mockTestContext
(
instance
);
TestContext
mockTestContext
=
mockTestContext
(
instance
);
given
(
mockTestContext
.
getApplicationContext
()).
willReturn
(
this
.
applicationContext
);
given
(
mockTestContext
.
getAttribute
(
DependencyInjectionTestExecutionListener
.
REINJECT_DEPENDENCIES_ATTRIBUTE
))
given
(
mockTestContext
.
getAttribute
(
DependencyInjectionTestExecutionListener
.
REINJECT_DEPENDENCIES_ATTRIBUTE
))
.
willReturn
(
Boolean
.
TRUE
);
.
willReturn
(
Boolean
.
TRUE
);
this
.
listener
.
beforeTestMethod
(
mockTestContext
);
this
.
listener
.
beforeTestMethod
(
mockTestContext
);
...
@@ -101,7 +100,6 @@ class MockitoTestExecutionListenerTests {
...
@@ -101,7 +100,6 @@ class MockitoTestExecutionListenerTests {
TestContext
testContext
=
mock
(
TestContext
.
class
);
TestContext
testContext
=
mock
(
TestContext
.
class
);
given
(
testContext
.
getTestInstance
()).
willReturn
(
instance
);
given
(
testContext
.
getTestInstance
()).
willReturn
(
instance
);
given
(
testContext
.
getTestClass
()).
willReturn
((
Class
)
instance
.
getClass
());
given
(
testContext
.
getTestClass
()).
willReturn
((
Class
)
instance
.
getClass
());
given
(
testContext
.
getApplicationContext
()).
willReturn
(
this
.
applicationContext
);
return
testContext
;
return
testContext
;
}
}
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/mock/mockito/QualifierDefinitionTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -20,12 +20,12 @@ import java.lang.annotation.Retention;
...
@@ -20,12 +20,12 @@ import java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
...
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.verify;
...
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
QualifierDefinitionTests
{
class
QualifierDefinitionTests
{
@Mock
@Mock
...
@@ -51,11 +52,6 @@ class QualifierDefinitionTests {
...
@@ -51,11 +52,6 @@ class QualifierDefinitionTests {
@Captor
@Captor
private
ArgumentCaptor
<
DependencyDescriptor
>
descriptorCaptor
;
private
ArgumentCaptor
<
DependencyDescriptor
>
descriptorCaptor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
forElementFieldIsNullShouldReturnNull
()
{
void
forElementFieldIsNullShouldReturnNull
()
{
assertThat
(
QualifierDefinition
.
forElement
((
Field
)
null
)).
isNull
();
assertThat
(
QualifierDefinition
.
forElement
((
Field
)
null
)).
isNull
();
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/client/RootUriRequestExpectationManagerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -20,10 +20,11 @@ import java.net.URI;
...
@@ -20,10 +20,11 @@ import java.net.URI;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.http.client.ClientHttpRequest
;
import
org.springframework.http.client.ClientHttpRequest
;
...
@@ -49,6 +50,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
...
@@ -49,6 +50,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
RootUriRequestExpectationManagerTests
{
class
RootUriRequestExpectationManagerTests
{
private
String
uri
=
"https://example.com"
;
private
String
uri
=
"https://example.com"
;
...
@@ -63,7 +65,6 @@ class RootUriRequestExpectationManagerTests {
...
@@ -63,7 +65,6 @@ class RootUriRequestExpectationManagerTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
manager
=
new
RootUriRequestExpectationManager
(
this
.
uri
,
this
.
delegate
);
this
.
manager
=
new
RootUriRequestExpectationManager
(
this
.
uri
,
this
.
delegate
);
}
}
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/LocalHostWebClientTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -25,9 +25,10 @@ import com.gargoylesoftware.htmlunit.WebConnection;
...
@@ -25,9 +25,10 @@ import com.gargoylesoftware.htmlunit.WebConnection;
import
com.gargoylesoftware.htmlunit.WebRequest
;
import
com.gargoylesoftware.htmlunit.WebRequest
;
import
com.gargoylesoftware.htmlunit.WebResponse
;
import
com.gargoylesoftware.htmlunit.WebResponse
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.mock.env.MockEnvironment
;
import
org.springframework.mock.env.MockEnvironment
;
...
@@ -44,15 +45,12 @@ import static org.mockito.Mockito.verify;
...
@@ -44,15 +45,12 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@SuppressWarnings
(
"resource"
)
@SuppressWarnings
(
"resource"
)
@ExtendWith
(
MockitoExtension
.
class
)
class
LocalHostWebClientTests
{
class
LocalHostWebClientTests
{
@Captor
@Captor
private
ArgumentCaptor
<
WebRequest
>
requestCaptor
;
private
ArgumentCaptor
<
WebRequest
>
requestCaptor
;
LocalHostWebClientTests
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
createWhenEnvironmentIsNullWillThrowException
()
{
void
createWhenEnvironmentIsNullWillThrowException
()
{
assertThatIllegalArgumentException
().
isThrownBy
(()
->
new
LocalHostWebClient
(
null
))
assertThatIllegalArgumentException
().
isThrownBy
(()
->
new
LocalHostWebClient
(
null
))
...
...
spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/htmlunit/webdriver/LocalHostWebConnectionHtmlUnitDriverTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -25,9 +25,10 @@ import com.gargoylesoftware.htmlunit.WebConsole;
...
@@ -25,9 +25,10 @@ import com.gargoylesoftware.htmlunit.WebConsole;
import
com.gargoylesoftware.htmlunit.WebRequest
;
import
com.gargoylesoftware.htmlunit.WebRequest
;
import
com.gargoylesoftware.htmlunit.WebWindow
;
import
com.gargoylesoftware.htmlunit.WebWindow
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentMatcher
;
import
org.mockito.ArgumentMatcher
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.openqa.selenium.Capabilities
;
import
org.openqa.selenium.Capabilities
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
...
@@ -45,13 +46,13 @@ import static org.mockito.Mockito.verify;
...
@@ -45,13 +46,13 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
LocalHostWebConnectionHtmlUnitDriverTests
{
class
LocalHostWebConnectionHtmlUnitDriverTests
{
@Mock
private
final
WebClient
webClient
;
private
WebClient
webClient
;
LocalHostWebConnectionHtmlUnitDriverTests
()
{
LocalHostWebConnectionHtmlUnitDriverTests
(
@Mock
WebClient
webClient
)
{
MockitoAnnotations
.
initMocks
(
this
)
;
this
.
webClient
=
webClient
;
given
(
this
.
webClient
.
getOptions
()).
willReturn
(
new
WebClientOptions
());
given
(
this
.
webClient
.
getOptions
()).
willReturn
(
new
WebClientOptions
());
given
(
this
.
webClient
.
getWebConsole
()).
willReturn
(
new
WebConsole
());
given
(
this
.
webClient
.
getWebConsole
()).
willReturn
(
new
WebConsole
());
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java
View file @
969dd35e
...
@@ -24,11 +24,12 @@ import java.net.URI;
...
@@ -24,11 +24,12 @@ import java.net.URI;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Nested
;
import
org.junit.jupiter.api.Nested
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.InOrder
;
import
org.mockito.InOrder
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi
;
import
org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi
;
import
org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi
;
import
org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi
;
...
@@ -64,6 +65,7 @@ import static org.mockito.Mockito.verify;
...
@@ -64,6 +65,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
* @author Scott Frederick
* @author Scott Frederick
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
DockerApiTests
{
class
DockerApiTests
{
private
static
final
String
API_URL
=
"/"
+
DockerApi
.
API_VERSION
;
private
static
final
String
API_URL
=
"/"
+
DockerApi
.
API_VERSION
;
...
@@ -81,7 +83,6 @@ class DockerApiTests {
...
@@ -81,7 +83,6 @@ class DockerApiTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
dockerApi
=
new
DockerApi
(
this
.
http
);
this
.
dockerApi
=
new
DockerApi
(
this
.
http
);
}
}
...
@@ -127,7 +128,6 @@ class DockerApiTests {
...
@@ -127,7 +128,6 @@ class DockerApiTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
api
=
DockerApiTests
.
this
.
dockerApi
.
image
();
this
.
api
=
DockerApiTests
.
this
.
dockerApi
.
image
();
}
}
...
@@ -232,7 +232,6 @@ class DockerApiTests {
...
@@ -232,7 +232,6 @@ class DockerApiTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
api
=
DockerApiTests
.
this
.
dockerApi
.
container
();
this
.
api
=
DockerApiTests
.
this
.
dockerApi
.
container
();
}
}
...
@@ -370,7 +369,6 @@ class DockerApiTests {
...
@@ -370,7 +369,6 @@ class DockerApiTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
api
=
DockerApiTests
.
this
.
dockerApi
.
volume
();
this
.
api
=
DockerApiTests
.
this
.
dockerApi
.
volume
();
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java
View file @
969dd35e
...
@@ -37,10 +37,11 @@ import org.apache.http.client.methods.HttpUriRequest;
...
@@ -37,10 +37,11 @@ import org.apache.http.client.methods.HttpUriRequest;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.buildpack.platform.docker.transport.HttpTransport.Response
;
import
org.springframework.boot.buildpack.platform.docker.transport.HttpTransport.Response
;
import
org.springframework.util.StreamUtils
;
import
org.springframework.util.StreamUtils
;
...
@@ -58,6 +59,7 @@ import static org.mockito.Mockito.verify;
...
@@ -58,6 +59,7 @@ import static org.mockito.Mockito.verify;
* @author Mike Smithson
* @author Mike Smithson
* @author Scott Frederick
* @author Scott Frederick
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
HttpClientTransportTests
{
class
HttpClientTransportTests
{
private
static
final
String
APPLICATION_JSON
=
"application/json"
;
private
static
final
String
APPLICATION_JSON
=
"application/json"
;
...
@@ -89,16 +91,13 @@ class HttpClientTransportTests {
...
@@ -89,16 +91,13 @@ class HttpClientTransportTests {
@BeforeEach
@BeforeEach
void
setup
()
throws
Exception
{
void
setup
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
client
.
execute
(
any
(
HttpHost
.
class
),
any
(
HttpRequest
.
class
))).
willReturn
(
this
.
response
);
given
(
this
.
response
.
getEntity
()).
willReturn
(
this
.
entity
);
given
(
this
.
response
.
getStatusLine
()).
willReturn
(
this
.
statusLine
);
this
.
http
=
new
TestHttpClientTransport
(
this
.
client
);
this
.
http
=
new
TestHttpClientTransport
(
this
.
client
);
this
.
uri
=
new
URI
(
"example"
);
this
.
uri
=
new
URI
(
"example"
);
}
}
@Test
@Test
void
getShouldExecuteHttpGet
()
throws
Exception
{
void
getShouldExecuteHttpGet
()
throws
Exception
{
givenClientWillReturnResponse
();
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
Response
response
=
this
.
http
.
get
(
this
.
uri
);
Response
response
=
this
.
http
.
get
(
this
.
uri
);
...
@@ -112,6 +111,7 @@ class HttpClientTransportTests {
...
@@ -112,6 +111,7 @@ class HttpClientTransportTests {
@Test
@Test
void
postShouldExecuteHttpPost
()
throws
Exception
{
void
postShouldExecuteHttpPost
()
throws
Exception
{
givenClientWillReturnResponse
();
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
Response
response
=
this
.
http
.
post
(
this
.
uri
);
Response
response
=
this
.
http
.
post
(
this
.
uri
);
...
@@ -125,6 +125,7 @@ class HttpClientTransportTests {
...
@@ -125,6 +125,7 @@ class HttpClientTransportTests {
@Test
@Test
void
postWithContentShouldExecuteHttpPost
()
throws
Exception
{
void
postWithContentShouldExecuteHttpPost
()
throws
Exception
{
givenClientWillReturnResponse
();
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
Response
response
=
this
.
http
.
post
(
this
.
uri
,
APPLICATION_JSON
,
Response
response
=
this
.
http
.
post
(
this
.
uri
,
APPLICATION_JSON
,
...
@@ -145,6 +146,7 @@ class HttpClientTransportTests {
...
@@ -145,6 +146,7 @@ class HttpClientTransportTests {
@Test
@Test
void
putWithContentShouldExecuteHttpPut
()
throws
Exception
{
void
putWithContentShouldExecuteHttpPut
()
throws
Exception
{
givenClientWillReturnResponse
();
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
Response
response
=
this
.
http
.
put
(
this
.
uri
,
APPLICATION_JSON
,
Response
response
=
this
.
http
.
put
(
this
.
uri
,
APPLICATION_JSON
,
...
@@ -165,6 +167,7 @@ class HttpClientTransportTests {
...
@@ -165,6 +167,7 @@ class HttpClientTransportTests {
@Test
@Test
void
deleteShouldExecuteHttpDelete
()
throws
IOException
{
void
deleteShouldExecuteHttpDelete
()
throws
IOException
{
givenClientWillReturnResponse
();
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
200
);
Response
response
=
this
.
http
.
delete
(
this
.
uri
);
Response
response
=
this
.
http
.
delete
(
this
.
uri
);
...
@@ -178,6 +181,7 @@ class HttpClientTransportTests {
...
@@ -178,6 +181,7 @@ class HttpClientTransportTests {
@Test
@Test
void
executeWhenResponseIsIn400RangeShouldThrowDockerException
()
throws
IOException
{
void
executeWhenResponseIsIn400RangeShouldThrowDockerException
()
throws
IOException
{
givenClientWillReturnResponse
();
given
(
this
.
entity
.
getContent
()).
willReturn
(
getClass
().
getResourceAsStream
(
"errors.json"
));
given
(
this
.
entity
.
getContent
()).
willReturn
(
getClass
().
getResourceAsStream
(
"errors.json"
));
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
404
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
404
);
assertThatExceptionOfType
(
DockerEngineException
.
class
).
isThrownBy
(()
->
this
.
http
.
get
(
this
.
uri
))
assertThatExceptionOfType
(
DockerEngineException
.
class
).
isThrownBy
(()
->
this
.
http
.
get
(
this
.
uri
))
...
@@ -188,7 +192,8 @@ class HttpClientTransportTests {
...
@@ -188,7 +192,8 @@ class HttpClientTransportTests {
}
}
@Test
@Test
void
executeWhenResponseIsIn500RangeWithNoContentShouldThrowDockerException
()
{
void
executeWhenResponseIsIn500RangeWithNoContentShouldThrowDockerException
()
throws
IOException
{
givenClientWillReturnResponse
();
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
500
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
500
);
assertThatExceptionOfType
(
DockerEngineException
.
class
).
isThrownBy
(()
->
this
.
http
.
get
(
this
.
uri
))
assertThatExceptionOfType
(
DockerEngineException
.
class
).
isThrownBy
(()
->
this
.
http
.
get
(
this
.
uri
))
.
satisfies
((
ex
)
->
{
.
satisfies
((
ex
)
->
{
...
@@ -199,6 +204,7 @@ class HttpClientTransportTests {
...
@@ -199,6 +204,7 @@ class HttpClientTransportTests {
@Test
@Test
void
executeWhenResponseIsIn500RangeWithMessageShouldThrowDockerException
()
throws
IOException
{
void
executeWhenResponseIsIn500RangeWithMessageShouldThrowDockerException
()
throws
IOException
{
givenClientWillReturnResponse
();
given
(
this
.
entity
.
getContent
()).
willReturn
(
getClass
().
getResourceAsStream
(
"message.json"
));
given
(
this
.
entity
.
getContent
()).
willReturn
(
getClass
().
getResourceAsStream
(
"message.json"
));
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
500
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
500
);
assertThatExceptionOfType
(
DockerEngineException
.
class
).
isThrownBy
(()
->
this
.
http
.
get
(
this
.
uri
))
assertThatExceptionOfType
(
DockerEngineException
.
class
).
isThrownBy
(()
->
this
.
http
.
get
(
this
.
uri
))
...
@@ -210,6 +216,7 @@ class HttpClientTransportTests {
...
@@ -210,6 +216,7 @@ class HttpClientTransportTests {
@Test
@Test
void
executeWhenResponseIsIn500RangeWithOtherContentShouldThrowDockerException
()
throws
IOException
{
void
executeWhenResponseIsIn500RangeWithOtherContentShouldThrowDockerException
()
throws
IOException
{
givenClientWillReturnResponse
();
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
entity
.
getContent
()).
willReturn
(
this
.
content
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
500
);
given
(
this
.
statusLine
.
getStatusCode
()).
willReturn
(
500
);
assertThatExceptionOfType
(
DockerEngineException
.
class
).
isThrownBy
(()
->
this
.
http
.
get
(
this
.
uri
))
assertThatExceptionOfType
(
DockerEngineException
.
class
).
isThrownBy
(()
->
this
.
http
.
get
(
this
.
uri
))
...
@@ -233,6 +240,12 @@ class HttpClientTransportTests {
...
@@ -233,6 +240,12 @@ class HttpClientTransportTests {
return
new
String
(
out
.
toByteArray
(),
StandardCharsets
.
UTF_8
);
return
new
String
(
out
.
toByteArray
(),
StandardCharsets
.
UTF_8
);
}
}
private
void
givenClientWillReturnResponse
()
throws
IOException
{
given
(
this
.
client
.
execute
(
any
(
HttpHost
.
class
),
any
(
HttpRequest
.
class
))).
willReturn
(
this
.
response
);
given
(
this
.
response
.
getEntity
()).
willReturn
(
this
.
entity
);
given
(
this
.
response
.
getStatusLine
()).
willReturn
(
this
.
statusLine
);
}
/**
/**
* Test {@link HttpClientTransport} implementation.
* Test {@link HttpClientTransport} implementation.
*/
*/
...
...
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/build.gradle
View file @
969dd35e
...
@@ -13,4 +13,5 @@ dependencies {
...
@@ -13,4 +13,5 @@ dependencies {
testImplementation
(
"org.assertj:assertj-core"
)
testImplementation
(
"org.assertj:assertj-core"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
}
}
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/ExtractCommandTests.java
View file @
969dd35e
...
@@ -27,9 +27,10 @@ import java.util.zip.ZipOutputStream;
...
@@ -27,9 +27,10 @@ import java.util.zip.ZipOutputStream;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
...
@@ -39,6 +40,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -39,6 +40,7 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ExtractCommandTests
{
class
ExtractCommandTests
{
@TempDir
@TempDir
...
@@ -57,17 +59,16 @@ class ExtractCommandTests {
...
@@ -57,17 +59,16 @@ class ExtractCommandTests {
@BeforeEach
@BeforeEach
void
setup
()
throws
Exception
{
void
setup
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
jarFile
=
createJarFile
(
"test.jar"
);
this
.
jarFile
=
createJarFile
(
"test.jar"
);
this
.
extract
=
new
File
(
this
.
temp
,
"extract"
);
this
.
extract
=
new
File
(
this
.
temp
,
"extract"
);
this
.
extract
.
mkdir
();
this
.
extract
.
mkdir
();
given
(
this
.
context
.
getJarFile
()).
willReturn
(
this
.
jarFile
);
given
(
this
.
context
.
getWorkingDir
()).
willReturn
(
this
.
extract
);
this
.
command
=
new
ExtractCommand
(
this
.
context
,
this
.
layers
);
this
.
command
=
new
ExtractCommand
(
this
.
context
,
this
.
layers
);
}
}
@Test
@Test
void
runExtractsLayers
()
throws
Exception
{
void
runExtractsLayers
()
throws
Exception
{
given
(
this
.
context
.
getJarFile
()).
willReturn
(
this
.
jarFile
);
given
(
this
.
context
.
getWorkingDir
()).
willReturn
(
this
.
extract
);
this
.
command
.
run
(
Collections
.
emptyMap
(),
Collections
.
emptyList
());
this
.
command
.
run
(
Collections
.
emptyMap
(),
Collections
.
emptyList
());
assertThat
(
this
.
extract
.
list
()).
containsOnly
(
"a"
,
"b"
,
"c"
,
"d"
);
assertThat
(
this
.
extract
.
list
()).
containsOnly
(
"a"
,
"b"
,
"c"
,
"d"
);
assertThat
(
new
File
(
this
.
extract
,
"a/a/a.jar"
)).
exists
();
assertThat
(
new
File
(
this
.
extract
,
"a/a/a.jar"
)).
exists
();
...
@@ -78,6 +79,7 @@ class ExtractCommandTests {
...
@@ -78,6 +79,7 @@ class ExtractCommandTests {
@Test
@Test
void
runWhenHasDestinationOptionExtractsLayers
()
{
void
runWhenHasDestinationOptionExtractsLayers
()
{
given
(
this
.
context
.
getJarFile
()).
willReturn
(
this
.
jarFile
);
File
out
=
new
File
(
this
.
extract
,
"out"
);
File
out
=
new
File
(
this
.
extract
,
"out"
);
this
.
command
.
run
(
Collections
.
singletonMap
(
ExtractCommand
.
DESTINATION_OPTION
,
out
.
getAbsolutePath
()),
this
.
command
.
run
(
Collections
.
singletonMap
(
ExtractCommand
.
DESTINATION_OPTION
,
out
.
getAbsolutePath
()),
Collections
.
emptyList
());
Collections
.
emptyList
());
...
@@ -89,6 +91,8 @@ class ExtractCommandTests {
...
@@ -89,6 +91,8 @@ class ExtractCommandTests {
@Test
@Test
void
runWhenHasLayerParamsExtractsLimitedLayers
()
{
void
runWhenHasLayerParamsExtractsLimitedLayers
()
{
given
(
this
.
context
.
getJarFile
()).
willReturn
(
this
.
jarFile
);
given
(
this
.
context
.
getWorkingDir
()).
willReturn
(
this
.
extract
);
this
.
command
.
run
(
Collections
.
emptyMap
(),
Arrays
.
asList
(
"a"
,
"c"
));
this
.
command
.
run
(
Collections
.
emptyMap
(),
Arrays
.
asList
(
"a"
,
"c"
));
assertThat
(
this
.
extract
.
list
()).
containsOnly
(
"a"
,
"c"
);
assertThat
(
this
.
extract
.
list
()).
containsOnly
(
"a"
,
"c"
);
assertThat
(
new
File
(
this
.
extract
,
"a/a/a.jar"
)).
exists
();
assertThat
(
new
File
(
this
.
extract
,
"a/a/a.jar"
)).
exists
();
...
...
spring-boot-project/spring-boot-tools/spring-boot-jarmode-layertools/src/test/java/org/springframework/boot/jarmode/layertools/ListCommandTests.java
View file @
969dd35e
...
@@ -28,9 +28,10 @@ import java.util.zip.ZipOutputStream;
...
@@ -28,9 +28,10 @@ import java.util.zip.ZipOutputStream;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.junit.jupiter.api.io.TempDir
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
...
@@ -41,6 +42,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -41,6 +42,7 @@ import static org.mockito.BDDMockito.given;
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ListCommandTests
{
class
ListCommandTests
{
@TempDir
@TempDir
...
@@ -51,19 +53,18 @@ class ListCommandTests {
...
@@ -51,19 +53,18 @@ class ListCommandTests {
private
File
jarFile
;
private
File
jarFile
;
private
ListCommand
command
;
private
TestPrintStream
out
;
@BeforeEach
@BeforeEach
void
setup
()
throws
Exception
{
void
setup
()
throws
Exception
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
jarFile
=
createJarFile
(
"test.jar"
);
this
.
jarFile
=
createJarFile
(
"test.jar"
);
given
(
this
.
context
.
getJarFile
()).
willReturn
(
this
.
jarFile
);
given
(
this
.
context
.
getJarFile
()).
willReturn
(
this
.
jarFile
);
this
.
command
=
new
ListCommand
(
this
.
context
);
this
.
command
=
new
ListCommand
(
this
.
context
);
this
.
out
=
new
TestPrintStream
(
this
);
this
.
out
=
new
TestPrintStream
(
this
);
}
}
private
ListCommand
command
;
private
TestPrintStream
out
;
@Test
@Test
void
listLayersShouldListLayers
()
{
void
listLayersShouldListLayers
()
{
Layers
layers
=
IndexedLayers
.
get
(
this
.
context
);
Layers
layers
=
IndexedLayers
.
get
(
this
.
context
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle
View file @
969dd35e
...
@@ -36,6 +36,7 @@ dependencies {
...
@@ -36,6 +36,7 @@ dependencies {
testImplementation
(
"org.assertj:assertj-core"
)
testImplementation
(
"org.assertj:assertj-core"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.springframework:spring-core"
)
testImplementation
(
"org.springframework:spring-core"
)
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -28,10 +28,11 @@ import org.apache.maven.model.Dependency;
...
@@ -28,10 +28,11 @@ import org.apache.maven.model.Dependency;
import
org.apache.maven.plugin.logging.Log
;
import
org.apache.maven.plugin.logging.Log
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.loader.tools.Library
;
import
org.springframework.boot.loader.tools.Library
;
import
org.springframework.boot.loader.tools.LibraryCallback
;
import
org.springframework.boot.loader.tools.LibraryCallback
;
...
@@ -48,6 +49,7 @@ import static org.mockito.Mockito.verify;
...
@@ -48,6 +49,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ArtifactsLibrariesTests
{
class
ArtifactsLibrariesTests
{
@Mock
@Mock
...
@@ -70,17 +72,15 @@ class ArtifactsLibrariesTests {
...
@@ -70,17 +72,15 @@ class ArtifactsLibrariesTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
artifacts
=
Collections
.
singleton
(
this
.
artifact
);
this
.
artifacts
=
Collections
.
singleton
(
this
.
artifact
);
this
.
libs
=
new
ArtifactsLibraries
(
this
.
artifacts
,
null
,
mock
(
Log
.
class
));
this
.
libs
=
new
ArtifactsLibraries
(
this
.
artifacts
,
null
,
mock
(
Log
.
class
));
given
(
this
.
artifact
.
getFile
()).
willReturn
(
this
.
file
);
given
(
this
.
artifactHandler
.
getExtension
()).
willReturn
(
"jar"
);
given
(
this
.
artifactHandler
.
getExtension
()).
willReturn
(
"jar"
);
given
(
this
.
artifact
.
getArtifactHandler
()).
willReturn
(
this
.
artifactHandler
);
}
}
@Test
@Test
void
callbackForJars
()
throws
Exception
{
void
callbackForJars
()
throws
Exception
{
given
(
this
.
artifact
.
getType
()).
willReturn
(
"jar"
);
given
(
this
.
artifact
.
getFile
()).
willReturn
(
this
.
file
);
given
(
this
.
artifact
.
getArtifactHandler
()).
willReturn
(
this
.
artifactHandler
);
given
(
this
.
artifact
.
getScope
()).
willReturn
(
"compile"
);
given
(
this
.
artifact
.
getScope
()).
willReturn
(
"compile"
);
this
.
libs
.
doWithLibraries
(
this
.
callback
);
this
.
libs
.
doWithLibraries
(
this
.
callback
);
verify
(
this
.
callback
).
library
(
this
.
libraryCaptor
.
capture
());
verify
(
this
.
callback
).
library
(
this
.
libraryCaptor
.
capture
());
...
@@ -92,9 +92,10 @@ class ArtifactsLibrariesTests {
...
@@ -92,9 +92,10 @@ class ArtifactsLibrariesTests {
@Test
@Test
void
callbackWithUnpack
()
throws
Exception
{
void
callbackWithUnpack
()
throws
Exception
{
given
(
this
.
artifact
.
getFile
()).
willReturn
(
this
.
file
);
given
(
this
.
artifact
.
getArtifactHandler
()).
willReturn
(
this
.
artifactHandler
);
given
(
this
.
artifact
.
getGroupId
()).
willReturn
(
"gid"
);
given
(
this
.
artifact
.
getGroupId
()).
willReturn
(
"gid"
);
given
(
this
.
artifact
.
getArtifactId
()).
willReturn
(
"aid"
);
given
(
this
.
artifact
.
getArtifactId
()).
willReturn
(
"aid"
);
given
(
this
.
artifact
.
getType
()).
willReturn
(
"jar"
);
given
(
this
.
artifact
.
getScope
()).
willReturn
(
"compile"
);
given
(
this
.
artifact
.
getScope
()).
willReturn
(
"compile"
);
Dependency
unpack
=
new
Dependency
();
Dependency
unpack
=
new
Dependency
();
unpack
.
setGroupId
(
"gid"
);
unpack
.
setGroupId
(
"gid"
);
...
@@ -109,14 +110,12 @@ class ArtifactsLibrariesTests {
...
@@ -109,14 +110,12 @@ class ArtifactsLibrariesTests {
void
renamesDuplicates
()
throws
Exception
{
void
renamesDuplicates
()
throws
Exception
{
Artifact
artifact1
=
mock
(
Artifact
.
class
);
Artifact
artifact1
=
mock
(
Artifact
.
class
);
Artifact
artifact2
=
mock
(
Artifact
.
class
);
Artifact
artifact2
=
mock
(
Artifact
.
class
);
given
(
artifact1
.
getType
()).
willReturn
(
"jar"
);
given
(
artifact1
.
getScope
()).
willReturn
(
"compile"
);
given
(
artifact1
.
getScope
()).
willReturn
(
"compile"
);
given
(
artifact1
.
getGroupId
()).
willReturn
(
"g1"
);
given
(
artifact1
.
getGroupId
()).
willReturn
(
"g1"
);
given
(
artifact1
.
getArtifactId
()).
willReturn
(
"artifact"
);
given
(
artifact1
.
getArtifactId
()).
willReturn
(
"artifact"
);
given
(
artifact1
.
getBaseVersion
()).
willReturn
(
"1.0"
);
given
(
artifact1
.
getBaseVersion
()).
willReturn
(
"1.0"
);
given
(
artifact1
.
getFile
()).
willReturn
(
new
File
(
"a"
));
given
(
artifact1
.
getFile
()).
willReturn
(
new
File
(
"a"
));
given
(
artifact1
.
getArtifactHandler
()).
willReturn
(
this
.
artifactHandler
);
given
(
artifact1
.
getArtifactHandler
()).
willReturn
(
this
.
artifactHandler
);
given
(
artifact2
.
getType
()).
willReturn
(
"jar"
);
given
(
artifact2
.
getScope
()).
willReturn
(
"compile"
);
given
(
artifact2
.
getScope
()).
willReturn
(
"compile"
);
given
(
artifact2
.
getGroupId
()).
willReturn
(
"g2"
);
given
(
artifact2
.
getGroupId
()).
willReturn
(
"g2"
);
given
(
artifact2
.
getArtifactId
()).
willReturn
(
"artifact"
);
given
(
artifact2
.
getArtifactId
()).
willReturn
(
"artifact"
);
...
...
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/web/servlet/MockServletWebServer.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -25,7 +25,6 @@ import java.util.Map;
...
@@ -25,7 +25,6 @@ import java.util.Map;
import
javax.servlet.Filter
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterRegistration
;
import
javax.servlet.FilterRegistration
;
import
javax.servlet.RequestDispatcher
;
import
javax.servlet.Servlet
;
import
javax.servlet.Servlet
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletException
;
...
@@ -34,6 +33,7 @@ import javax.servlet.ServletRegistration;
...
@@ -34,6 +33,7 @@ import javax.servlet.ServletRegistration;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
lenient
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
/**
...
@@ -66,27 +66,26 @@ public abstract class MockServletWebServer {
...
@@ -66,27 +66,26 @@ public abstract class MockServletWebServer {
private
void
initialize
()
{
private
void
initialize
()
{
try
{
try
{
this
.
servletContext
=
mock
(
ServletContext
.
class
);
this
.
servletContext
=
mock
(
ServletContext
.
class
);
given
(
this
.
servletContext
.
addServlet
(
anyString
(),
any
(
Servlet
.
class
))).
will
Answer
((
invocation
)
->
{
lenient
().
do
Answer
((
invocation
)
->
{
RegisteredServlet
registeredServlet
=
new
RegisteredServlet
(
invocation
.
getArgument
(
1
));
RegisteredServlet
registeredServlet
=
new
RegisteredServlet
(
invocation
.
getArgument
(
1
));
MockServletWebServer
.
this
.
registeredServlets
.
add
(
registeredServlet
);
MockServletWebServer
.
this
.
registeredServlets
.
add
(
registeredServlet
);
return
registeredServlet
.
getRegistration
();
return
registeredServlet
.
getRegistration
();
});
})
.
when
(
this
.
servletContext
).
addServlet
(
anyString
(),
any
(
Servlet
.
class
))
;
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
will
Answer
((
invocation
)
->
{
lenient
().
do
Answer
((
invocation
)
->
{
RegisteredFilter
registeredFilter
=
new
RegisteredFilter
(
invocation
.
getArgument
(
1
));
RegisteredFilter
registeredFilter
=
new
RegisteredFilter
(
invocation
.
getArgument
(
1
));
MockServletWebServer
.
this
.
registeredFilters
.
add
(
registeredFilter
);
MockServletWebServer
.
this
.
registeredFilters
.
add
(
registeredFilter
);
return
registeredFilter
.
getRegistration
();
return
registeredFilter
.
getRegistration
();
});
})
.
when
(
this
.
servletContext
).
addFilter
(
anyString
(),
any
(
Filter
.
class
))
;
final
Map
<
String
,
String
>
initParameters
=
new
HashMap
<>();
final
Map
<
String
,
String
>
initParameters
=
new
HashMap
<>();
given
(
this
.
servletContext
.
setInitParameter
(
anyString
(),
anyString
())).
will
((
invocation
)
->
{
lenient
().
doAnswer
((
invocation
)
->
{
initParameters
.
put
(
invocation
.
getArgument
(
0
),
invocation
.
getArgument
(
1
));
initParameters
.
put
(
invocation
.
getArgument
(
0
),
invocation
.
getArgument
(
1
));
return
null
;
return
null
;
});
})
.
when
(
this
.
servletContext
).
setInitParameter
(
anyString
(),
anyString
())
;
given
(
this
.
servletContext
.
getInitParameterNames
())
given
(
this
.
servletContext
.
getInitParameterNames
())
.
willReturn
(
Collections
.
enumeration
(
initParameters
.
keySet
()));
.
willReturn
(
Collections
.
enumeration
(
initParameters
.
keySet
()));
given
(
this
.
servletContext
.
getInitParameter
(
anyString
())
)
lenient
().
doAnswer
((
invocation
)
->
initParameters
.
get
(
invocation
.
getArgument
(
0
))).
when
(
this
.
servletContext
)
.
willAnswer
((
invocation
)
->
initParameters
.
get
(
invocation
.
getArgument
(
0
)
));
.
getInitParameter
(
anyString
(
));
given
(
this
.
servletContext
.
getAttributeNames
()).
willReturn
(
Collections
.
emptyEnumeration
());
given
(
this
.
servletContext
.
getAttributeNames
()).
willReturn
(
Collections
.
emptyEnumeration
());
given
(
this
.
servletContext
.
getNamedDispatcher
(
"default"
)).
willReturn
(
mock
(
RequestDispatcher
.
class
));
for
(
Initializer
initializer
:
this
.
initializers
)
{
for
(
Initializer
initializer
:
this
.
initializers
)
{
initializer
.
onStartup
(
this
.
servletContext
);
initializer
.
onStartup
(
this
.
servletContext
);
}
}
...
...
spring-boot-project/spring-boot/build.gradle
View file @
969dd35e
...
@@ -92,6 +92,7 @@ dependencies {
...
@@ -92,6 +92,7 @@ dependencies {
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.junit.jupiter:junit-jupiter"
)
testImplementation
(
"org.mariadb.jdbc:mariadb-java-client"
)
testImplementation
(
"org.mariadb.jdbc:mariadb-java-client"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-core"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.postgresql:postgresql"
)
testImplementation
(
"org.postgresql:postgresql"
)
testImplementation
(
"org.springframework:spring-context-support"
)
testImplementation
(
"org.springframework:spring-context-support"
)
testImplementation
(
"org.springframework.data:spring-data-redis"
)
testImplementation
(
"org.springframework.data:spring-data-redis"
)
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/BannerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -19,12 +19,11 @@ package org.springframework.boot;
...
@@ -19,12 +19,11 @@ package org.springframework.boot;
import
java.io.PrintStream
;
import
java.io.PrintStream
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.Banner.Mode
;
import
org.springframework.boot.Banner.Mode
;
import
org.springframework.boot.testsupport.system.CapturedOutput
;
import
org.springframework.boot.testsupport.system.CapturedOutput
;
...
@@ -47,7 +46,7 @@ import static org.mockito.Mockito.verify;
...
@@ -47,7 +46,7 @@ import static org.mockito.Mockito.verify;
* @author Michael Stummvoll
* @author Michael Stummvoll
* @author Michael Simons
* @author Michael Simons
*/
*/
@ExtendWith
(
OutputCaptureExtension
.
class
)
@ExtendWith
(
{
MockitoExtension
.
class
,
OutputCaptureExtension
.
class
}
)
class
BannerTests
{
class
BannerTests
{
private
ConfigurableApplicationContext
context
;
private
ConfigurableApplicationContext
context
;
...
@@ -62,11 +61,6 @@ class BannerTests {
...
@@ -62,11 +61,6 @@ class BannerTests {
@Captor
@Captor
private
ArgumentCaptor
<
Class
<?>>
sourceClassCaptor
;
private
ArgumentCaptor
<
Class
<?>>
sourceClassCaptor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
testDefaultBanner
(
CapturedOutput
output
)
{
void
testDefaultBanner
(
CapturedOutput
output
)
{
SpringApplication
application
=
createSpringApplication
();
SpringApplication
application
=
createSpringApplication
();
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorsTests.java
View file @
969dd35e
...
@@ -25,9 +25,10 @@ import java.util.function.Supplier;
...
@@ -25,9 +25,10 @@ import java.util.function.Supplier;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.cloud.CloudPlatform
;
import
org.springframework.boot.cloud.CloudPlatform
;
import
org.springframework.boot.context.config.ConfigDataEnvironmentContributor.Kind
;
import
org.springframework.boot.context.config.ConfigDataEnvironmentContributor.Kind
;
...
@@ -52,6 +53,7 @@ import static org.mockito.Mockito.verify;
...
@@ -52,6 +53,7 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ConfigDataEnvironmentContributorsTests
{
class
ConfigDataEnvironmentContributorsTests
{
private
DeferredLogFactory
logFactory
=
Supplier:
:
get
;
private
DeferredLogFactory
logFactory
=
Supplier:
:
get
;
...
@@ -69,7 +71,6 @@ class ConfigDataEnvironmentContributorsTests {
...
@@ -69,7 +71,6 @@ class ConfigDataEnvironmentContributorsTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
environment
=
new
MockEnvironment
();
this
.
environment
=
new
MockEnvironment
();
this
.
binder
=
Binder
.
get
(
this
.
environment
);
this
.
binder
=
Binder
.
get
(
this
.
environment
);
ConfigDataLocationResolvers
resolvers
=
new
ConfigDataLocationResolvers
(
this
.
logFactory
,
this
.
binder
,
null
);
ConfigDataLocationResolvers
resolvers
=
new
ConfigDataLocationResolvers
(
this
.
logFactory
,
this
.
binder
,
null
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorTests.java
View file @
969dd35e
...
@@ -19,12 +19,13 @@ package org.springframework.boot.context.config;
...
@@ -19,12 +19,13 @@ package org.springframework.boot.context.config;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
itoAnnotations
;
import
org.mockito.Mock
;
import
org.mockito.Spy
;
import
org.mockito.Spy
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.env.StandardEnvironment
;
...
@@ -46,13 +47,15 @@ import static org.mockito.Mockito.verifyNoInteractions;
...
@@ -46,13 +47,15 @@ import static org.mockito.Mockito.verifyNoInteractions;
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ConfigDataEnvironmentPostProcessorTests
{
class
ConfigDataEnvironmentPostProcessorTests
{
private
ConfigDataEnvironment
configDataEnvironment
=
mock
(
ConfigDataEnvironment
.
class
);
private
StandardEnvironment
environment
=
new
StandardEnvironment
(
);
private
S
tandardEnvironment
environment
;
private
S
pringApplication
application
=
new
SpringApplication
()
;
private
SpringApplication
application
;
@Mock
private
ConfigDataEnvironment
configDataEnvironment
;
@Spy
@Spy
private
ConfigDataEnvironmentPostProcessor
postProcessor
=
new
ConfigDataEnvironmentPostProcessor
(
Supplier:
:
get
);
private
ConfigDataEnvironmentPostProcessor
postProcessor
=
new
ConfigDataEnvironmentPostProcessor
(
Supplier:
:
get
);
...
@@ -63,13 +66,6 @@ class ConfigDataEnvironmentPostProcessorTests {
...
@@ -63,13 +66,6 @@ class ConfigDataEnvironmentPostProcessorTests {
@Captor
@Captor
private
ArgumentCaptor
<
ResourceLoader
>
resourceLoaderCaptor
;
private
ArgumentCaptor
<
ResourceLoader
>
resourceLoaderCaptor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
application
=
new
SpringApplication
();
this
.
environment
=
new
StandardEnvironment
();
}
@Test
@Test
@SuppressWarnings
(
"deprecation"
)
@SuppressWarnings
(
"deprecation"
)
void
defaultOrderMatchesDeprecatedListener
()
{
void
defaultOrderMatchesDeprecatedListener
()
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataImporterTests.java
View file @
969dd35e
...
@@ -23,8 +23,9 @@ import java.util.List;
...
@@ -23,8 +23,9 @@ import java.util.List;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.mock.env.MockPropertySource
;
import
org.springframework.mock.env.MockPropertySource
;
...
@@ -38,6 +39,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -38,6 +39,7 @@ import static org.mockito.BDDMockito.given;
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ConfigDataImporterTests
{
class
ConfigDataImporterTests
{
@Mock
@Mock
...
@@ -60,7 +62,6 @@ class ConfigDataImporterTests {
...
@@ -60,7 +62,6 @@ class ConfigDataImporterTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
activationContext
.
getProfiles
()).
willReturn
(
this
.
profiles
);
given
(
this
.
activationContext
.
getProfiles
()).
willReturn
(
this
.
profiles
);
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java
View file @
969dd35e
...
@@ -23,10 +23,10 @@ import java.util.Collections;
...
@@ -23,10 +23,10 @@ import java.util.Collections;
import
java.util.List
;
import
java.util.List
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.logging.DeferredLogFactory
;
import
org.springframework.boot.logging.DeferredLogFactory
;
...
@@ -45,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
...
@@ -45,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ConfigDataLocationResolversTests
{
class
ConfigDataLocationResolversTests
{
private
DeferredLogFactory
logFactory
=
Supplier:
:
get
;
private
DeferredLogFactory
logFactory
=
Supplier:
:
get
;
...
@@ -60,11 +61,6 @@ class ConfigDataLocationResolversTests {
...
@@ -60,11 +61,6 @@ class ConfigDataLocationResolversTests {
private
ResourceLoader
resourceLoader
=
new
DefaultResourceLoader
();
private
ResourceLoader
resourceLoader
=
new
DefaultResourceLoader
();
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
createWhenInjectingBinderCreatesResolver
()
{
void
createWhenInjectingBinderCreatesResolver
()
{
ConfigDataLocationResolvers
resolvers
=
new
ConfigDataLocationResolvers
(
this
.
logFactory
,
this
.
binder
,
ConfigDataLocationResolvers
resolvers
=
new
ConfigDataLocationResolvers
(
this
.
logFactory
,
this
.
binder
,
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindConverterTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -22,10 +22,10 @@ import java.time.Duration;
...
@@ -22,10 +22,10 @@ import java.time.Duration;
import
java.util.List
;
import
java.util.List
;
import
java.util.function.Consumer
;
import
java.util.function.Consumer
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.beans.PropertyEditorRegistry
;
import
org.springframework.beans.PropertyEditorRegistry
;
import
org.springframework.boot.convert.ApplicationConversionService
;
import
org.springframework.boot.convert.ApplicationConversionService
;
...
@@ -48,16 +48,12 @@ import static org.mockito.Mockito.verify;
...
@@ -48,16 +48,12 @@ import static org.mockito.Mockito.verify;
* @author Phillip Webb
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andy Wilkinson
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
BindConverterTests
{
class
BindConverterTests
{
@Mock
@Mock
private
Consumer
<
PropertyEditorRegistry
>
propertyEditorInitializer
;
private
Consumer
<
PropertyEditorRegistry
>
propertyEditorInitializer
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
createWhenConversionServiceIsNullShouldThrowException
()
{
void
createWhenConversionServiceIsNullShouldThrowException
()
{
assertThatIllegalArgumentException
().
isThrownBy
(()
->
BindConverter
.
get
(
null
,
null
))
assertThatIllegalArgumentException
().
isThrownBy
(()
->
BindConverter
.
get
(
null
,
null
))
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BindResultTests.java
View file @
969dd35e
...
@@ -22,10 +22,10 @@ import java.util.function.Consumer;
...
@@ -22,10 +22,10 @@ import java.util.function.Consumer;
import
java.util.function.Function
;
import
java.util.function.Function
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
...
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
...
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
* @author Phillip Webb
* @author Phillip Webb
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
BindResultTests
{
class
BindResultTests
{
@Mock
@Mock
...
@@ -52,11 +53,6 @@ class BindResultTests {
...
@@ -52,11 +53,6 @@ class BindResultTests {
@Mock
@Mock
private
Supplier
<
String
>
supplier
;
private
Supplier
<
String
>
supplier
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
getWhenHasValueShouldReturnValue
()
{
void
getWhenHasValueShouldReturnValue
()
{
BindResult
<
String
>
result
=
BindResult
.
of
(
"foo"
);
BindResult
<
String
>
result
=
BindResult
.
of
(
"foo"
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BoundPropertiesTrackingBindHandlerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -22,8 +22,9 @@ import java.util.function.Consumer;
...
@@ -22,8 +22,9 @@ import java.util.function.Consumer;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.context.properties.source.ConfigurationProperty
;
import
org.springframework.boot.context.properties.source.ConfigurationProperty
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySource
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySource
;
...
@@ -39,6 +40,7 @@ import static org.mockito.Mockito.verify;
...
@@ -39,6 +40,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Madhura Bhave
* @author Madhura Bhave
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
public
class
BoundPropertiesTrackingBindHandlerTests
{
public
class
BoundPropertiesTrackingBindHandlerTests
{
private
List
<
ConfigurationPropertySource
>
sources
=
new
ArrayList
<>();
private
List
<
ConfigurationPropertySource
>
sources
=
new
ArrayList
<>();
...
@@ -52,7 +54,6 @@ public class BoundPropertiesTrackingBindHandlerTests {
...
@@ -52,7 +54,6 @@ public class BoundPropertiesTrackingBindHandlerTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
binder
=
new
Binder
(
this
.
sources
);
this
.
binder
=
new
Binder
(
this
.
sources
);
this
.
handler
=
new
BoundPropertiesTrackingBindHandler
(
this
.
consumer
);
this
.
handler
=
new
BoundPropertiesTrackingBindHandler
(
this
.
consumer
);
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/DefaultPropertiesPropertySourceTests.java
View file @
969dd35e
...
@@ -19,12 +19,12 @@ package org.springframework.boot.env;
...
@@ -19,12 +19,12 @@ package org.springframework.boot.env;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.function.Consumer
;
import
java.util.function.Consumer
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.core.env.MutablePropertySources
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.core.env.PropertySource
;
...
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
...
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
DefaultPropertiesPropertySourceTests
{
class
DefaultPropertiesPropertySourceTests
{
@Mock
@Mock
...
@@ -48,11 +49,6 @@ class DefaultPropertiesPropertySourceTests {
...
@@ -48,11 +49,6 @@ class DefaultPropertiesPropertySourceTests {
@Captor
@Captor
private
ArgumentCaptor
<
DefaultPropertiesPropertySource
>
captor
;
private
ArgumentCaptor
<
DefaultPropertiesPropertySource
>
captor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
nameIsDefaultProperties
()
{
void
nameIsDefaultProperties
()
{
assertThat
(
DefaultPropertiesPropertySource
.
NAME
).
isEqualTo
(
"defaultProperties"
);
assertThat
(
DefaultPropertiesPropertySource
.
NAME
).
isEqualTo
(
"defaultProperties"
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/metadata/CompositeDataSourcePoolMetadataProviderTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -22,8 +22,9 @@ import javax.sql.DataSource;
...
@@ -22,8 +22,9 @@ import javax.sql.DataSource;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
...
@@ -33,6 +34,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -33,6 +34,7 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
CompositeDataSourcePoolMetadataProviderTests
{
class
CompositeDataSourcePoolMetadataProviderTests
{
@Mock
@Mock
...
@@ -58,7 +60,6 @@ class CompositeDataSourcePoolMetadataProviderTests {
...
@@ -58,7 +60,6 @@ class CompositeDataSourcePoolMetadataProviderTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
firstProvider
.
getDataSourcePoolMetadata
(
this
.
firstDataSource
)).
willReturn
(
this
.
first
);
given
(
this
.
firstProvider
.
getDataSourcePoolMetadata
(
this
.
firstDataSource
)).
willReturn
(
this
.
first
);
given
(
this
.
firstProvider
.
getDataSourcePoolMetadata
(
this
.
secondDataSource
)).
willReturn
(
this
.
second
);
given
(
this
.
firstProvider
.
getDataSourcePoolMetadata
(
this
.
secondDataSource
)).
willReturn
(
this
.
second
);
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RestTemplateBuilderTests.java
View file @
969dd35e
...
@@ -26,11 +26,11 @@ import java.util.Set;
...
@@ -26,11 +26,11 @@ import java.util.Set;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.config.RequestConfig
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.InOrder
;
import
org.mockito.InOrder
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpMethod
;
...
@@ -76,6 +76,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
...
@@ -76,6 +76,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* @author Kevin Strijbos
* @author Kevin Strijbos
* @author Ilya Lukyanovich
* @author Ilya Lukyanovich
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
RestTemplateBuilderTests
{
class
RestTemplateBuilderTests
{
private
RestTemplateBuilder
builder
=
new
RestTemplateBuilder
();
private
RestTemplateBuilder
builder
=
new
RestTemplateBuilder
();
...
@@ -86,11 +87,6 @@ class RestTemplateBuilderTests {
...
@@ -86,11 +87,6 @@ class RestTemplateBuilderTests {
@Mock
@Mock
private
ClientHttpRequestInterceptor
interceptor
;
private
ClientHttpRequestInterceptor
interceptor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
createWhenCustomizersAreNullShouldThrowException
()
{
void
createWhenCustomizersAreNullShouldThrowException
()
{
RestTemplateCustomizer
[]
customizers
=
null
;
RestTemplateCustomizer
[]
customizers
=
null
;
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/RootUriTemplateHandlerTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -23,8 +23,9 @@ import java.util.Map;
...
@@ -23,8 +23,9 @@ import java.util.Map;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.util.UriTemplateHandler
;
import
org.springframework.web.util.UriTemplateHandler
;
...
@@ -41,6 +42,7 @@ import static org.mockito.Mockito.verify;
...
@@ -41,6 +42,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
RootUriTemplateHandlerTests
{
class
RootUriTemplateHandlerTests
{
private
URI
uri
;
private
URI
uri
;
...
@@ -51,13 +53,9 @@ class RootUriTemplateHandlerTests {
...
@@ -51,13 +53,9 @@ class RootUriTemplateHandlerTests {
public
UriTemplateHandler
handler
;
public
UriTemplateHandler
handler
;
@BeforeEach
@BeforeEach
@SuppressWarnings
(
"unchecked"
)
void
setup
()
throws
URISyntaxException
{
void
setup
()
throws
URISyntaxException
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
uri
=
new
URI
(
"https://example.com/hello"
);
this
.
uri
=
new
URI
(
"https://example.com/hello"
);
this
.
handler
=
new
RootUriTemplateHandler
(
"https://example.com"
,
this
.
delegate
);
this
.
handler
=
new
RootUriTemplateHandler
(
"https://example.com"
,
this
.
delegate
);
given
(
this
.
delegate
.
expand
(
anyString
(),
any
(
Map
.
class
))).
willReturn
(
this
.
uri
);
given
(
this
.
delegate
.
expand
(
anyString
(),
any
(
Object
[].
class
))).
willReturn
(
this
.
uri
);
}
}
@Test
@Test
...
@@ -73,7 +71,9 @@ class RootUriTemplateHandlerTests {
...
@@ -73,7 +71,9 @@ class RootUriTemplateHandlerTests {
}
}
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
void
expandMapVariablesShouldPrefixRoot
()
{
void
expandMapVariablesShouldPrefixRoot
()
{
given
(
this
.
delegate
.
expand
(
anyString
(),
any
(
Map
.
class
))).
willReturn
(
this
.
uri
);
HashMap
<
String
,
Object
>
uriVariables
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
uriVariables
=
new
HashMap
<>();
URI
expanded
=
this
.
handler
.
expand
(
"/hello"
,
uriVariables
);
URI
expanded
=
this
.
handler
.
expand
(
"/hello"
,
uriVariables
);
verify
(
this
.
delegate
).
expand
(
"https://example.com/hello"
,
uriVariables
);
verify
(
this
.
delegate
).
expand
(
"https://example.com/hello"
,
uriVariables
);
...
@@ -81,7 +81,9 @@ class RootUriTemplateHandlerTests {
...
@@ -81,7 +81,9 @@ class RootUriTemplateHandlerTests {
}
}
@Test
@Test
@SuppressWarnings
(
"unchecked"
)
void
expandMapVariablesWhenPathDoesNotStartWithSlashShouldNotPrefixRoot
()
{
void
expandMapVariablesWhenPathDoesNotStartWithSlashShouldNotPrefixRoot
()
{
given
(
this
.
delegate
.
expand
(
anyString
(),
any
(
Map
.
class
))).
willReturn
(
this
.
uri
);
HashMap
<
String
,
Object
>
uriVariables
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
uriVariables
=
new
HashMap
<>();
URI
expanded
=
this
.
handler
.
expand
(
"https://spring.io/hello"
,
uriVariables
);
URI
expanded
=
this
.
handler
.
expand
(
"https://spring.io/hello"
,
uriVariables
);
verify
(
this
.
delegate
).
expand
(
"https://spring.io/hello"
,
uriVariables
);
verify
(
this
.
delegate
).
expand
(
"https://spring.io/hello"
,
uriVariables
);
...
@@ -90,6 +92,7 @@ class RootUriTemplateHandlerTests {
...
@@ -90,6 +92,7 @@ class RootUriTemplateHandlerTests {
@Test
@Test
void
expandArrayVariablesShouldPrefixRoot
()
{
void
expandArrayVariablesShouldPrefixRoot
()
{
given
(
this
.
delegate
.
expand
(
anyString
(),
any
(
Object
[].
class
))).
willReturn
(
this
.
uri
);
Object
[]
uriVariables
=
new
Object
[
0
];
Object
[]
uriVariables
=
new
Object
[
0
];
URI
expanded
=
this
.
handler
.
expand
(
"/hello"
,
uriVariables
);
URI
expanded
=
this
.
handler
.
expand
(
"/hello"
,
uriVariables
);
verify
(
this
.
delegate
).
expand
(
"https://example.com/hello"
,
uriVariables
);
verify
(
this
.
delegate
).
expand
(
"https://example.com/hello"
,
uriVariables
);
...
@@ -98,6 +101,7 @@ class RootUriTemplateHandlerTests {
...
@@ -98,6 +101,7 @@ class RootUriTemplateHandlerTests {
@Test
@Test
void
expandArrayVariablesWhenPathDoesNotStartWithSlashShouldNotPrefixRoot
()
{
void
expandArrayVariablesWhenPathDoesNotStartWithSlashShouldNotPrefixRoot
()
{
given
(
this
.
delegate
.
expand
(
anyString
(),
any
(
Object
[].
class
))).
willReturn
(
this
.
uri
);
Object
[]
uriVariables
=
new
Object
[
0
];
Object
[]
uriVariables
=
new
Object
[
0
];
URI
expanded
=
this
.
handler
.
expand
(
"https://spring.io/hello"
,
uriVariables
);
URI
expanded
=
this
.
handler
.
expand
(
"https://spring.io/hello"
,
uriVariables
);
verify
(
this
.
delegate
).
expand
(
"https://spring.io/hello"
,
uriVariables
);
verify
(
this
.
delegate
).
expand
(
"https://spring.io/hello"
,
uriVariables
);
...
@@ -106,6 +110,7 @@ class RootUriTemplateHandlerTests {
...
@@ -106,6 +110,7 @@ class RootUriTemplateHandlerTests {
@Test
@Test
void
applyShouldWrapExistingTemplate
()
{
void
applyShouldWrapExistingTemplate
()
{
given
(
this
.
delegate
.
expand
(
anyString
(),
any
(
Object
[].
class
))).
willReturn
(
this
.
uri
);
RestTemplate
restTemplate
=
new
RestTemplate
();
RestTemplate
restTemplate
=
new
RestTemplate
();
restTemplate
.
setUriTemplateHandler
(
this
.
delegate
);
restTemplate
.
setUriTemplateHandler
(
this
.
delegate
);
this
.
handler
=
RootUriTemplateHandler
.
addTo
(
restTemplate
,
"https://example.com"
);
this
.
handler
=
RootUriTemplateHandler
.
addTo
(
restTemplate
,
"https://example.com"
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/WebServerFactoryCustomizerBeanPostProcessorTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -17,15 +17,15 @@
...
@@ -17,15 +17,15 @@
package
org
.
springframework
.
boot
.
web
.
server
;
package
org
.
springframework
.
boot
.
web
.
server
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.ListableBeanFactory
;
import
org.springframework.beans.factory.ListableBeanFactory
;
...
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.mock;
...
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.mock;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
WebServerFactoryCustomizerBeanPostProcessorTests
{
class
WebServerFactoryCustomizerBeanPostProcessorTests
{
private
WebServerFactoryCustomizerBeanPostProcessor
processor
=
new
WebServerFactoryCustomizerBeanPostProcessor
();
private
WebServerFactoryCustomizerBeanPostProcessor
processor
=
new
WebServerFactoryCustomizerBeanPostProcessor
();
...
@@ -49,7 +50,6 @@ class WebServerFactoryCustomizerBeanPostProcessorTests {
...
@@ -49,7 +50,6 @@ class WebServerFactoryCustomizerBeanPostProcessorTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
processor
.
setBeanFactory
(
this
.
beanFactory
);
this
.
processor
.
setBeanFactory
(
this
.
beanFactory
);
}
}
...
@@ -62,7 +62,6 @@ class WebServerFactoryCustomizerBeanPostProcessorTests {
...
@@ -62,7 +62,6 @@ class WebServerFactoryCustomizerBeanPostProcessorTests {
@Test
@Test
void
postProcessBeforeShouldReturnBean
()
{
void
postProcessBeforeShouldReturnBean
()
{
addMockBeans
(
Collections
.
emptyMap
());
Object
bean
=
new
Object
();
Object
bean
=
new
Object
();
Object
result
=
this
.
processor
.
postProcessBeforeInitialization
(
bean
,
"foo"
);
Object
result
=
this
.
processor
.
postProcessBeforeInitialization
(
bean
,
"foo"
);
assertThat
(
result
).
isSameAs
(
bean
);
assertThat
(
result
).
isSameAs
(
bean
);
...
@@ -70,7 +69,6 @@ class WebServerFactoryCustomizerBeanPostProcessorTests {
...
@@ -70,7 +69,6 @@ class WebServerFactoryCustomizerBeanPostProcessorTests {
@Test
@Test
void
postProcessAfterShouldReturnBean
()
{
void
postProcessAfterShouldReturnBean
()
{
addMockBeans
(
Collections
.
emptyMap
());
Object
bean
=
new
Object
();
Object
bean
=
new
Object
();
Object
result
=
this
.
processor
.
postProcessAfterInitialization
(
bean
,
"foo"
);
Object
result
=
this
.
processor
.
postProcessAfterInitialization
(
bean
,
"foo"
);
assertThat
(
result
).
isSameAs
(
bean
);
assertThat
(
result
).
isSameAs
(
bean
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -28,10 +28,10 @@ import javax.servlet.Filter;
...
@@ -28,10 +28,10 @@ import javax.servlet.Filter;
import
javax.servlet.FilterRegistration
;
import
javax.servlet.FilterRegistration
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContext
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
...
@@ -46,6 +46,7 @@ import static org.mockito.Mockito.verify;
...
@@ -46,6 +46,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
abstract
class
AbstractFilterRegistrationBeanTests
{
abstract
class
AbstractFilterRegistrationBeanTests
{
@Mock
@Mock
...
@@ -54,14 +55,9 @@ abstract class AbstractFilterRegistrationBeanTests {
...
@@ -54,14 +55,9 @@ abstract class AbstractFilterRegistrationBeanTests {
@Mock
@Mock
FilterRegistration
.
Dynamic
registration
;
FilterRegistration
.
Dynamic
registration
;
@BeforeEach
void
setupMocks
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
registration
);
}
@Test
@Test
void
startupWithDefaults
()
throws
Exception
{
void
startupWithDefaults
()
throws
Exception
{
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
registration
);
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
bean
.
onStartup
(
this
.
servletContext
);
bean
.
onStartup
(
this
.
servletContext
);
verify
(
this
.
servletContext
).
addFilter
(
eq
(
"mockFilter"
),
getExpectedFilter
());
verify
(
this
.
servletContext
).
addFilter
(
eq
(
"mockFilter"
),
getExpectedFilter
());
...
@@ -71,6 +67,7 @@ abstract class AbstractFilterRegistrationBeanTests {
...
@@ -71,6 +67,7 @@ abstract class AbstractFilterRegistrationBeanTests {
@Test
@Test
void
startupWithSpecifiedValues
()
throws
Exception
{
void
startupWithSpecifiedValues
()
throws
Exception
{
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
registration
);
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
bean
.
setName
(
"test"
);
bean
.
setName
(
"test"
);
bean
.
setAsyncSupported
(
false
);
bean
.
setAsyncSupported
(
false
);
...
@@ -135,6 +132,7 @@ abstract class AbstractFilterRegistrationBeanTests {
...
@@ -135,6 +132,7 @@ abstract class AbstractFilterRegistrationBeanTests {
@Test
@Test
void
setServletRegistrationBeanReplacesValue
()
throws
Exception
{
void
setServletRegistrationBeanReplacesValue
()
throws
Exception
{
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
registration
);
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
(
mockServletRegistration
(
"a"
));
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
(
mockServletRegistration
(
"a"
));
bean
.
setServletRegistrationBeans
(
bean
.
setServletRegistrationBeans
(
new
LinkedHashSet
<
ServletRegistrationBean
<?>>(
Collections
.
singletonList
(
mockServletRegistration
(
"b"
))));
new
LinkedHashSet
<
ServletRegistrationBean
<?>>(
Collections
.
singletonList
(
mockServletRegistration
(
"b"
))));
...
@@ -144,6 +142,7 @@ abstract class AbstractFilterRegistrationBeanTests {
...
@@ -144,6 +142,7 @@ abstract class AbstractFilterRegistrationBeanTests {
@Test
@Test
void
modifyInitParameters
()
throws
Exception
{
void
modifyInitParameters
()
throws
Exception
{
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
registration
);
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
bean
.
addInitParameter
(
"a"
,
"b"
);
bean
.
addInitParameter
(
"a"
,
"b"
);
bean
.
getInitParameters
().
put
(
"a"
,
"c"
);
bean
.
getInitParameters
().
put
(
"a"
,
"c"
);
...
@@ -181,6 +180,7 @@ abstract class AbstractFilterRegistrationBeanTests {
...
@@ -181,6 +180,7 @@ abstract class AbstractFilterRegistrationBeanTests {
@Test
@Test
void
withSpecificDispatcherTypes
()
throws
Exception
{
void
withSpecificDispatcherTypes
()
throws
Exception
{
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
registration
);
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
bean
.
setDispatcherTypes
(
DispatcherType
.
INCLUDE
,
DispatcherType
.
FORWARD
);
bean
.
setDispatcherTypes
(
DispatcherType
.
INCLUDE
,
DispatcherType
.
FORWARD
);
bean
.
onStartup
(
this
.
servletContext
);
bean
.
onStartup
(
this
.
servletContext
);
...
@@ -190,6 +190,7 @@ abstract class AbstractFilterRegistrationBeanTests {
...
@@ -190,6 +190,7 @@ abstract class AbstractFilterRegistrationBeanTests {
@Test
@Test
void
withSpecificDispatcherTypesEnumSet
()
throws
Exception
{
void
withSpecificDispatcherTypesEnumSet
()
throws
Exception
{
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
registration
);
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
AbstractFilterRegistrationBean
<?>
bean
=
createFilterRegistrationBean
();
EnumSet
<
DispatcherType
>
types
=
EnumSet
.
of
(
DispatcherType
.
INCLUDE
,
DispatcherType
.
FORWARD
);
EnumSet
<
DispatcherType
>
types
=
EnumSet
.
of
(
DispatcherType
.
INCLUDE
,
DispatcherType
.
FORWARD
);
bean
.
setDispatcherTypes
(
types
);
bean
.
setDispatcherTypes
(
types
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationBeanTests.java
View file @
969dd35e
...
@@ -32,7 +32,10 @@ import org.springframework.boot.web.servlet.mock.MockFilter;
...
@@ -32,7 +32,10 @@ import org.springframework.boot.web.servlet.mock.MockFilter;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
org.springframework.web.filter.OncePerRequestFilter
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
/**
/**
...
@@ -84,6 +87,7 @@ class FilterRegistrationBeanTests extends AbstractFilterRegistrationBeanTests {
...
@@ -84,6 +87,7 @@ class FilterRegistrationBeanTests extends AbstractFilterRegistrationBeanTests {
@Test
@Test
void
startupWithOncePerRequestDefaults
()
throws
Exception
{
void
startupWithOncePerRequestDefaults
()
throws
Exception
{
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
registration
);
FilterRegistrationBean
<?>
bean
=
new
FilterRegistrationBean
<>(
this
.
oncePerRequestFilter
);
FilterRegistrationBean
<?>
bean
=
new
FilterRegistrationBean
<>(
this
.
oncePerRequestFilter
);
bean
.
onStartup
(
this
.
servletContext
);
bean
.
onStartup
(
this
.
servletContext
);
verify
(
this
.
servletContext
).
addFilter
(
eq
(
"oncePerRequestFilter"
),
eq
(
this
.
oncePerRequestFilter
));
verify
(
this
.
servletContext
).
addFilter
(
eq
(
"oncePerRequestFilter"
),
eq
(
this
.
oncePerRequestFilter
));
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletListenerRegistrationBeanTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -21,10 +21,10 @@ import java.util.EventListener;
...
@@ -21,10 +21,10 @@ import java.util.EventListener;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContextListener
;
import
javax.servlet.ServletContextListener
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegalArgumentException
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
...
@@ -36,6 +36,7 @@ import static org.mockito.Mockito.verify;
...
@@ -36,6 +36,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Dave Syer
* @author Dave Syer
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ServletListenerRegistrationBeanTests
{
class
ServletListenerRegistrationBeanTests
{
@Mock
@Mock
...
@@ -44,11 +45,6 @@ class ServletListenerRegistrationBeanTests {
...
@@ -44,11 +45,6 @@ class ServletListenerRegistrationBeanTests {
@Mock
@Mock
private
ServletContext
servletContext
;
private
ServletContext
servletContext
;
@BeforeEach
void
setupMocks
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
startupWithDefaults
()
throws
Exception
{
void
startupWithDefaults
()
throws
Exception
{
ServletListenerRegistrationBean
<
ServletContextListener
>
bean
=
new
ServletListenerRegistrationBean
<>(
ServletListenerRegistrationBean
<
ServletContextListener
>
bean
=
new
ServletListenerRegistrationBean
<>(
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletRegistrationBeanTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -22,16 +22,15 @@ import java.util.HashMap;
...
@@ -22,16 +22,15 @@ import java.util.HashMap;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterRegistration
;
import
javax.servlet.FilterRegistration
;
import
javax.servlet.Servlet
;
import
javax.servlet.Servlet
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletRegistration
;
import
javax.servlet.ServletRegistration
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.boot.web.servlet.mock.MockServlet
;
import
org.springframework.boot.web.servlet.mock.MockServlet
;
...
@@ -47,6 +46,7 @@ import static org.mockito.Mockito.verify;
...
@@ -47,6 +46,7 @@ import static org.mockito.Mockito.verify;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
ServletRegistrationBeanTests
{
class
ServletRegistrationBeanTests
{
private
final
MockServlet
servlet
=
new
MockServlet
();
private
final
MockServlet
servlet
=
new
MockServlet
();
...
@@ -60,15 +60,9 @@ class ServletRegistrationBeanTests {
...
@@ -60,15 +60,9 @@ class ServletRegistrationBeanTests {
@Mock
@Mock
private
FilterRegistration
.
Dynamic
filterRegistration
;
private
FilterRegistration
.
Dynamic
filterRegistration
;
@BeforeEach
void
setupMocks
()
{
MockitoAnnotations
.
initMocks
(
this
);
given
(
this
.
servletContext
.
addServlet
(
anyString
(),
any
(
Servlet
.
class
))).
willReturn
(
this
.
registration
);
given
(
this
.
servletContext
.
addFilter
(
anyString
(),
any
(
Filter
.
class
))).
willReturn
(
this
.
filterRegistration
);
}
@Test
@Test
void
startupWithDefaults
()
throws
Exception
{
void
startupWithDefaults
()
throws
Exception
{
given
(
this
.
servletContext
.
addServlet
(
anyString
(),
any
(
Servlet
.
class
))).
willReturn
(
this
.
registration
);
ServletRegistrationBean
<
MockServlet
>
bean
=
new
ServletRegistrationBean
<>(
this
.
servlet
);
ServletRegistrationBean
<
MockServlet
>
bean
=
new
ServletRegistrationBean
<>(
this
.
servlet
);
bean
.
onStartup
(
this
.
servletContext
);
bean
.
onStartup
(
this
.
servletContext
);
verify
(
this
.
servletContext
).
addServlet
(
"mockServlet"
,
this
.
servlet
);
verify
(
this
.
servletContext
).
addServlet
(
"mockServlet"
,
this
.
servlet
);
...
@@ -87,6 +81,7 @@ class ServletRegistrationBeanTests {
...
@@ -87,6 +81,7 @@ class ServletRegistrationBeanTests {
@Test
@Test
void
startupWithSpecifiedValues
()
throws
Exception
{
void
startupWithSpecifiedValues
()
throws
Exception
{
given
(
this
.
servletContext
.
addServlet
(
anyString
(),
any
(
Servlet
.
class
))).
willReturn
(
this
.
registration
);
ServletRegistrationBean
<
MockServlet
>
bean
=
new
ServletRegistrationBean
<>();
ServletRegistrationBean
<
MockServlet
>
bean
=
new
ServletRegistrationBean
<>();
bean
.
setName
(
"test"
);
bean
.
setName
(
"test"
);
bean
.
setServlet
(
this
.
servlet
);
bean
.
setServlet
(
this
.
servlet
);
...
@@ -169,6 +164,7 @@ class ServletRegistrationBeanTests {
...
@@ -169,6 +164,7 @@ class ServletRegistrationBeanTests {
@Test
@Test
void
setMappingReplacesValue
()
throws
Exception
{
void
setMappingReplacesValue
()
throws
Exception
{
given
(
this
.
servletContext
.
addServlet
(
anyString
(),
any
(
Servlet
.
class
))).
willReturn
(
this
.
registration
);
ServletRegistrationBean
<
MockServlet
>
bean
=
new
ServletRegistrationBean
<>(
this
.
servlet
,
"/a"
,
"/b"
);
ServletRegistrationBean
<
MockServlet
>
bean
=
new
ServletRegistrationBean
<>(
this
.
servlet
,
"/a"
,
"/b"
);
bean
.
setUrlMappings
(
new
LinkedHashSet
<>(
Arrays
.
asList
(
"/c"
,
"/d"
)));
bean
.
setUrlMappings
(
new
LinkedHashSet
<>(
Arrays
.
asList
(
"/c"
,
"/d"
)));
bean
.
onStartup
(
this
.
servletContext
);
bean
.
onStartup
(
this
.
servletContext
);
...
@@ -177,6 +173,7 @@ class ServletRegistrationBeanTests {
...
@@ -177,6 +173,7 @@ class ServletRegistrationBeanTests {
@Test
@Test
void
modifyInitParameters
()
throws
Exception
{
void
modifyInitParameters
()
throws
Exception
{
given
(
this
.
servletContext
.
addServlet
(
anyString
(),
any
(
Servlet
.
class
))).
willReturn
(
this
.
registration
);
ServletRegistrationBean
<
MockServlet
>
bean
=
new
ServletRegistrationBean
<>(
this
.
servlet
,
"/a"
,
"/b"
);
ServletRegistrationBean
<
MockServlet
>
bean
=
new
ServletRegistrationBean
<>(
this
.
servlet
,
"/a"
,
"/b"
);
bean
.
addInitParameter
(
"a"
,
"b"
);
bean
.
addInitParameter
(
"a"
,
"b"
);
bean
.
getInitParameters
().
put
(
"a"
,
"c"
);
bean
.
getInitParameters
().
put
(
"a"
,
"c"
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java
View file @
969dd35e
...
@@ -33,13 +33,12 @@ import javax.servlet.ServletRequest;
...
@@ -33,13 +33,12 @@ import javax.servlet.ServletRequest;
import
javax.servlet.ServletResponse
;
import
javax.servlet.ServletResponse
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.AfterEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Captor
;
import
org.mockito.InOrder
;
import
org.mockito.InOrder
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.beans.factory.BeanCreationException
;
...
@@ -94,20 +93,14 @@ import static org.mockito.Mockito.withSettings;
...
@@ -94,20 +93,14 @@ import static org.mockito.Mockito.withSettings;
* @author Phillip Webb
* @author Phillip Webb
* @author Stephane Nicoll
* @author Stephane Nicoll
*/
*/
@ExtendWith
(
OutputCaptureExtension
.
class
)
@ExtendWith
(
{
OutputCaptureExtension
.
class
,
MockitoExtension
.
class
}
)
class
ServletWebServerApplicationContextTests
{
class
ServletWebServerApplicationContextTests
{
private
ServletWebServerApplicationContext
context
;
private
ServletWebServerApplicationContext
context
=
new
ServletWebServerApplicationContext
()
;
@Captor
@Captor
private
ArgumentCaptor
<
Filter
>
filterCaptor
;
private
ArgumentCaptor
<
Filter
>
filterCaptor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
context
=
new
ServletWebServerApplicationContext
();
}
@AfterEach
@AfterEach
void
cleanup
()
{
void
cleanup
()
{
this
.
context
.
close
();
this
.
context
.
close
();
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/webservices/client/WebServiceTemplateBuilderTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -23,10 +23,10 @@ import java.util.Set;
...
@@ -23,10 +23,10 @@ import java.util.Set;
import
javax.xml.transform.sax.SAXTransformerFactory
;
import
javax.xml.transform.sax.SAXTransformerFactory
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
...
@@ -55,6 +55,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
...
@@ -55,6 +55,7 @@ import static org.mockito.Mockito.verifyNoInteractions;
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Dmytro Nosan
* @author Dmytro Nosan
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
WebServiceTemplateBuilderTests
{
class
WebServiceTemplateBuilderTests
{
private
final
WebServiceTemplateBuilder
builder
=
new
WebServiceTemplateBuilder
();
private
final
WebServiceTemplateBuilder
builder
=
new
WebServiceTemplateBuilder
();
...
@@ -65,11 +66,6 @@ class WebServiceTemplateBuilderTests {
...
@@ -65,11 +66,6 @@ class WebServiceTemplateBuilderTests {
@Mock
@Mock
private
ClientInterceptor
interceptor
;
private
ClientInterceptor
interceptor
;
@BeforeEach
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
}
@Test
@Test
void
createWithCustomizersShouldApplyCustomizers
()
{
void
createWithCustomizersShouldApplyCustomizers
()
{
WebServiceTemplateCustomizer
customizer
=
mock
(
WebServiceTemplateCustomizer
.
class
);
WebServiceTemplateCustomizer
customizer
=
mock
(
WebServiceTemplateCustomizer
.
class
);
...
...
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test/build.gradle
View file @
969dd35e
...
@@ -12,7 +12,8 @@ dependencies {
...
@@ -12,7 +12,8 @@ dependencies {
runtimeOnly
(
"com.h2database:h2"
)
runtimeOnly
(
"com.h2database:h2"
)
testImplementation
(
project
(
":spring-boot-project:spring-boot-starters:spring-boot-starter-test"
))
testImplementation
(
project
(
":spring-boot-project:spring-boot-starters:spring-boot-starter-test"
))
testImplementation
(
"net.sourceforge.htmlunit:htmlunit"
)
testImplementation
(
"org.mockito:mockito-junit-jupiter"
)
testImplementation
(
"org.seleniumhq.selenium:selenium-api"
)
testImplementation
(
"org.seleniumhq.selenium:selenium-api"
)
testImplementation
(
"org.seleniumhq.selenium:htmlunit-driver"
)
testImplementation
(
"org.seleniumhq.selenium:htmlunit-driver"
)
testImplementation
(
"net.sourceforge.htmlunit:htmlunit"
)
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-test/src/test/java/smoketest/test/web/UserVehicleServiceTests.java
View file @
969dd35e
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
@@ -18,8 +18,9 @@ package smoketest.test.web;
...
@@ -18,8 +18,9 @@ package smoketest.test.web;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
MockitoAnnotations
;
import
org.mockito.
junit.jupiter.MockitoExtension
;
import
smoketest.test.domain.User
;
import
smoketest.test.domain.User
;
import
smoketest.test.domain.UserRepository
;
import
smoketest.test.domain.UserRepository
;
import
smoketest.test.domain.VehicleIdentificationNumber
;
import
smoketest.test.domain.VehicleIdentificationNumber
;
...
@@ -37,6 +38,7 @@ import static org.mockito.BDDMockito.given;
...
@@ -37,6 +38,7 @@ import static org.mockito.BDDMockito.given;
*
*
* @author Phillip Webb
* @author Phillip Webb
*/
*/
@ExtendWith
(
MockitoExtension
.
class
)
class
UserVehicleServiceTests
{
class
UserVehicleServiceTests
{
private
static
final
VehicleIdentificationNumber
VIN
=
new
VehicleIdentificationNumber
(
"00000000000000000"
);
private
static
final
VehicleIdentificationNumber
VIN
=
new
VehicleIdentificationNumber
(
"00000000000000000"
);
...
@@ -51,7 +53,6 @@ class UserVehicleServiceTests {
...
@@ -51,7 +53,6 @@ class UserVehicleServiceTests {
@BeforeEach
@BeforeEach
void
setup
()
{
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
this
.
service
=
new
UserVehicleService
(
this
.
userRepository
,
this
.
vehicleDetailsService
);
this
.
service
=
new
UserVehicleService
(
this
.
userRepository
,
this
.
vehicleDetailsService
);
}
}
...
...
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