Skip to content

Commit 969dd35

Browse files
committed
Upgrade to Mockito 3.4.6
Closes gh-22838
1 parent f2a52a8 commit 969dd35

File tree

79 files changed

+444
-443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+444
-443
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ dependencies {
129129
testImplementation("org.hsqldb:hsqldb")
130130
testImplementation("org.junit.jupiter:junit-jupiter")
131131
testImplementation("org.mockito:mockito-core")
132+
testImplementation("org.mockito:mockito-junit-jupiter")
132133
testImplementation("org.skyscreamer:jsonassert")
133134
testImplementation("org.springframework:spring-orm")
134135
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,9 @@
1818

1919
import org.junit.jupiter.api.BeforeEach;
2020
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.extension.ExtendWith;
2122
import org.mockito.Mock;
22-
import org.mockito.MockitoAnnotations;
23+
import org.mockito.junit.jupiter.MockitoExtension;
2324
import reactor.core.publisher.Mono;
2425
import reactor.test.StepVerifier;
2526

@@ -41,6 +42,7 @@
4142
*
4243
* @author Madhura Bhave
4344
*/
45+
@ExtendWith(MockitoExtension.class)
4446
class ReactiveCloudFoundrySecurityInterceptorTests {
4547

4648
@Mock
@@ -53,7 +55,6 @@ class ReactiveCloudFoundrySecurityInterceptorTests {
5355

5456
@BeforeEach
5557
void setup() {
56-
MockitoAnnotations.initMocks(this);
5758
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, "my-app-id");
5859
}
5960

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveTokenValidatorTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,8 +31,9 @@
3131

3232
import org.junit.jupiter.api.BeforeEach;
3333
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.extension.ExtendWith;
3435
import org.mockito.Mock;
35-
import org.mockito.MockitoAnnotations;
36+
import org.mockito.junit.jupiter.MockitoExtension;
3637
import reactor.core.publisher.Mono;
3738
import reactor.test.StepVerifier;
3839
import reactor.test.publisher.PublisherProbe;
@@ -52,6 +53,7 @@
5253
*
5354
* @author Madhura Bhave
5455
*/
56+
@ExtendWith(MockitoExtension.class)
5557
class ReactiveTokenValidatorTests {
5658

5759
private static final byte[] DOT = ".".getBytes();
@@ -85,7 +87,6 @@ class ReactiveTokenValidatorTests {
8587

8688
@BeforeEach
8789
void setup() {
88-
MockitoAnnotations.initMocks(this);
8990
VALID_KEYS.put("valid-key", VALID_KEY);
9091
INVALID_KEYS.put("invalid-key", INVALID_KEY);
9192
this.tokenValidator = new ReactiveTokenValidator(this.securityService);
@@ -159,7 +160,6 @@ void validateTokenWhenCacheEmptyAndInvalidKeyShouldThrowException() throws Excep
159160
void validateTokenWhenCacheValidShouldNotFetchTokenKeys() throws Exception {
160161
PublisherProbe<Map<String, String>> fetchTokenKeys = PublisherProbe.empty();
161162
ReflectionTestUtils.setField(this.tokenValidator, "cachedTokenKeys", VALID_KEYS);
162-
given(this.securityService.fetchTokenKeys()).willReturn(fetchTokenKeys.mono());
163163
given(this.securityService.getUaaUrl()).willReturn(Mono.just("http://localhost:8080/uaa"));
164164
String header = "{\"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
165165
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,9 +18,10 @@
1818

1919
import org.junit.jupiter.api.BeforeEach;
2020
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.extension.ExtendWith;
2122
import org.mockito.ArgumentCaptor;
2223
import org.mockito.Mock;
23-
import org.mockito.MockitoAnnotations;
24+
import org.mockito.junit.jupiter.MockitoExtension;
2425

2526
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel;
2627
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason;
@@ -41,6 +42,7 @@
4142
*
4243
* @author Madhura Bhave
4344
*/
45+
@ExtendWith(MockitoExtension.class)
4446
class CloudFoundrySecurityInterceptorTests {
4547

4648
@Mock
@@ -55,7 +57,6 @@ class CloudFoundrySecurityInterceptorTests {
5557

5658
@BeforeEach
5759
void setup() {
58-
MockitoAnnotations.initMocks(this);
5960
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, "my-app-id");
6061
this.request = new MockHttpServletRequest();
6162
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/TokenValidatorTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,9 +31,10 @@
3131

3232
import org.junit.jupiter.api.BeforeEach;
3333
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.extension.ExtendWith;
3435
import org.mockito.Mock;
3536
import org.mockito.Mockito;
36-
import org.mockito.MockitoAnnotations;
37+
import org.mockito.junit.jupiter.MockitoExtension;
3738

3839
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException;
3940
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason;
@@ -52,6 +53,7 @@
5253
*
5354
* @author Madhura Bhave
5455
*/
56+
@ExtendWith(MockitoExtension.class)
5557
class TokenValidatorTests {
5658

5759
private static final byte[] DOT = ".".getBytes();
@@ -85,7 +87,6 @@ class TokenValidatorTests {
8587

8688
@BeforeEach
8789
void setup() {
88-
MockitoAnnotations.initMocks(this);
8990
this.tokenValidator = new TokenValidator(this.securityService);
9091
}
9192

@@ -135,7 +136,6 @@ void validateTokenWhenValidShouldNotFetchTokenKeys() throws Exception {
135136
void validateTokenWhenSignatureInvalidShouldThrowException() throws Exception {
136137
ReflectionTestUtils.setField(this.tokenValidator, "tokenKeys",
137138
Collections.singletonMap("valid-key", INVALID_KEY));
138-
given(this.securityService.getUaaUrl()).willReturn("http://localhost:8080/uaa");
139139
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
140140
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
141141
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(
@@ -145,7 +145,6 @@ void validateTokenWhenSignatureInvalidShouldThrowException() throws Exception {
145145

146146
@Test
147147
void validateTokenWhenTokenAlgorithmIsNotRS256ShouldThrowException() throws Exception {
148-
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
149148
String header = "{ \"alg\": \"HS256\", \"typ\": \"JWT\"}";
150149
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
151150
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/IncludeExcludeEndpointFilterTests.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.endpoint.expose;
1818

19-
import org.junit.jupiter.api.BeforeEach;
2019
import org.junit.jupiter.api.Test;
21-
import org.mockito.MockitoAnnotations;
20+
import org.junit.jupiter.api.extension.ExtendWith;
21+
import org.mockito.junit.jupiter.MockitoExtension;
2222

2323
import org.springframework.boot.actuate.endpoint.EndpointFilter;
2424
import org.springframework.boot.actuate.endpoint.EndpointId;
@@ -36,15 +36,11 @@
3636
*
3737
* @author Phillip Webb
3838
*/
39+
@ExtendWith(MockitoExtension.class)
3940
class IncludeExcludeEndpointFilterTests {
4041

4142
private IncludeExcludeEndpointFilter<?> filter;
4243

43-
@BeforeEach
44-
void setup() {
45-
MockitoAnnotations.initMocks(this);
46-
}
47-
4844
@Test
4945
void createWhenEndpointTypeIsNullShouldThrowException() {
5046
assertThatIllegalArgumentException()
@@ -123,7 +119,7 @@ void matchWhenDiscovererDoesNotMatchShouldMatch() {
123119
environment.setProperty("foo.include", "bar");
124120
environment.setProperty("foo.exclude", "");
125121
this.filter = new IncludeExcludeEndpointFilter<>(DifferentTestExposableWebEndpoint.class, environment, "foo");
126-
assertThat(match(EndpointId.of("baz"))).isTrue();
122+
assertThat(match()).isTrue();
127123
}
128124

129125
@Test
@@ -161,10 +157,16 @@ private void setupFilter(String include, String exclude) {
161157
this.filter = new IncludeExcludeEndpointFilter<>(TestExposableWebEndpoint.class, environment, "foo", "def");
162158
}
163159

160+
private boolean match() {
161+
return match(null);
162+
}
163+
164164
@SuppressWarnings({ "rawtypes", "unchecked" })
165165
private boolean match(EndpointId id) {
166166
ExposableEndpoint<?> endpoint = mock(TestExposableWebEndpoint.class);
167-
given(endpoint.getEndpointId()).willReturn(id);
167+
if (id != null) {
168+
given(endpoint.getEndpointId()).willReturn(id);
169+
}
168170
return ((EndpointFilter) this.filter).match(endpoint);
169171
}
170172

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroupTests.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import java.util.Arrays;
2121
import java.util.Collections;
2222

23-
import org.junit.jupiter.api.BeforeEach;
2423
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.extension.ExtendWith;
2525
import org.mockito.Mock;
26-
import org.mockito.MockitoAnnotations;
26+
import org.mockito.junit.jupiter.MockitoExtension;
2727

2828
import org.springframework.boot.actuate.autoconfigure.health.HealthProperties.Show;
2929
import org.springframework.boot.actuate.endpoint.SecurityContext;
@@ -41,6 +41,7 @@
4141
*
4242
* @author Phillip Webb
4343
*/
44+
@ExtendWith(MockitoExtension.class)
4445
class AutoConfiguredHealthEndpointGroupTests {
4546

4647
@Mock
@@ -55,11 +56,6 @@ class AutoConfiguredHealthEndpointGroupTests {
5556
@Mock
5657
private Principal principal;
5758

58-
@BeforeEach
59-
void setup() {
60-
MockitoAnnotations.initMocks(this);
61-
}
62-
6359
@Test
6460
void isMemberWhenMemberPredicateMatchesAcceptsTrue() {
6561
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> name.startsWith("a"),
@@ -112,17 +108,17 @@ void showDetailsWhenShowDetailsIsWhenAuthorizedAndUseIsInRoleReturnsTrue() {
112108
this.statusAggregator, this.httpCodeStatusMapper, null, Show.WHEN_AUTHORIZED,
113109
Arrays.asList("admin", "root", "bossmode"));
114110
given(this.securityContext.getPrincipal()).willReturn(this.principal);
111+
given(this.securityContext.isUserInRole("admin")).willReturn(false);
115112
given(this.securityContext.isUserInRole("root")).willReturn(true);
116113
assertThat(group.showDetails(this.securityContext)).isTrue();
117114
}
118115

119116
@Test
120-
void showDetailsWhenShowDetailsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse() {
117+
void showDetailsWhenShowDetailsIsWhenAuthorizedAndUserIsNotInRoleReturnsFalse() {
121118
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
122119
this.statusAggregator, this.httpCodeStatusMapper, null, Show.WHEN_AUTHORIZED,
123-
Arrays.asList("admin", "rot", "bossmode"));
120+
Arrays.asList("admin", "root", "bossmode"));
124121
given(this.securityContext.getPrincipal()).willReturn(this.principal);
125-
given(this.securityContext.isUserInRole("root")).willReturn(true);
126122
assertThat(group.showDetails(this.securityContext)).isFalse();
127123
}
128124

@@ -198,17 +194,17 @@ void showComponentsWhenShowComponentsIsWhenAuthorizedAndUseIsInRoleReturnsTrue()
198194
this.statusAggregator, this.httpCodeStatusMapper, Show.WHEN_AUTHORIZED, Show.NEVER,
199195
Arrays.asList("admin", "root", "bossmode"));
200196
given(this.securityContext.getPrincipal()).willReturn(this.principal);
197+
given(this.securityContext.isUserInRole("admin")).willReturn(false);
201198
given(this.securityContext.isUserInRole("root")).willReturn(true);
202199
assertThat(group.showComponents(this.securityContext)).isTrue();
203200
}
204201

205202
@Test
206-
void showComponentsWhenShowComponentsIsWhenAuthorizedAndUseIsNotInRoleReturnsFalse() {
203+
void showComponentsWhenShowComponentsIsWhenAuthorizedAndUserIsNotInRoleReturnsFalse() {
207204
AutoConfiguredHealthEndpointGroup group = new AutoConfiguredHealthEndpointGroup((name) -> true,
208205
this.statusAggregator, this.httpCodeStatusMapper, Show.WHEN_AUTHORIZED, Show.NEVER,
209206
Arrays.asList("admin", "rot", "bossmode"));
210207
given(this.securityContext.getPrincipal()).willReturn(this.principal);
211-
given(this.securityContext.isUserInRole("root")).willReturn(true);
212208
assertThat(group.showComponents(this.securityContext)).isFalse();
213209
}
214210

0 commit comments

Comments
 (0)