Migrate from ExpectedException rule to AssertJ
Replace ExpectedException JUnit rules with AssertJ exception assertions. Closes gh-14336
This commit is contained in:
parent
42cb0effc4
commit
d76bba5e6f
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2017 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.cloudfoundry;
|
|
||||||
|
|
||||||
import org.hamcrest.CustomMatcher;
|
|
||||||
import org.hamcrest.Matcher;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hamcrest matcher to check the {@link AuthorizationExceptionMatcher} {@link Reason}.
|
|
||||||
*
|
|
||||||
* @author Madhura Bhave
|
|
||||||
*/
|
|
||||||
public final class AuthorizationExceptionMatcher {
|
|
||||||
|
|
||||||
private AuthorizationExceptionMatcher() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Matcher<?> withReason(Reason reason) {
|
|
||||||
return new CustomMatcher<Object>(
|
|
||||||
"CloudFoundryAuthorizationException with " + reason + " reason") {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(Object object) {
|
|
||||||
return ((object instanceof CloudFoundryAuthorizationException)
|
|
||||||
&& ((CloudFoundryAuthorizationException) object)
|
|
||||||
.getReason() == reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -16,14 +16,15 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.cloudfoundry;
|
package org.springframework.boot.actuate.autoconfigure.cloudfoundry;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason;
|
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException.Reason;
|
||||||
import org.springframework.util.Base64Utils;
|
import org.springframework.util.Base64Utils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link Token}.
|
* Tests for {@link Token}.
|
||||||
|
@ -32,43 +33,40 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class TokenTests {
|
public class TokenTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidJwtShouldThrowException() {
|
public void invalidJwtShouldThrowException() {
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
.isThrownBy(() -> new Token("invalid-token"))
|
||||||
new Token("invalid-token");
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidJwtClaimsShouldThrowException() {
|
public void invalidJwtClaimsShouldThrowException() {
|
||||||
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
||||||
String claims = "invalid-claims";
|
String claims = "invalid-claims";
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
.isThrownBy(() -> new Token(Base64Utils.encodeToString(header.getBytes())
|
||||||
new Token(Base64Utils.encodeToString(header.getBytes()) + "."
|
+ "." + Base64Utils.encodeToString(claims.getBytes())))
|
||||||
+ Base64Utils.encodeToString(claims.getBytes()));
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidJwtHeaderShouldThrowException() {
|
public void invalidJwtHeaderShouldThrowException() {
|
||||||
String header = "invalid-header";
|
String header = "invalid-header";
|
||||||
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
.isThrownBy(() -> new Token(Base64Utils.encodeToString(header.getBytes())
|
||||||
new Token(Base64Utils.encodeToString(header.getBytes()) + "."
|
+ "." + Base64Utils.encodeToString(claims.getBytes())))
|
||||||
+ Base64Utils.encodeToString(claims.getBytes()));
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyJwtSignatureShouldThrowException() {
|
public void emptyJwtSignatureShouldThrowException() {
|
||||||
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0b3B0YWwu"
|
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0b3B0YWwu"
|
||||||
+ "Y29tIiwiZXhwIjoxNDI2NDIwODAwLCJhd2Vzb21lIjp0cnVlfQ.";
|
+ "Y29tIiwiZXhwIjoxNDI2NDIwODAwLCJhd2Vzb21lIjp0cnVlfQ.";
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
.isThrownBy(() -> new Token(token))
|
||||||
new Token(token);
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -93,9 +91,9 @@ public class TokenTests {
|
||||||
String header = "{\"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
String header = "{\"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
||||||
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
||||||
Token token = createToken(header, claims);
|
Token token = createToken(header, claims);
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
.isThrownBy(() -> token.getSignatureAlgorithm())
|
||||||
token.getSignatureAlgorithm();
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -103,9 +101,9 @@ public class TokenTests {
|
||||||
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
||||||
String claims = "{\"exp\": 2147483647}";
|
String claims = "{\"exp\": 2147483647}";
|
||||||
Token token = createToken(header, claims);
|
Token token = createToken(header, claims);
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
.isThrownBy(() -> token.getIssuer())
|
||||||
token.getIssuer();
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -113,9 +111,9 @@ public class TokenTests {
|
||||||
String header = "{\"alg\": \"RS256\", \"typ\": \"JWT\"}";
|
String header = "{\"alg\": \"RS256\", \"typ\": \"JWT\"}";
|
||||||
String claims = "{\"exp\": 2147483647}";
|
String claims = "{\"exp\": 2147483647}";
|
||||||
Token token = createToken(header, claims);
|
Token token = createToken(header, claims);
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
.isThrownBy(() -> token.getKeyId())
|
||||||
token.getKeyId();
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -123,9 +121,9 @@ public class TokenTests {
|
||||||
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
String header = "{\"alg\": \"RS256\", \"kid\": \"key-id\", \"typ\": \"JWT\"}";
|
||||||
String claims = "{\"iss\": \"http://localhost:8080/uaa/oauth/token\"" + "}";
|
String claims = "{\"iss\": \"http://localhost:8080/uaa/oauth/token\"" + "}";
|
||||||
Token token = createToken(header, claims);
|
Token token = createToken(header, claims);
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
.isThrownBy(() -> token.getExpiry())
|
||||||
token.getExpiry();
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Token createToken(String header, String claims) {
|
private Token createToken(String header, String claims) {
|
||||||
|
@ -135,4 +133,9 @@ public class TokenTests {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Consumer<CloudFoundryAuthorizationException> reasonRequirement(
|
||||||
|
Reason reason) {
|
||||||
|
return (ex) -> assertThat(ex.getReason()).isEqualTo(reason);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,7 @@ import java.util.stream.Collectors;
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import reactor.netty.http.HttpResources;
|
import reactor.netty.http.HttpResources;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
||||||
|
@ -65,7 +63,7 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,9 +73,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class ReactiveCloudFoundryActuatorAutoConfigurationTests {
|
public class ReactiveCloudFoundryActuatorAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
|
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(
|
.withConfiguration(AutoConfigurations.of(
|
||||||
ReactiveSecurityAutoConfiguration.class,
|
ReactiveSecurityAutoConfiguration.class,
|
||||||
|
@ -335,9 +330,11 @@ public class ReactiveCloudFoundryActuatorAutoConfigurationTests {
|
||||||
.getField(interceptor, "cloudFoundrySecurityService");
|
.getField(interceptor, "cloudFoundrySecurityService");
|
||||||
WebClient webClient = (WebClient) ReflectionTestUtils
|
WebClient webClient = (WebClient) ReflectionTestUtils
|
||||||
.getField(interceptorSecurityService, "webClient");
|
.getField(interceptorSecurityService, "webClient");
|
||||||
this.thrown.expectCause(instanceOf(SSLException.class));
|
assertThatExceptionOfType(RuntimeException.class)
|
||||||
webClient.get().uri("https://self-signed.badssl.com/").exchange()
|
.isThrownBy(
|
||||||
.block();
|
webClient.get().uri("https://self-signed.badssl.com/")
|
||||||
|
.exchange()::block)
|
||||||
|
.withCauseInstanceOf(SSLException.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,14 +17,13 @@
|
||||||
package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
|
package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel;
|
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel;
|
||||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AuthorizationExceptionMatcher;
|
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;
|
||||||
import org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer;
|
import org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer;
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||||
|
@ -35,6 +34,7 @@ import org.springframework.test.web.client.MockRestServiceServer;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
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.springframework.test.web.client.match.MockRestRequestMatchers.header;
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
|
||||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError;
|
import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError;
|
||||||
|
@ -49,9 +49,6 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||||
*/
|
*/
|
||||||
public class CloudFoundrySecurityServiceTests {
|
public class CloudFoundrySecurityServiceTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private static final String CLOUD_CONTROLLER = "http://my-cloud-controller.com";
|
private static final String CLOUD_CONTROLLER = "http://my-cloud-controller.com";
|
||||||
|
|
||||||
private static final String CLOUD_CONTROLLER_PERMISSIONS = CLOUD_CONTROLLER
|
private static final String CLOUD_CONTROLLER_PERMISSIONS = CLOUD_CONTROLLER
|
||||||
|
@ -123,9 +120,9 @@ public class CloudFoundrySecurityServiceTests {
|
||||||
this.server.expect(requestTo(CLOUD_CONTROLLER_PERMISSIONS))
|
this.server.expect(requestTo(CLOUD_CONTROLLER_PERMISSIONS))
|
||||||
.andExpect(header("Authorization", "bearer my-access-token"))
|
.andExpect(header("Authorization", "bearer my-access-token"))
|
||||||
.andRespond(withUnauthorizedRequest());
|
.andRespond(withUnauthorizedRequest());
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_TOKEN));
|
() -> this.securityService.getAccessLevel("my-access-token", "my-app-id"))
|
||||||
this.securityService.getAccessLevel("my-access-token", "my-app-id");
|
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -133,9 +130,9 @@ public class CloudFoundrySecurityServiceTests {
|
||||||
this.server.expect(requestTo(CLOUD_CONTROLLER_PERMISSIONS))
|
this.server.expect(requestTo(CLOUD_CONTROLLER_PERMISSIONS))
|
||||||
.andExpect(header("Authorization", "bearer my-access-token"))
|
.andExpect(header("Authorization", "bearer my-access-token"))
|
||||||
.andRespond(withStatus(HttpStatus.FORBIDDEN));
|
.andRespond(withStatus(HttpStatus.FORBIDDEN));
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.ACCESS_DENIED));
|
() -> this.securityService.getAccessLevel("my-access-token", "my-app-id"))
|
||||||
this.securityService.getAccessLevel("my-access-token", "my-app-id");
|
.satisfies(reasonRequirement(Reason.ACCESS_DENIED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -143,9 +140,9 @@ public class CloudFoundrySecurityServiceTests {
|
||||||
this.server.expect(requestTo(CLOUD_CONTROLLER_PERMISSIONS))
|
this.server.expect(requestTo(CLOUD_CONTROLLER_PERMISSIONS))
|
||||||
.andExpect(header("Authorization", "bearer my-access-token"))
|
.andExpect(header("Authorization", "bearer my-access-token"))
|
||||||
.andRespond(withServerError());
|
.andRespond(withServerError());
|
||||||
this.thrown.expect(
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class).isThrownBy(
|
||||||
AuthorizationExceptionMatcher.withReason(Reason.SERVICE_UNAVAILABLE));
|
() -> this.securityService.getAccessLevel("my-access-token", "my-app-id"))
|
||||||
this.securityService.getAccessLevel("my-access-token", "my-app-id");
|
.satisfies(reasonRequirement(Reason.SERVICE_UNAVAILABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -188,9 +185,9 @@ public class CloudFoundrySecurityServiceTests {
|
||||||
"{\"token_endpoint\":\"" + UAA_URL + "\"}", MediaType.APPLICATION_JSON));
|
"{\"token_endpoint\":\"" + UAA_URL + "\"}", MediaType.APPLICATION_JSON));
|
||||||
this.server.expect(requestTo(UAA_URL + "/token_keys"))
|
this.server.expect(requestTo(UAA_URL + "/token_keys"))
|
||||||
.andRespond(withServerError());
|
.andRespond(withServerError());
|
||||||
this.thrown.expect(
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
AuthorizationExceptionMatcher.withReason(Reason.SERVICE_UNAVAILABLE));
|
.isThrownBy(() -> this.securityService.fetchTokenKeys())
|
||||||
this.securityService.fetchTokenKeys();
|
.satisfies(reasonRequirement(Reason.SERVICE_UNAVAILABLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -209,9 +206,14 @@ public class CloudFoundrySecurityServiceTests {
|
||||||
public void getUaaUrlWhenCloudControllerUrlIsNotReachableShouldThrowException() {
|
public void getUaaUrlWhenCloudControllerUrlIsNotReachableShouldThrowException() {
|
||||||
this.server.expect(requestTo(CLOUD_CONTROLLER + "/info"))
|
this.server.expect(requestTo(CLOUD_CONTROLLER + "/info"))
|
||||||
.andRespond(withServerError());
|
.andRespond(withServerError());
|
||||||
this.thrown.expect(
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
AuthorizationExceptionMatcher.withReason(Reason.SERVICE_UNAVAILABLE));
|
.isThrownBy(() -> this.securityService.getUaaUrl())
|
||||||
this.securityService.getUaaUrl();
|
.satisfies(reasonRequirement(Reason.SERVICE_UNAVAILABLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Consumer<CloudFoundryAuthorizationException> reasonRequirement(
|
||||||
|
Reason reason) {
|
||||||
|
return (ex) -> assertThat(ex.getReason()).isEqualTo(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,11 +18,8 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
|
||||||
|
|
||||||
import javax.net.ssl.SSLHandshakeException;
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
|
|
||||||
import org.hamcrest.Matcher;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.testsupport.web.servlet.ExampleServlet;
|
import org.springframework.boot.testsupport.web.servlet.ExampleServlet;
|
||||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||||
|
@ -35,16 +32,13 @@ import org.springframework.web.client.ResourceAccessException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link SkipSslVerificationHttpRequestFactory}.
|
* Test for {@link SkipSslVerificationHttpRequestFactory}.
|
||||||
*/
|
*/
|
||||||
public class SkipSslVerificationHttpRequestFactoryTests {
|
public class SkipSslVerificationHttpRequestFactoryTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private WebServer webServer;
|
private WebServer webServer;
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -59,17 +53,13 @@ public class SkipSslVerificationHttpRequestFactoryTests {
|
||||||
String httpsUrl = getHttpsUrl();
|
String httpsUrl = getHttpsUrl();
|
||||||
SkipSslVerificationHttpRequestFactory requestFactory = new SkipSslVerificationHttpRequestFactory();
|
SkipSslVerificationHttpRequestFactory requestFactory = new SkipSslVerificationHttpRequestFactory();
|
||||||
RestTemplate restTemplate = new RestTemplate(requestFactory);
|
RestTemplate restTemplate = new RestTemplate(requestFactory);
|
||||||
|
RestTemplate otherRestTemplate = new RestTemplate();
|
||||||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(httpsUrl,
|
ResponseEntity<String> responseEntity = restTemplate.getForEntity(httpsUrl,
|
||||||
String.class);
|
String.class);
|
||||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
this.thrown.expect(ResourceAccessException.class);
|
assertThatExceptionOfType(ResourceAccessException.class)
|
||||||
this.thrown.expectCause(isSSLHandshakeException());
|
.isThrownBy(() -> otherRestTemplate.getForEntity(httpsUrl, String.class))
|
||||||
RestTemplate otherRestTemplate = new RestTemplate();
|
.withCauseInstanceOf(SSLHandshakeException.class);
|
||||||
otherRestTemplate.getForEntity(httpsUrl, String.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Matcher<Throwable> isSSLHandshakeException() {
|
|
||||||
return instanceOf(SSLHandshakeException.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHttpsUrl() {
|
private String getHttpsUrl() {
|
||||||
|
|
|
@ -27,22 +27,23 @@ import java.security.spec.InvalidKeySpecException;
|
||||||
import java.security.spec.PKCS8EncodedKeySpec;
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AuthorizationExceptionMatcher;
|
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;
|
||||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.Token;
|
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.Token;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.springframework.util.Base64Utils;
|
import org.springframework.util.Base64Utils;
|
||||||
import org.springframework.util.StreamUtils;
|
import org.springframework.util.StreamUtils;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
@ -55,9 +56,6 @@ public class TokenValidatorTests {
|
||||||
|
|
||||||
private static final byte[] DOT = ".".getBytes();
|
private static final byte[] DOT = ".".getBytes();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private CloudFoundrySecurityService securityService;
|
private CloudFoundrySecurityService securityService;
|
||||||
|
|
||||||
|
@ -100,10 +98,10 @@ public class TokenValidatorTests {
|
||||||
given(this.securityService.fetchTokenKeys()).willReturn(INVALID_KEYS);
|
given(this.securityService.fetchTokenKeys()).willReturn(INVALID_KEYS);
|
||||||
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\"]}";
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_KEY_ID));
|
.isThrownBy(() -> this.tokenValidator.validate(
|
||||||
this.tokenValidator.validate(
|
new Token(getSignedToken(header.getBytes(), claims.getBytes()))))
|
||||||
new Token(getSignedToken(header.getBytes(), claims.getBytes())));
|
.satisfies(reasonRequirement(Reason.INVALID_KEY_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -148,10 +146,10 @@ public class TokenValidatorTests {
|
||||||
given(this.securityService.getUaaUrl()).willReturn("http://localhost:8080/uaa");
|
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\"]}";
|
||||||
this.thrown.expect(
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
AuthorizationExceptionMatcher.withReason(Reason.INVALID_SIGNATURE));
|
.isThrownBy(() -> this.tokenValidator.validate(
|
||||||
this.tokenValidator.validate(
|
new Token(getSignedToken(header.getBytes(), claims.getBytes()))))
|
||||||
new Token(getSignedToken(header.getBytes(), claims.getBytes())));
|
.satisfies(reasonRequirement(Reason.INVALID_SIGNATURE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -160,10 +158,10 @@ public class TokenValidatorTests {
|
||||||
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
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\"]}";
|
||||||
this.thrown.expect(AuthorizationExceptionMatcher
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.withReason(Reason.UNSUPPORTED_TOKEN_SIGNING_ALGORITHM));
|
.isThrownBy(() -> this.tokenValidator.validate(
|
||||||
this.tokenValidator.validate(
|
new Token(getSignedToken(header.getBytes(), claims.getBytes()))))
|
||||||
new Token(getSignedToken(header.getBytes(), claims.getBytes())));
|
.satisfies(reasonRequirement(Reason.UNSUPPORTED_TOKEN_SIGNING_ALGORITHM));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -172,10 +170,10 @@ public class TokenValidatorTests {
|
||||||
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
given(this.securityService.fetchTokenKeys()).willReturn(VALID_KEYS);
|
||||||
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\"}";
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\"}";
|
||||||
String claims = "{ \"jti\": \"0236399c350c47f3ae77e67a75e75e7d\", \"exp\": 1477509977, \"scope\": [\"actuator.read\"]}";
|
String claims = "{ \"jti\": \"0236399c350c47f3ae77e67a75e75e7d\", \"exp\": 1477509977, \"scope\": [\"actuator.read\"]}";
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.TOKEN_EXPIRED));
|
.isThrownBy(() -> this.tokenValidator.validate(
|
||||||
this.tokenValidator.validate(
|
new Token(getSignedToken(header.getBytes(), claims.getBytes()))))
|
||||||
new Token(getSignedToken(header.getBytes(), claims.getBytes())));
|
.satisfies(reasonRequirement(Reason.TOKEN_EXPIRED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -184,10 +182,10 @@ public class TokenValidatorTests {
|
||||||
given(this.securityService.getUaaUrl()).willReturn("http://other-uaa.com");
|
given(this.securityService.getUaaUrl()).willReturn("http://other-uaa.com");
|
||||||
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\", \"scope\": [\"actuator.read\"]}";
|
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\", \"typ\": \"JWT\", \"scope\": [\"actuator.read\"]}";
|
||||||
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
|
||||||
this.thrown
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
.expect(AuthorizationExceptionMatcher.withReason(Reason.INVALID_ISSUER));
|
.isThrownBy(() -> this.tokenValidator.validate(
|
||||||
this.tokenValidator.validate(
|
new Token(getSignedToken(header.getBytes(), claims.getBytes()))))
|
||||||
new Token(getSignedToken(header.getBytes(), claims.getBytes())));
|
.satisfies(reasonRequirement(Reason.INVALID_ISSUER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -197,10 +195,10 @@ public class TokenValidatorTests {
|
||||||
given(this.securityService.getUaaUrl()).willReturn("http://localhost:8080/uaa");
|
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\": [\"foo.bar\"]}";
|
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"foo.bar\"]}";
|
||||||
this.thrown.expect(
|
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
|
||||||
AuthorizationExceptionMatcher.withReason(Reason.INVALID_AUDIENCE));
|
.isThrownBy(() -> this.tokenValidator.validate(
|
||||||
this.tokenValidator.validate(
|
new Token(getSignedToken(header.getBytes(), claims.getBytes()))))
|
||||||
new Token(getSignedToken(header.getBytes(), claims.getBytes())));
|
.satisfies(reasonRequirement(Reason.INVALID_AUDIENCE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSignedToken(byte[] header, byte[] claims) throws Exception {
|
private String getSignedToken(byte[] header, byte[] claims) throws Exception {
|
||||||
|
@ -265,4 +263,9 @@ public class TokenValidatorTests {
|
||||||
return result.toByteArray();
|
return result.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Consumer<CloudFoundryAuthorizationException> reasonRequirement(
|
||||||
|
Reason reason) {
|
||||||
|
return (ex) -> assertThat(ex.getReason()).isEqualTo(reason);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
package org.springframework.boot.actuate.autoconfigure.endpoint;
|
package org.springframework.boot.actuate.autoconfigure.endpoint;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.EndpointFilter;
|
import org.springframework.boot.actuate.endpoint.EndpointFilter;
|
||||||
|
@ -28,6 +26,7 @@ import org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -38,9 +37,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class ExposeExcludePropertyEndpointFilterTests {
|
public class ExposeExcludePropertyEndpointFilterTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private ExposeExcludePropertyEndpointFilter<?> filter;
|
private ExposeExcludePropertyEndpointFilter<?> filter;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -50,32 +46,34 @@ public class ExposeExcludePropertyEndpointFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenEndpointTypeIsNullShouldThrowException() {
|
public void createWhenEndpointTypeIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("EndpointType must not be null");
|
.isThrownBy(() -> new ExposeExcludePropertyEndpointFilter<>(null,
|
||||||
new ExposeExcludePropertyEndpointFilter<>(null, new MockEnvironment(), "foo");
|
new MockEnvironment(), "foo"))
|
||||||
|
.withMessageContaining("EndpointType must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenEnvironmentIsNullShouldThrowException() {
|
public void createWhenEnvironmentIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Environment must not be null");
|
.isThrownBy(() -> new ExposeExcludePropertyEndpointFilter<>(
|
||||||
new ExposeExcludePropertyEndpointFilter<>(ExposableEndpoint.class, null, "foo");
|
ExposableEndpoint.class, null, "foo"))
|
||||||
|
.withMessageContaining("Environment must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenPrefixIsNullShouldThrowException() {
|
public void createWhenPrefixIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Prefix must not be empty");
|
.isThrownBy(() -> new ExposeExcludePropertyEndpointFilter<>(
|
||||||
new ExposeExcludePropertyEndpointFilter<>(ExposableEndpoint.class,
|
ExposableEndpoint.class, new MockEnvironment(), null))
|
||||||
new MockEnvironment(), null);
|
.withMessageContaining("Prefix must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenPrefixIsEmptyShouldThrowException() {
|
public void createWhenPrefixIsEmptyShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Prefix must not be empty");
|
.isThrownBy(() -> new ExposeExcludePropertyEndpointFilter<>(
|
||||||
new ExposeExcludePropertyEndpointFilter<>(ExposableEndpoint.class,
|
ExposableEndpoint.class, new MockEnvironment(), ""))
|
||||||
new MockEnvironment(), "");
|
.withMessageContaining("Prefix must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,15 +22,14 @@ import javax.management.MBeanServer;
|
||||||
import javax.management.MalformedObjectNameException;
|
import javax.management.MalformedObjectNameException;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint;
|
import org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -41,9 +40,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class DefaultEndpointObjectNameFactoryTests {
|
public class DefaultEndpointObjectNameFactoryTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final MockEnvironment environment = new MockEnvironment();
|
private final MockEnvironment environment = new MockEnvironment();
|
||||||
|
|
||||||
private final JmxEndpointProperties properties = new JmxEndpointProperties(
|
private final JmxEndpointProperties properties = new JmxEndpointProperties(
|
||||||
|
@ -101,10 +97,10 @@ public class DefaultEndpointObjectNameFactoryTests {
|
||||||
public void generateObjectNameWithUniqueNamesDeprecatedPropertyMismatchMainProperty() {
|
public void generateObjectNameWithUniqueNamesDeprecatedPropertyMismatchMainProperty() {
|
||||||
this.environment.setProperty("spring.jmx.unique-names", "false");
|
this.environment.setProperty("spring.jmx.unique-names", "false");
|
||||||
this.properties.setUniqueNames(true);
|
this.properties.setUniqueNames(true);
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("spring.jmx.unique-names");
|
.isThrownBy(() -> generateObjectName(endpoint("test")))
|
||||||
this.thrown.expectMessage("management.endpoints.jmx.unique-names");
|
.withMessageContaining("spring.jmx.unique-names")
|
||||||
generateObjectName(endpoint("test"));
|
.withMessageContaining("management.endpoints.jmx.unique-names");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.endpoint.web;
|
package org.springframework.boot.actuate.autoconfigure.endpoint.web;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link WebEndpointProperties}.
|
* Tests for {@link WebEndpointProperties}.
|
||||||
|
@ -29,9 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class WebEndpointPropertiesTests {
|
public class WebEndpointPropertiesTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultBasePathShouldBeApplication() {
|
public void defaultBasePathShouldBeApplication() {
|
||||||
WebEndpointProperties properties = new WebEndpointProperties();
|
WebEndpointProperties properties = new WebEndpointProperties();
|
||||||
|
@ -50,9 +46,9 @@ public class WebEndpointPropertiesTests {
|
||||||
@Test
|
@Test
|
||||||
public void basePathMustStartWithSlash() {
|
public void basePathMustStartWithSlash() {
|
||||||
WebEndpointProperties properties = new WebEndpointProperties();
|
WebEndpointProperties properties = new WebEndpointProperties();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Base path must start with '/' or be empty");
|
.isThrownBy(() -> properties.setBasePath("admin"))
|
||||||
properties.setBasePath("admin");
|
.withMessageContaining("Base path must start with '/' or be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -25,9 +25,7 @@ import io.micrometer.core.instrument.config.MeterFilterReply;
|
||||||
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
|
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
|
||||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@ -37,6 +35,7 @@ import org.springframework.boot.test.util.TestPropertyValues;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link PropertiesMeterFilter}.
|
* Tests for {@link PropertiesMeterFilter}.
|
||||||
|
@ -46,9 +45,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class PropertiesMeterFilterTests {
|
public class PropertiesMeterFilterTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private DistributionStatisticConfig config;
|
private DistributionStatisticConfig config;
|
||||||
|
|
||||||
|
@ -59,9 +55,9 @@ public class PropertiesMeterFilterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenPropertiesIsNullShouldThrowException() {
|
public void createWhenPropertiesIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Properties must not be null");
|
.isThrownBy(() -> new PropertiesMeterFilter(null))
|
||||||
new PropertiesMeterFilter(null);
|
.withMessageContaining("Properties must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +21,7 @@ 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.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@ -33,6 +31,7 @@ import org.springframework.boot.actuate.health.Health;
|
||||||
import org.springframework.boot.actuate.health.Status;
|
import org.springframework.boot.actuate.health.Status;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
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.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -44,9 +43,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class RabbitHealthIndicatorTests {
|
public class RabbitHealthIndicatorTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private RabbitTemplate rabbitTemplate;
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@ -64,9 +60,9 @@ public class RabbitHealthIndicatorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenRabbitTemplateIsNullShouldThrowException() {
|
public void createWhenRabbitTemplateIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("RabbitTemplate must not be null");
|
.isThrownBy(() -> new RabbitHealthIndicator(null))
|
||||||
new RabbitHealthIndicator(null);
|
.withMessageContaining("RabbitTemplate must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,13 +19,12 @@ package org.springframework.boot.actuate.audit;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link AuditEvent}.
|
* Tests for {@link AuditEvent}.
|
||||||
|
@ -35,9 +34,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class AuditEventTests {
|
public class AuditEventTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nowEvent() {
|
public void nowEvent() {
|
||||||
AuditEvent event = new AuditEvent("phil", "UNKNOWN",
|
AuditEvent event = new AuditEvent("phil", "UNKNOWN",
|
||||||
|
@ -64,17 +60,18 @@ public class AuditEventTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullTimestamp() {
|
public void nullTimestamp() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Timestamp must not be null");
|
.isThrownBy(() -> new AuditEvent(null, "phil", "UNKNOWN",
|
||||||
new AuditEvent(null, "phil", "UNKNOWN",
|
Collections.singletonMap("a", (Object) "b")))
|
||||||
Collections.singletonMap("a", (Object) "b"));
|
.withMessageContaining("Timestamp must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullType() {
|
public void nullType() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Type must not be null");
|
.isThrownBy(() -> new AuditEvent("phil", null,
|
||||||
new AuditEvent("phil", null, Collections.singletonMap("a", (Object) "b"));
|
Collections.singletonMap("a", (Object) "b")))
|
||||||
|
.withMessageContaining("Type must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,11 +22,10 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link InMemoryAuditEventRepository}.
|
* Tests for {@link InMemoryAuditEventRepository}.
|
||||||
|
@ -37,9 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class InMemoryAuditEventRepositoryTests {
|
public class InMemoryAuditEventRepositoryTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lessThanCapacity() {
|
public void lessThanCapacity() {
|
||||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||||
|
@ -65,10 +61,9 @@ public class InMemoryAuditEventRepositoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addNullAuditEvent() {
|
public void addNullAuditEvent() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
|
||||||
this.thrown.expectMessage("AuditEvent must not be null");
|
|
||||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||||
repository.add(null);
|
assertThatIllegalArgumentException().isThrownBy(() -> repository.add(null))
|
||||||
|
.withMessageContaining("AuditEvent must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,9 +22,7 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry;
|
import org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry;
|
||||||
import org.springframework.boot.actuate.cache.CachesEndpoint.CacheManagerDescriptor;
|
import org.springframework.boot.actuate.cache.CachesEndpoint.CacheManagerDescriptor;
|
||||||
|
@ -34,6 +32,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||||
import org.springframework.cache.support.SimpleCacheManager;
|
import org.springframework.cache.support.SimpleCacheManager;
|
||||||
|
|
||||||
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.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
@ -46,9 +45,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class CachesEndpointTests {
|
public class CachesEndpointTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allCachesWithSingleCacheManager() {
|
public void allCachesWithSingleCacheManager() {
|
||||||
CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test",
|
CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test",
|
||||||
|
@ -94,11 +90,10 @@ public class CachesEndpointTests {
|
||||||
cacheManagers.put("test", new ConcurrentMapCacheManager("b", "dupe-cache"));
|
cacheManagers.put("test", new ConcurrentMapCacheManager("b", "dupe-cache"));
|
||||||
cacheManagers.put("another", new ConcurrentMapCacheManager("c", "dupe-cache"));
|
cacheManagers.put("another", new ConcurrentMapCacheManager("c", "dupe-cache"));
|
||||||
CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
|
CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
|
||||||
this.thrown.expect(NonUniqueCacheException.class);
|
assertThatExceptionOfType(NonUniqueCacheException.class)
|
||||||
this.thrown.expectMessage("dupe-cache");
|
.isThrownBy(() -> endpoint.cache("dupe-cache", null))
|
||||||
this.thrown.expectMessage("test");
|
.withMessageContaining("dupe-cache").withMessageContaining("test")
|
||||||
this.thrown.expectMessage("another");
|
.withMessageContaining("another");
|
||||||
endpoint.cache("dupe-cache", null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -159,11 +154,10 @@ public class CachesEndpointTests {
|
||||||
cacheManagers.put("test", cacheManager(mockCache("dupe-cache"), mockCache("b")));
|
cacheManagers.put("test", cacheManager(mockCache("dupe-cache"), mockCache("b")));
|
||||||
cacheManagers.put("another", cacheManager(mockCache("dupe-cache")));
|
cacheManagers.put("another", cacheManager(mockCache("dupe-cache")));
|
||||||
CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
|
CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
|
||||||
|
assertThatExceptionOfType(NonUniqueCacheException.class)
|
||||||
this.thrown.expectMessage("dupe-cache");
|
.isThrownBy(() -> endpoint.clearCache("dupe-cache", null))
|
||||||
this.thrown.expectMessage("test");
|
.withMessageContaining("dupe-cache").withMessageContaining("test")
|
||||||
this.thrown.expectMessage("another");
|
.withMessageContaining("another");
|
||||||
endpoint.clearCache("dupe-cache", null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,15 +18,14 @@ package org.springframework.boot.actuate.endpoint.annotation;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.OperationType;
|
import org.springframework.boot.actuate.endpoint.OperationType;
|
||||||
import org.springframework.core.annotation.AnnotationAttributes;
|
import org.springframework.core.annotation.AnnotationAttributes;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DiscoveredOperationMethod}.
|
* Tests for {@link DiscoveredOperationMethod}.
|
||||||
|
@ -35,15 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class DiscoveredOperationMethodTests {
|
public class DiscoveredOperationMethodTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenAnnotationAttributesIsNullShouldThrowException() {
|
public void createWhenAnnotationAttributesIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
|
||||||
this.thrown.expectMessage("AnnotationAttributes must not be null");
|
|
||||||
Method method = ReflectionUtils.findMethod(getClass(), "example");
|
Method method = ReflectionUtils.findMethod(getClass(), "example");
|
||||||
new DiscoveredOperationMethod(method, OperationType.READ, null);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
|
() -> new DiscoveredOperationMethod(method, OperationType.READ, null))
|
||||||
|
.withMessageContaining("AnnotationAttributes must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,9 +18,7 @@ package org.springframework.boot.actuate.endpoint.annotation;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.EndpointFilter;
|
import org.springframework.boot.actuate.endpoint.EndpointFilter;
|
||||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||||
|
@ -30,6 +28,7 @@ import org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -40,14 +39,11 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class DiscovererEndpointFilterTests {
|
public class DiscovererEndpointFilterTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenDiscovererIsNullShouldThrowException() {
|
public void createWhenDiscovererIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Discoverer must not be null");
|
.isThrownBy(() -> new TestDiscovererEndpointFilter(null))
|
||||||
new TestDiscovererEndpointFilter(null);
|
.withMessageContaining("Discoverer must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -32,9 +32,7 @@ import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.EndpointFilter;
|
import org.springframework.boot.actuate.endpoint.EndpointFilter;
|
||||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||||
|
@ -54,6 +52,8 @@ import org.springframework.core.annotation.AliasFor;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,39 +65,39 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class EndpointDiscovererTests {
|
public class EndpointDiscovererTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenApplicationContextIsNullShouldThrowException() {
|
public void createWhenApplicationContextIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ApplicationContext must not be null");
|
.isThrownBy(() -> new TestEndpointDiscoverer(null,
|
||||||
new TestEndpointDiscoverer(null, mock(ParameterValueMapper.class),
|
mock(ParameterValueMapper.class), Collections.emptyList(),
|
||||||
Collections.emptyList(), Collections.emptyList());
|
Collections.emptyList()))
|
||||||
|
.withMessageContaining("ApplicationContext must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenParameterValueMapperIsNullShouldThrowException() {
|
public void createWhenParameterValueMapperIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ParameterValueMapper must not be null");
|
.isThrownBy(
|
||||||
new TestEndpointDiscoverer(mock(ApplicationContext.class), null,
|
() -> new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
||||||
Collections.emptyList(), Collections.emptyList());
|
null, Collections.emptyList(), Collections.emptyList()))
|
||||||
|
.withMessageContaining("ParameterValueMapper must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenInvokerAdvisorsIsNullShouldThrowException() {
|
public void createWhenInvokerAdvisorsIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("InvokerAdvisors must not be null");
|
.isThrownBy(() -> new TestEndpointDiscoverer(
|
||||||
new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
mock(ApplicationContext.class), mock(ParameterValueMapper.class),
|
||||||
mock(ParameterValueMapper.class), null, Collections.emptyList());
|
null, Collections.emptyList()))
|
||||||
|
.withMessageContaining("InvokerAdvisors must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenFiltersIsNullShouldThrowException() {
|
public void createWhenFiltersIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("Filters must not be null");
|
() -> new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
||||||
new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
mock(ParameterValueMapper.class), Collections.emptyList(), null))
|
||||||
mock(ParameterValueMapper.class), Collections.emptyList(), null);
|
.withMessageContaining("Filters must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -139,11 +139,11 @@ public class EndpointDiscovererTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenTwoEndpointsHaveTheSameIdShouldThrowException() {
|
public void getEndpointsWhenTwoEndpointsHaveTheSameIdShouldThrowException() {
|
||||||
load(ClashingEndpointConfiguration.class, (context) -> {
|
load(ClashingEndpointConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(context) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Found two endpoints with the id 'test': ");
|
.isThrownBy(new TestEndpointDiscoverer(context)::getEndpoints)
|
||||||
new TestEndpointDiscoverer(context).getEndpoints();
|
.withMessageContaining(
|
||||||
});
|
"Found two endpoints with the id 'test': "));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,9 +18,7 @@ package org.springframework.boot.actuate.endpoint.invoke.convert;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.invoke.OperationParameter;
|
import org.springframework.boot.actuate.endpoint.invoke.OperationParameter;
|
||||||
import org.springframework.boot.actuate.endpoint.invoke.ParameterMappingException;
|
import org.springframework.boot.actuate.endpoint.invoke.ParameterMappingException;
|
||||||
|
@ -29,6 +27,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||||
|
|
||||||
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.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
@ -43,9 +42,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class ConversionServiceParameterValueMapperTests {
|
public class ConversionServiceParameterValueMapperTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mapParameterShouldDelegateToConversionService() {
|
public void mapParameterShouldDelegateToConversionService() {
|
||||||
DefaultFormattingConversionService conversionService = spy(
|
DefaultFormattingConversionService conversionService = spy(
|
||||||
|
@ -90,9 +86,9 @@ public class ConversionServiceParameterValueMapperTests {
|
||||||
ConversionService conversionService = new DefaultConversionService();
|
ConversionService conversionService = new DefaultConversionService();
|
||||||
ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper(
|
ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper(
|
||||||
conversionService);
|
conversionService);
|
||||||
this.thrown.expect(ParameterMappingException.class);
|
assertThatExceptionOfType(ParameterMappingException.class).isThrownBy(() -> mapper
|
||||||
mapper.mapParameterValue(new TestOperationParameter(OffsetDateTime.class),
|
.mapParameterValue(new TestOperationParameter(OffsetDateTime.class),
|
||||||
"2011-12-03T10:15:30+01:00");
|
"2011-12-03T10:15:30+01:00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestOperationParameter implements OperationParameter {
|
private static class TestOperationParameter implements OperationParameter {
|
||||||
|
|
|
@ -25,9 +25,7 @@ import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.invoke.OperationParameter;
|
import org.springframework.boot.actuate.endpoint.invoke.OperationParameter;
|
||||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||||
|
@ -35,6 +33,8 @@ import org.springframework.core.ParameterNameDiscoverer;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,9 +44,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class OperationMethodParametersTests {
|
public class OperationMethodParametersTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example",
|
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example",
|
||||||
String.class);
|
String.class);
|
||||||
|
|
||||||
|
@ -55,24 +52,25 @@ public class OperationMethodParametersTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenMethodIsNullShouldThrowException() {
|
public void createWhenMethodIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Method must not be null");
|
.isThrownBy(() -> new OperationMethodParameters(null,
|
||||||
new OperationMethodParameters(null, mock(ParameterNameDiscoverer.class));
|
mock(ParameterNameDiscoverer.class)))
|
||||||
|
.withMessageContaining("Method must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenParameterNameDiscovererIsNullShouldThrowException() {
|
public void createWhenParameterNameDiscovererIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ParameterNameDiscoverer must not be null");
|
.isThrownBy(() -> new OperationMethodParameters(this.exampleMethod, null))
|
||||||
new OperationMethodParameters(this.exampleMethod, null);
|
.withMessageContaining("ParameterNameDiscoverer must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenParameterNameDiscovererReturnsNullShouldThrowException() {
|
public void createWhenParameterNameDiscovererReturnsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Failed to extract parameter names");
|
.isThrownBy(() -> new OperationMethodParameters(this.exampleMethod,
|
||||||
new OperationMethodParameters(this.exampleMethod,
|
mock(ParameterNameDiscoverer.class)))
|
||||||
mock(ParameterNameDiscoverer.class));
|
.withMessageContaining("Failed to extract parameter names");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,15 +18,14 @@ package org.springframework.boot.actuate.endpoint.invoke.reflect;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.OperationType;
|
import org.springframework.boot.actuate.endpoint.OperationType;
|
||||||
import org.springframework.boot.actuate.endpoint.invoke.OperationParameters;
|
import org.springframework.boot.actuate.endpoint.invoke.OperationParameters;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link OperationMethod}.
|
* Tests for {@link OperationMethod}.
|
||||||
|
@ -35,24 +34,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class OperationMethodTests {
|
public class OperationMethodTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example",
|
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example",
|
||||||
String.class);
|
String.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenMethodIsNullShouldThrowException() {
|
public void createWhenMethodIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Method must not be null");
|
.isThrownBy(() -> new OperationMethod(null, OperationType.READ))
|
||||||
new OperationMethod(null, OperationType.READ);
|
.withMessageContaining("Method must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenOperationTypeIsNullShouldThrowException() {
|
public void createWhenOperationTypeIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("OperationType must not be null");
|
.isThrownBy(() -> new OperationMethod(this.exampleMethod, null))
|
||||||
new OperationMethod(this.exampleMethod, null);
|
.withMessageContaining("OperationType must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -19,9 +19,7 @@ package org.springframework.boot.actuate.endpoint.invoke.reflect;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||||
import org.springframework.boot.actuate.endpoint.OperationType;
|
import org.springframework.boot.actuate.endpoint.OperationType;
|
||||||
|
@ -32,6 +30,8 @@ import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
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.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,9 +41,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class ReflectiveOperationInvokerTests {
|
public class ReflectiveOperationInvokerTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private Example target;
|
private Example target;
|
||||||
|
|
||||||
private OperationMethod operationMethod;
|
private OperationMethod operationMethod;
|
||||||
|
@ -62,24 +59,26 @@ public class ReflectiveOperationInvokerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenTargetIsNullShouldThrowException() {
|
public void createWhenTargetIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Target must not be null");
|
.isThrownBy(() -> new ReflectiveOperationInvoker(null,
|
||||||
new ReflectiveOperationInvoker(null, this.operationMethod,
|
this.operationMethod, this.parameterValueMapper))
|
||||||
this.parameterValueMapper);
|
.withMessageContaining("Target must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenOperationMethodIsNullShouldThrowException() {
|
public void createWhenOperationMethodIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("OperationMethod must not be null");
|
.isThrownBy(() -> new ReflectiveOperationInvoker(this.target, null,
|
||||||
new ReflectiveOperationInvoker(this.target, null, this.parameterValueMapper);
|
this.parameterValueMapper))
|
||||||
|
.withMessageContaining("OperationMethod must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenParameterValueMapperIsNullShouldThrowException() {
|
public void createWhenParameterValueMapperIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ParameterValueMapper must not be null");
|
.isThrownBy(() -> new ReflectiveOperationInvoker(this.target,
|
||||||
new ReflectiveOperationInvoker(this.target, this.operationMethod, null);
|
this.operationMethod, null))
|
||||||
|
.withMessageContaining("ParameterValueMapper must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -95,9 +94,9 @@ public class ReflectiveOperationInvokerTests {
|
||||||
public void invokeWhenMissingNonNullableArgumentShouldThrowException() {
|
public void invokeWhenMissingNonNullableArgumentShouldThrowException() {
|
||||||
ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target,
|
ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target,
|
||||||
this.operationMethod, this.parameterValueMapper);
|
this.operationMethod, this.parameterValueMapper);
|
||||||
this.thrown.expect(MissingParametersException.class);
|
assertThatExceptionOfType(MissingParametersException.class).isThrownBy(
|
||||||
invoker.invoke(new InvocationContext(mock(SecurityContext.class),
|
() -> invoker.invoke(new InvocationContext(mock(SecurityContext.class),
|
||||||
Collections.singletonMap("name", null)));
|
Collections.singletonMap("name", null))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -21,15 +21,14 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||||
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
||||||
import org.springframework.boot.actuate.endpoint.invoke.OperationInvoker;
|
import org.springframework.boot.actuate.endpoint.invoke.OperationInvoker;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
|
@ -43,14 +42,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
*/
|
*/
|
||||||
public class CachingOperationInvokerTests {
|
public class CachingOperationInvokerTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createInstanceWithTtlSetToZero() {
|
public void createInstanceWithTtlSetToZero() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("TimeToLive");
|
() -> new CachingOperationInvoker(mock(OperationInvoker.class), 0))
|
||||||
new CachingOperationInvoker(mock(OperationInvoker.class), 0);
|
.withMessageContaining("TimeToLive");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -27,9 +27,7 @@ import javax.management.MBeanException;
|
||||||
import javax.management.MBeanInfo;
|
import javax.management.MBeanInfo;
|
||||||
import javax.management.ReflectionException;
|
import javax.management.ReflectionException;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import org.springframework.beans.FatalBeanException;
|
import org.springframework.beans.FatalBeanException;
|
||||||
|
@ -38,7 +36,8 @@ import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -55,9 +54,6 @@ public class EndpointMBeanTests {
|
||||||
|
|
||||||
private static final String[] NO_SIGNATURE = {};
|
private static final String[] NO_SIGNATURE = {};
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(
|
private TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(
|
||||||
new TestJmxOperation());
|
new TestJmxOperation());
|
||||||
|
|
||||||
|
@ -65,16 +61,17 @@ public class EndpointMBeanTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenResponseMapperIsNullShouldThrowException() {
|
public void createWhenResponseMapperIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("ResponseMapper must not be null");
|
() -> new EndpointMBean(null, null, mock(ExposableJmxEndpoint.class)))
|
||||||
new EndpointMBean(null, null, mock(ExposableJmxEndpoint.class));
|
.withMessageContaining("ResponseMapper must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenEndpointIsNullShouldThrowException() {
|
public void createWhenEndpointIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Endpoint must not be null");
|
.isThrownBy(() -> new EndpointMBean(
|
||||||
new EndpointMBean(mock(JmxOperationResponseMapper.class), null, null);
|
mock(JmxOperationResponseMapper.class), null, null))
|
||||||
|
.withMessageContaining("Endpoint must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -100,10 +97,11 @@ public class EndpointMBeanTests {
|
||||||
throw new FatalBeanException("test failure");
|
throw new FatalBeanException("test failure");
|
||||||
}));
|
}));
|
||||||
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
||||||
this.thrown.expect(MBeanException.class);
|
assertThatExceptionOfType(MBeanException.class)
|
||||||
this.thrown.expectCause(instanceOf(IllegalStateException.class));
|
.isThrownBy(() -> bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE))
|
||||||
this.thrown.expectMessage("test failure");
|
.withCauseInstanceOf(IllegalStateException.class)
|
||||||
bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
|
.withMessageContaining("test failure");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -114,20 +112,21 @@ public class EndpointMBeanTests {
|
||||||
throw new UnsupportedOperationException("test failure");
|
throw new UnsupportedOperationException("test failure");
|
||||||
}));
|
}));
|
||||||
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
||||||
this.thrown.expect(MBeanException.class);
|
assertThatExceptionOfType(MBeanException.class)
|
||||||
this.thrown.expectCause(instanceOf(UnsupportedOperationException.class));
|
.isThrownBy(() -> bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE))
|
||||||
this.thrown.expectMessage("test failure");
|
.withCauseInstanceOf(UnsupportedOperationException.class)
|
||||||
bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
|
.withMessageContaining("test failure");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invokeWhenActionNameIsNotAnOperationShouldThrowException()
|
public void invokeWhenActionNameIsNotAnOperationShouldThrowException()
|
||||||
throws MBeanException, ReflectionException {
|
throws MBeanException, ReflectionException {
|
||||||
EndpointMBean bean = createEndpointMBean();
|
EndpointMBean bean = createEndpointMBean();
|
||||||
this.thrown.expect(ReflectionException.class);
|
assertThatExceptionOfType(ReflectionException.class)
|
||||||
this.thrown.expectCause(instanceOf(IllegalArgumentException.class));
|
.isThrownBy(
|
||||||
this.thrown.expectMessage("no operation named missingOperation");
|
() -> bean.invoke("missingOperation", NO_PARAMS, NO_SIGNATURE))
|
||||||
bean.invoke("missingOperation", NO_PARAMS, NO_SIGNATURE);
|
.withCauseInstanceOf(IllegalArgumentException.class)
|
||||||
|
.withMessageContaining("no operation named missingOperation");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -159,10 +158,10 @@ public class EndpointMBeanTests {
|
||||||
};
|
};
|
||||||
TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(operation);
|
TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(operation);
|
||||||
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
||||||
this.thrown.expect(ReflectionException.class);
|
assertThatExceptionOfType(ReflectionException.class)
|
||||||
this.thrown.expectCause(instanceOf(IllegalArgumentException.class));
|
.isThrownBy(() -> bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE))
|
||||||
this.thrown.expectMessage("test failure");
|
.withRootCauseInstanceOf(IllegalArgumentException.class)
|
||||||
bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
|
.withMessageContaining("test failure");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -189,18 +188,18 @@ public class EndpointMBeanTests {
|
||||||
public void getAttributeShouldThrowException()
|
public void getAttributeShouldThrowException()
|
||||||
throws AttributeNotFoundException, MBeanException, ReflectionException {
|
throws AttributeNotFoundException, MBeanException, ReflectionException {
|
||||||
EndpointMBean bean = createEndpointMBean();
|
EndpointMBean bean = createEndpointMBean();
|
||||||
this.thrown.expect(AttributeNotFoundException.class);
|
assertThatExceptionOfType(AttributeNotFoundException.class)
|
||||||
this.thrown.expectMessage("EndpointMBeans do not support attributes");
|
.isThrownBy(() -> bean.getAttribute("test"))
|
||||||
bean.getAttribute("test");
|
.withMessageContaining("EndpointMBeans do not support attributes");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAttributeShouldThrowException() throws AttributeNotFoundException,
|
public void setAttributeShouldThrowException() throws AttributeNotFoundException,
|
||||||
InvalidAttributeValueException, MBeanException, ReflectionException {
|
InvalidAttributeValueException, MBeanException, ReflectionException {
|
||||||
EndpointMBean bean = createEndpointMBean();
|
EndpointMBean bean = createEndpointMBean();
|
||||||
this.thrown.expect(AttributeNotFoundException.class);
|
assertThatExceptionOfType(AttributeNotFoundException.class)
|
||||||
this.thrown.expectMessage("EndpointMBeans do not support attributes");
|
.isThrownBy(() -> bean.setAttribute(new Attribute("test", "test")))
|
||||||
bean.setAttribute(new Attribute("test", "test"));
|
.withMessageContaining("EndpointMBeans do not support attributes");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -26,9 +26,7 @@ import javax.management.MalformedObjectNameException;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
@ -38,6 +36,9 @@ import org.springframework.jmx.JmxException;
|
||||||
import org.springframework.jmx.export.MBeanExportException;
|
import org.springframework.jmx.export.MBeanExportException;
|
||||||
|
|
||||||
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.assertThatIllegalArgumentException;
|
||||||
|
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;
|
||||||
|
@ -52,9 +53,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class JmxEndpointExporterTests {
|
public class JmxEndpointExporterTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private MBeanServer mBeanServer;
|
private MBeanServer mBeanServer;
|
||||||
|
|
||||||
|
@ -82,34 +80,34 @@ public class JmxEndpointExporterTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenMBeanServerIsNullShouldThrowException() {
|
public void createWhenMBeanServerIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("MBeanServer must not be null");
|
.isThrownBy(() -> new JmxEndpointExporter(null, this.objectNameFactory,
|
||||||
new JmxEndpointExporter(null, this.objectNameFactory, this.responseMapper,
|
this.responseMapper, this.endpoints))
|
||||||
this.endpoints);
|
.withMessageContaining("MBeanServer must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenObjectNameFactoryIsNullShouldThrowException() {
|
public void createWhenObjectNameFactoryIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ObjectNameFactory must not be null");
|
.isThrownBy(() -> new JmxEndpointExporter(this.mBeanServer, null,
|
||||||
new JmxEndpointExporter(this.mBeanServer, null, this.responseMapper,
|
this.responseMapper, this.endpoints))
|
||||||
this.endpoints);
|
.withMessageContaining("ObjectNameFactory must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenResponseMapperIsNullShouldThrowException() {
|
public void createWhenResponseMapperIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ResponseMapper must not be null");
|
.isThrownBy(() -> new JmxEndpointExporter(this.mBeanServer,
|
||||||
new JmxEndpointExporter(this.mBeanServer, this.objectNameFactory, null,
|
this.objectNameFactory, null, this.endpoints))
|
||||||
this.endpoints);
|
.withMessageContaining("ResponseMapper must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenEndpointsIsNullShouldThrowException() {
|
public void createWhenEndpointsIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Endpoints must not be null");
|
.isThrownBy(() -> new JmxEndpointExporter(this.mBeanServer,
|
||||||
new JmxEndpointExporter(this.mBeanServer, this.objectNameFactory,
|
this.objectNameFactory, this.responseMapper, null))
|
||||||
this.responseMapper, null);
|
.withMessageContaining("Endpoints must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -135,9 +133,8 @@ public class JmxEndpointExporterTests {
|
||||||
given(this.objectNameFactory.getObjectName(any(ExposableJmxEndpoint.class)))
|
given(this.objectNameFactory.getObjectName(any(ExposableJmxEndpoint.class)))
|
||||||
.willThrow(MalformedObjectNameException.class);
|
.willThrow(MalformedObjectNameException.class);
|
||||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(this.exporter::afterPropertiesSet)
|
||||||
this.thrown.expectMessage("Invalid ObjectName for endpoint 'test'");
|
.withMessageContaining("Invalid ObjectName for endpoint 'test'");
|
||||||
this.exporter.afterPropertiesSet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -145,9 +142,9 @@ public class JmxEndpointExporterTests {
|
||||||
given(this.mBeanServer.registerMBean(any(), any(ObjectName.class)))
|
given(this.mBeanServer.registerMBean(any(), any(ObjectName.class)))
|
||||||
.willThrow(new MBeanRegistrationException(new RuntimeException()));
|
.willThrow(new MBeanRegistrationException(new RuntimeException()));
|
||||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||||
this.thrown.expect(MBeanExportException.class);
|
assertThatExceptionOfType(MBeanExportException.class)
|
||||||
this.thrown.expectMessage("Failed to register MBean for endpoint 'test");
|
.isThrownBy(this.exporter::afterPropertiesSet)
|
||||||
this.exporter.afterPropertiesSet();
|
.withMessageContaining("Failed to register MBean for endpoint 'test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -176,9 +173,9 @@ public class JmxEndpointExporterTests {
|
||||||
this.exporter.afterPropertiesSet();
|
this.exporter.afterPropertiesSet();
|
||||||
willThrow(new MBeanRegistrationException(new RuntimeException()))
|
willThrow(new MBeanRegistrationException(new RuntimeException()))
|
||||||
.given(this.mBeanServer).unregisterMBean(any(ObjectName.class));
|
.given(this.mBeanServer).unregisterMBean(any(ObjectName.class));
|
||||||
this.thrown.expect(JmxException.class);
|
assertThatExceptionOfType(JmxException.class)
|
||||||
this.thrown.expectMessage("Failed to unregister MBean with ObjectName 'boot");
|
.isThrownBy(() -> this.exporter.destroy()).withMessageContaining(
|
||||||
this.exporter.destroy();
|
"Failed to unregister MBean with ObjectName 'boot");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,9 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
|
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
|
@ -49,6 +47,7 @@ import org.springframework.jmx.export.annotation.ManagedOperationParameters;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link JmxEndpointDiscoverer}.
|
* Tests for {@link JmxEndpointDiscoverer}.
|
||||||
|
@ -58,9 +57,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class JmxEndpointDiscovererTests {
|
public class JmxEndpointDiscovererTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||||
load(EmptyConfiguration.class,
|
load(EmptyConfiguration.class,
|
||||||
|
@ -113,13 +109,10 @@ public class JmxEndpointDiscovererTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenJmxExtensionIsMissingEndpointShouldThrowException() {
|
public void getEndpointsWhenJmxExtensionIsMissingEndpointShouldThrowException() {
|
||||||
load(TestJmxEndpointExtension.class, (discoverer) -> {
|
load(TestJmxEndpointExtension.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage(
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
"Invalid extension 'jmxEndpointDiscovererTests.TestJmxEndpointExtension': "
|
"Invalid extension 'jmxEndpointDiscovererTests.TestJmxEndpointExtension': no endpoint found with id 'test'"));
|
||||||
+ "no endpoint found with id 'test'");
|
|
||||||
discoverer.getEndpoints();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -188,51 +181,42 @@ public class JmxEndpointDiscovererTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
public void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
||||||
load(ClashingJmxEndpointConfiguration.class, (discoverer) -> {
|
load(ClashingJmxEndpointConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Found multiple extensions for the endpoint bean "
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
+ "testEndpoint (testExtensionOne, testExtensionTwo)");
|
"Found multiple extensions for the endpoint bean testEndpoint (testExtensionOne, testExtensionTwo)"));
|
||||||
discoverer.getEndpoints();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
public void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
||||||
load(ClashingStandardEndpointConfiguration.class, (discoverer) -> {
|
load(ClashingStandardEndpointConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Found two endpoints with the id 'test': ");
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
discoverer.getEndpoints();
|
"Found two endpoints with the id 'test': "));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
public void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||||
load(ClashingOperationsEndpoint.class, (discoverer) -> {
|
load(ClashingOperationsEndpoint.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Unable to map duplicate endpoint operations: "
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
+ "[MBean call 'getAll'] to jmxEndpointDiscovererTests.ClashingOperationsEndpoint");
|
"Unable to map duplicate endpoint operations: [MBean call 'getAll'] to jmxEndpointDiscovererTests.ClashingOperationsEndpoint"));
|
||||||
discoverer.getEndpoints();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
public void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||||
load(AdditionalClashingOperationsConfiguration.class, (discoverer) -> {
|
load(AdditionalClashingOperationsConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Unable to map duplicate endpoint operations: "
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
+ "[MBean call 'getAll'] to testEndpoint (clashingOperationsJmxEndpointExtension)");
|
"Unable to map duplicate endpoint operations: [MBean call 'getAll'] to testEndpoint (clashingOperationsJmxEndpointExtension)"));
|
||||||
discoverer.getEndpoints();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
public void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
||||||
load(InvalidJmxExtensionConfiguration.class, (discoverer) -> {
|
load(InvalidJmxExtensionConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Endpoint bean 'nonJmxEndpoint' cannot support the "
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
+ "extension bean 'nonJmxJmxEndpointExtension'");
|
"Endpoint bean 'nonJmxEndpoint' cannot support the extension bean 'nonJmxJmxEndpointExtension'"));
|
||||||
discoverer.getEndpoints();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getInvoker(JmxOperation operation) {
|
private Object getInvoker(JmxOperation operation) {
|
||||||
|
|
|
@ -20,11 +20,10 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link EndpointMediaTypes}.
|
* Tests for {@link EndpointMediaTypes}.
|
||||||
|
@ -33,21 +32,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class EndpointMediaTypesTests {
|
public class EndpointMediaTypesTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenProducedIsNullShouldThrowException() {
|
public void createWhenProducedIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Produced must not be null");
|
.isThrownBy(() -> new EndpointMediaTypes(null, Collections.emptyList()))
|
||||||
new EndpointMediaTypes(null, Collections.emptyList());
|
.withMessageContaining("Produced must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenConsumedIsNullShouldThrowException() {
|
public void createWhenConsumedIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Consumed must not be null");
|
.isThrownBy(() -> new EndpointMediaTypes(Collections.emptyList(), null))
|
||||||
new EndpointMediaTypes(Collections.emptyList(), null);
|
.withMessageContaining("Consumed must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -27,11 +27,10 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.assertj.core.api.Assertions.entry;
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,21 +41,18 @@ import static org.assertj.core.api.Assertions.entry;
|
||||||
*/
|
*/
|
||||||
public class EndpointServletTests {
|
public class EndpointServletTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenServletClassIsNullShouldThrowException() {
|
public void createWhenServletClassIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Servlet must not be null");
|
.isThrownBy(() -> new EndpointServlet((Class<Servlet>) null))
|
||||||
new EndpointServlet((Class<Servlet>) null);
|
.withMessageContaining("Servlet must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenServletIsNullShouldThrowException() {
|
public void createWhenServletIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Servlet must not be null");
|
.isThrownBy(() -> new EndpointServlet((Servlet) null))
|
||||||
new EndpointServlet((Servlet) null);
|
.withMessageContaining("Servlet must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -75,15 +71,15 @@ public class EndpointServletTests {
|
||||||
@Test
|
@Test
|
||||||
public void withInitParameterNullName() {
|
public void withInitParameterNullName() {
|
||||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
endpointServlet.withInitParameter(null, "value");
|
.isThrownBy(() -> endpointServlet.withInitParameter(null, "value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withInitParameterEmptyName() {
|
public void withInitParameterEmptyName() {
|
||||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
endpointServlet.withInitParameter(" ", "value");
|
.isThrownBy(() -> endpointServlet.withInitParameter(" ", "value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -105,15 +101,15 @@ public class EndpointServletTests {
|
||||||
@Test
|
@Test
|
||||||
public void withInitParametersNullName() {
|
public void withInitParametersNullName() {
|
||||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> endpointServlet
|
||||||
endpointServlet.withInitParameters(Collections.singletonMap(null, "value"));
|
.withInitParameters(Collections.singletonMap(null, "value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withInitParametersEmptyName() {
|
public void withInitParametersEmptyName() {
|
||||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> endpointServlet
|
||||||
endpointServlet.withInitParameters(Collections.singletonMap(" ", "value"));
|
.withInitParameters(Collections.singletonMap(" ", "value")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.endpoint.web;
|
package org.springframework.boot.actuate.endpoint.web;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link Link}.
|
* Tests for {@link Link}.
|
||||||
|
@ -29,14 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class LinkTests {
|
public class LinkTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenHrefIsNullShouldThrowException() {
|
public void createWhenHrefIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> new Link(null))
|
||||||
this.thrown.expectMessage("HREF must not be null");
|
.withMessageContaining("HREF must not be null");
|
||||||
new Link(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -20,15 +20,14 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.EndpointsSupplier;
|
import org.springframework.boot.actuate.endpoint.EndpointsSupplier;
|
||||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||||
import org.springframework.boot.actuate.endpoint.Operation;
|
import org.springframework.boot.actuate.endpoint.Operation;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -39,21 +38,20 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class PathMappedEndpointsTests {
|
public class PathMappedEndpointsTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenSupplierIsNullShouldThrowException() {
|
public void createWhenSupplierIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Supplier must not be null");
|
.isThrownBy(
|
||||||
new PathMappedEndpoints(null, (WebEndpointsSupplier) null);
|
() -> new PathMappedEndpoints(null, (WebEndpointsSupplier) null))
|
||||||
|
.withMessageContaining("Supplier must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenSuppliersIsNullShouldThrowException() {
|
public void createWhenSuppliersIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Suppliers must not be null");
|
.isThrownBy(() -> new PathMappedEndpoints(null,
|
||||||
new PathMappedEndpoints(null, (Collection<EndpointsSupplier<?>>) null);
|
(Collection<EndpointsSupplier<?>>) null))
|
||||||
|
.withMessageContaining("Suppliers must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -27,15 +27,14 @@ import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
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.MockitoAnnotations;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
@ -50,9 +49,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class ServletEndpointRegistrarTests {
|
public class ServletEndpointRegistrarTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ServletContext servletContext;
|
private ServletContext servletContext;
|
||||||
|
|
||||||
|
@ -71,9 +67,9 @@ public class ServletEndpointRegistrarTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenServletEndpointsIsNullShouldThrowException() {
|
public void createWhenServletEndpointsIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ServletEndpoints must not be null");
|
.isThrownBy(() -> new ServletEndpointRegistrar(null, null))
|
||||||
new ServletEndpointRegistrar(null, null);
|
.withMessageContaining("ServletEndpoints must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,9 +22,7 @@ import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.DiscoveredEndpoint;
|
import org.springframework.boot.actuate.endpoint.annotation.DiscoveredEndpoint;
|
||||||
|
@ -41,6 +39,7 @@ import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ControllerEndpointDiscoverer}.
|
* Tests for {@link ControllerEndpointDiscoverer}.
|
||||||
|
@ -50,9 +49,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class ControllerEndpointDiscovererTests {
|
public class ControllerEndpointDiscovererTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -140,12 +136,10 @@ public class ControllerEndpointDiscovererTests {
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
public void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
||||||
this.contextRunner.withUserConfiguration(TestControllerWithOperation.class)
|
this.contextRunner.withUserConfiguration(TestControllerWithOperation.class)
|
||||||
.run(assertDiscoverer((discoverer) -> {
|
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||||
this.thrown.expect(IllegalStateException.class);
|
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||||
this.thrown.expectMessage(
|
.withMessageContaining(
|
||||||
"ControllerEndpoints must not declare operations");
|
"ControllerEndpoints must not declare operations")));
|
||||||
discoverer.getEndpoints();
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContextConsumer<AssertableApplicationContext> assertDiscoverer(
|
private ContextConsumer<AssertableApplicationContext> assertDiscoverer(
|
||||||
|
|
|
@ -29,9 +29,7 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.DiscoveredEndpoint;
|
import org.springframework.boot.actuate.endpoint.annotation.DiscoveredEndpoint;
|
||||||
|
@ -50,6 +48,7 @@ import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ServletEndpointDiscoverer}.
|
* Tests for {@link ServletEndpointDiscoverer}.
|
||||||
|
@ -59,9 +58,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class ServletEndpointDiscovererTests {
|
public class ServletEndpointDiscovererTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -116,43 +112,36 @@ public class ServletEndpointDiscovererTests {
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
public void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
||||||
this.contextRunner.withUserConfiguration(TestServletEndpointWithOperation.class)
|
this.contextRunner.withUserConfiguration(TestServletEndpointWithOperation.class)
|
||||||
.run(assertDiscoverer((discoverer) -> {
|
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||||
this.thrown.expect(IllegalStateException.class);
|
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||||
this.thrown.expectMessage(
|
.withMessageContaining(
|
||||||
"ServletEndpoints must not declare operations");
|
"ServletEndpoints must not declare operations")));
|
||||||
discoverer.getEndpoints();
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointWhenEndpointNotASupplierShouldThrowException() {
|
public void getEndpointWhenEndpointNotASupplierShouldThrowException() {
|
||||||
this.contextRunner.withUserConfiguration(TestServletEndpointNotASupplier.class)
|
this.contextRunner.withUserConfiguration(TestServletEndpointNotASupplier.class)
|
||||||
.run(assertDiscoverer((discoverer) -> {
|
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||||
this.thrown.expect(IllegalStateException.class);
|
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||||
this.thrown.expectMessage("must be a supplier");
|
.withMessageContaining("must be a supplier")));
|
||||||
discoverer.getEndpoints();
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointWhenEndpointSuppliesWrongTypeShouldThrowException() {
|
public void getEndpointWhenEndpointSuppliesWrongTypeShouldThrowException() {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
.withUserConfiguration(TestServletEndpointSupplierOfWrongType.class)
|
.withUserConfiguration(TestServletEndpointSupplierOfWrongType.class)
|
||||||
.run(assertDiscoverer((discoverer) -> {
|
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||||
this.thrown.expect(IllegalStateException.class);
|
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||||
this.thrown.expectMessage("must supply an EndpointServlet");
|
.withMessageContaining(
|
||||||
discoverer.getEndpoints();
|
"must supply an EndpointServlet")));
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointWhenEndpointSuppliesNullShouldThrowException() {
|
public void getEndpointWhenEndpointSuppliesNullShouldThrowException() {
|
||||||
this.contextRunner.withUserConfiguration(TestServletEndpointSupplierOfNull.class)
|
this.contextRunner.withUserConfiguration(TestServletEndpointSupplierOfNull.class)
|
||||||
.run(assertDiscoverer((discoverer) -> {
|
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(
|
||||||
this.thrown.expect(IllegalStateException.class);
|
IllegalStateException.class).isThrownBy(discoverer::getEndpoints)
|
||||||
this.thrown.expectMessage("must not supply null");
|
.withMessageContaining("must not supply null")));
|
||||||
discoverer.getEndpoints();
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContextConsumer<AssertableApplicationContext> assertDiscoverer(
|
private ContextConsumer<AssertableApplicationContext> assertDiscoverer(
|
||||||
|
|
|
@ -29,9 +29,7 @@ import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.assertj.core.api.Condition;
|
import org.assertj.core.api.Condition;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
|
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
|
||||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||||
|
@ -58,6 +56,7 @@ import org.springframework.core.io.Resource;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link WebEndpointDiscoverer}.
|
* Tests for {@link WebEndpointDiscoverer}.
|
||||||
|
@ -68,9 +67,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class WebEndpointDiscovererTests {
|
public class WebEndpointDiscovererTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||||
load(EmptyConfiguration.class,
|
load(EmptyConfiguration.class,
|
||||||
|
@ -79,13 +75,11 @@ public class WebEndpointDiscovererTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenWebExtensionIsMissingEndpointShouldThrowException() {
|
public void getEndpointsWhenWebExtensionIsMissingEndpointShouldThrowException() {
|
||||||
load(TestWebEndpointExtensionConfiguration.class, (discoverer) -> {
|
load(TestWebEndpointExtensionConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage(
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
"Invalid extension 'endpointExtension': no endpoint found with id '"
|
"Invalid extension 'endpointExtension': no endpoint found with id '"
|
||||||
+ "test'");
|
+ "test'"));
|
||||||
discoverer.getEndpoints();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -140,52 +134,49 @@ public class WebEndpointDiscovererTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
public void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
||||||
load(ClashingWebEndpointConfiguration.class, (discoverer) -> {
|
load(ClashingWebEndpointConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Found multiple extensions for the endpoint bean "
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
+ "testEndpoint (testExtensionOne, testExtensionTwo)");
|
"Found multiple extensions for the endpoint bean "
|
||||||
discoverer.getEndpoints();
|
+ "testEndpoint (testExtensionOne, testExtensionTwo)"));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
public void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
||||||
load(ClashingStandardEndpointConfiguration.class, (discoverer) -> {
|
load(ClashingStandardEndpointConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Found two endpoints with the id 'test': ");
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
discoverer.getEndpoints();
|
"Found two endpoints with the id 'test': "));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
public void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||||
load(ClashingOperationsEndpointConfiguration.class, (discoverer) -> {
|
load(ClashingOperationsEndpointConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Unable to map duplicate endpoint operations: "
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
|
"Unable to map duplicate endpoint operations: "
|
||||||
+ "[web request predicate GET to path 'test' "
|
+ "[web request predicate GET to path 'test' "
|
||||||
+ "produces: application/json] to clashingOperationsEndpoint");
|
+ "produces: application/json] to clashingOperationsEndpoint"));
|
||||||
discoverer.getEndpoints();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
public void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
||||||
load(InvalidWebExtensionConfiguration.class, (discoverer) -> {
|
load(InvalidWebExtensionConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Endpoint bean 'nonWebEndpoint' cannot support the "
|
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||||
+ "extension bean 'nonWebWebEndpointExtension'");
|
"Endpoint bean 'nonWebEndpoint' cannot support the "
|
||||||
discoverer.getEndpoints();
|
+ "extension bean 'nonWebWebEndpointExtension'"));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
public void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||||
load(ClashingSelectorsWebEndpointExtensionConfiguration.class, (discoverer) -> {
|
load(ClashingSelectorsWebEndpointExtensionConfiguration.class,
|
||||||
this.thrown.expect(IllegalStateException.class);
|
(discoverer) -> assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Unable to map duplicate endpoint operations");
|
.isThrownBy(discoverer::getEndpoints)
|
||||||
this.thrown.expectMessage("to testEndpoint (clashingSelectorsExtension)");
|
.withMessageContaining(
|
||||||
discoverer.getEndpoints();
|
"Unable to map duplicate endpoint operations")
|
||||||
});
|
.withMessageContaining(
|
||||||
|
"to testEndpoint (clashingSelectorsExtension)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,9 +18,7 @@ package org.springframework.boot.actuate.endpoint.web.reactive;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||||
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
|
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
|
||||||
|
@ -36,6 +34,7 @@ import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.server.MethodNotAllowedException;
|
import org.springframework.web.server.MethodNotAllowedException;
|
||||||
|
|
||||||
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.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -47,9 +46,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class ControllerEndpointHandlerMappingTests {
|
public class ControllerEndpointHandlerMappingTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -92,8 +88,8 @@ public class ControllerEndpointHandlerMappingTests {
|
||||||
public void mappingNarrowedToMethod() throws Exception {
|
public void mappingNarrowedToMethod() throws Exception {
|
||||||
ExposableControllerEndpoint first = firstEndpoint();
|
ExposableControllerEndpoint first = firstEndpoint();
|
||||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first);
|
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first);
|
||||||
this.thrown.expect(MethodNotAllowedException.class);
|
assertThatExceptionOfType(MethodNotAllowedException.class).isThrownBy(
|
||||||
getHandler(mapping, HttpMethod.POST, "/actuator/first");
|
() -> getHandler(mapping, HttpMethod.POST, "/actuator/first"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getHandler(ControllerEndpointHandlerMapping mapping, HttpMethod method,
|
private Object getHandler(ControllerEndpointHandlerMapping mapping, HttpMethod method,
|
||||||
|
|
|
@ -18,9 +18,7 @@ package org.springframework.boot.actuate.endpoint.web.servlet;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||||
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
|
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
|
||||||
|
@ -34,6 +32,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
|
||||||
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.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -45,9 +44,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class ControllerEndpointHandlerMappingTests {
|
public class ControllerEndpointHandlerMappingTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -80,8 +76,8 @@ public class ControllerEndpointHandlerMappingTests {
|
||||||
public void mappingNarrowedToMethod() throws Exception {
|
public void mappingNarrowedToMethod() throws Exception {
|
||||||
ExposableControllerEndpoint first = firstEndpoint();
|
ExposableControllerEndpoint first = firstEndpoint();
|
||||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first);
|
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first);
|
||||||
this.thrown.expect(HttpRequestMethodNotSupportedException.class);
|
assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class)
|
||||||
mapping.getHandler(request("POST", "/actuator/first"));
|
.isThrownBy(() -> mapping.getHandler(request("POST", "/actuator/first")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -19,11 +19,11 @@ package org.springframework.boot.actuate.health;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
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.assertThatIllegalStateException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -35,9 +35,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class DefaultHealthIndicatorRegistryTests {
|
public class DefaultHealthIndicatorRegistryTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private HealthIndicator one = mock(HealthIndicator.class);
|
private HealthIndicator one = mock(HealthIndicator.class);
|
||||||
|
|
||||||
private HealthIndicator two = mock(HealthIndicator.class);
|
private HealthIndicator two = mock(HealthIndicator.class);
|
||||||
|
@ -65,9 +62,10 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||||
@Test
|
@Test
|
||||||
public void registerAlreadyUsedName() {
|
public void registerAlreadyUsedName() {
|
||||||
this.registry.register("one", this.one);
|
this.registry.register("one", this.one);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("HealthIndicator with name 'one' already registered");
|
.isThrownBy(() -> this.registry.register("one", this.two))
|
||||||
this.registry.register("one", this.two);
|
.withMessageContaining(
|
||||||
|
"HealthIndicator with name 'one' already registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -102,9 +100,8 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||||
public void getAllIsImmutable() {
|
public void getAllIsImmutable() {
|
||||||
this.registry.register("one", this.one);
|
this.registry.register("one", this.one);
|
||||||
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
||||||
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
this.thrown.expect(UnsupportedOperationException.class);
|
.isThrownBy(snapshot::clear);
|
||||||
snapshot.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,12 @@ package org.springframework.boot.actuate.health;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
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.assertThatIllegalStateException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -36,9 +36,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class DefaultReactiveHealthIndicatorRegistryTests {
|
public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private ReactiveHealthIndicator one = mock(ReactiveHealthIndicator.class);
|
private ReactiveHealthIndicator one = mock(ReactiveHealthIndicator.class);
|
||||||
|
|
||||||
private ReactiveHealthIndicator two = mock(ReactiveHealthIndicator.class);
|
private ReactiveHealthIndicator two = mock(ReactiveHealthIndicator.class);
|
||||||
|
@ -66,9 +63,10 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||||
@Test
|
@Test
|
||||||
public void registerAlreadyUsedName() {
|
public void registerAlreadyUsedName() {
|
||||||
this.registry.register("one", this.one);
|
this.registry.register("one", this.one);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("HealthIndicator with name 'one' already registered");
|
.isThrownBy(() -> this.registry.register("one", this.two))
|
||||||
this.registry.register("one", this.two);
|
.withMessageContaining(
|
||||||
|
"HealthIndicator with name 'one' already registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -103,9 +101,8 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||||
public void getAllIsImmutable() {
|
public void getAllIsImmutable() {
|
||||||
this.registry.register("one", this.one);
|
this.registry.register("one", this.one);
|
||||||
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
||||||
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
this.thrown.expect(UnsupportedOperationException.class);
|
.isThrownBy(snapshot::clear);
|
||||||
snapshot.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,10 @@ import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.assertj.core.api.Assertions.entry;
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,14 +35,11 @@ import static org.assertj.core.api.Assertions.entry;
|
||||||
*/
|
*/
|
||||||
public class HealthTests {
|
public class HealthTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void statusMustNotBeNull() {
|
public void statusMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Status must not be null");
|
.isThrownBy(() -> new Health.Builder(null, null))
|
||||||
new Health.Builder(null, null);
|
.withMessageContaining("Status must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.info;
|
package org.springframework.boot.actuate.info;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
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.entry;
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,15 +29,11 @@ import static org.assertj.core.api.Assertions.entry;
|
||||||
*/
|
*/
|
||||||
public class InfoTests {
|
public class InfoTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void infoIsImmutable() {
|
public void infoIsImmutable() {
|
||||||
Info info = new Info.Builder().withDetail("foo", "bar").build();
|
Info info = new Info.Builder().withDetail("foo", "bar").build();
|
||||||
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
this.thrown.expect(UnsupportedOperationException.class);
|
.isThrownBy(info.getDetails()::clear);
|
||||||
info.getDetails().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.info;
|
package org.springframework.boot.actuate.info;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link SimpleInfoContributor}.
|
* Tests for {@link SimpleInfoContributor}.
|
||||||
|
@ -29,13 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class SimpleInfoContributorTests {
|
public class SimpleInfoContributorTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void prefixIsMandatory() {
|
public void prefixIsMandatory() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
new SimpleInfoContributor(null, new Object());
|
.isThrownBy(() -> new SimpleInfoContributor(null, new Object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -27,13 +27,12 @@ import io.micrometer.core.instrument.Statistic;
|
||||||
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
|
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
|
||||||
import io.micrometer.core.instrument.simple.SimpleConfig;
|
import io.micrometer.core.instrument.simple.SimpleConfig;
|
||||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException;
|
import org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link MetricsEndpoint}.
|
* Tests for {@link MetricsEndpoint}.
|
||||||
|
@ -43,9 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class MetricsEndpointTests {
|
public class MetricsEndpointTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT,
|
private final MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT,
|
||||||
new MockClock());
|
new MockClock());
|
||||||
|
|
||||||
|
@ -118,8 +114,8 @@ public class MetricsEndpointTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void metricWithInvalidTag() {
|
public void metricWithInvalidTag() {
|
||||||
this.thrown.expect(InvalidEndpointRequestException.class);
|
assertThatExceptionOfType(InvalidEndpointRequestException.class).isThrownBy(
|
||||||
this.endpoint.metric("counter", Collections.singletonList("key"));
|
() -> this.endpoint.metric("counter", Collections.singletonList("key")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -19,9 +19,7 @@ package org.springframework.boot.actuate.system;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@ -45,9 +43,6 @@ public class DiskSpaceHealthIndicatorTests {
|
||||||
|
|
||||||
private static final DataSize TOTAL_SPACE = DataSize.ofKilobytes(10);
|
private static final DataSize TOTAL_SPACE = DataSize.ofKilobytes(10);
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private File fileMock;
|
private File fileMock;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +20,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.boot.autoconfigure.context.filtersample.ExampleConfiguration;
|
import org.springframework.boot.autoconfigure.context.filtersample.ExampleConfiguration;
|
||||||
|
@ -33,6 +31,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.FilterType;
|
import org.springframework.context.annotation.FilterType;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link AutoConfigurationExcludeFilter}.
|
* Tests for {@link AutoConfigurationExcludeFilter}.
|
||||||
|
@ -43,9 +42,6 @@ public class AutoConfigurationExcludeFilterTests {
|
||||||
|
|
||||||
private static final Class<?> FILTERED = ExampleFilteredAutoConfiguration.class;
|
private static final Class<?> FILTERED = ExampleFilteredAutoConfiguration.class;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -60,8 +56,8 @@ public class AutoConfigurationExcludeFilterTests {
|
||||||
this.context = new AnnotationConfigApplicationContext(Config.class);
|
this.context = new AnnotationConfigApplicationContext(Config.class);
|
||||||
assertThat(this.context.getBeansOfType(String.class)).hasSize(1);
|
assertThat(this.context.getBeansOfType(String.class)).hasSize(1);
|
||||||
assertThat(this.context.getBean(String.class)).isEqualTo("test");
|
assertThat(this.context.getBean(String.class)).isEqualTo("test");
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(FILTERED);
|
.isThrownBy(() -> this.context.getBean(FILTERED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +23,7 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
|
@ -43,6 +41,7 @@ import org.springframework.core.type.StandardAnnotationMetadata;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link AutoConfigurationImportSelector}
|
* Tests for {@link AutoConfigurationImportSelector}
|
||||||
|
@ -61,9 +60,6 @@ public class AutoConfigurationImportSelectorTests {
|
||||||
|
|
||||||
private List<AutoConfigurationImportFilter> filters = new ArrayList<>();
|
private List<AutoConfigurationImportFilter> filters = new ArrayList<>();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException expected = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
@ -173,14 +169,14 @@ public class AutoConfigurationImportSelectorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonAutoConfigurationClassExclusionsShouldThrowException() {
|
public void nonAutoConfigurationClassExclusionsShouldThrowException() {
|
||||||
this.expected.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(
|
||||||
selectImports(EnableAutoConfigurationWithFaultyClassExclude.class);
|
() -> selectImports(EnableAutoConfigurationWithFaultyClassExclude.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonAutoConfigurationClassNameExclusionsWhenPresentOnClassPathShouldThrowException() {
|
public void nonAutoConfigurationClassNameExclusionsWhenPresentOnClassPathShouldThrowException() {
|
||||||
this.expected.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(() -> selectImports(
|
||||||
selectImports(EnableAutoConfigurationWithFaultyClassNameExclude.class);
|
EnableAutoConfigurationWithFaultyClassNameExclude.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -188,8 +184,8 @@ public class AutoConfigurationImportSelectorTests {
|
||||||
this.environment.setProperty("spring.autoconfigure.exclude",
|
this.environment.setProperty("spring.autoconfigure.exclude",
|
||||||
"org.springframework.boot.autoconfigure."
|
"org.springframework.boot.autoconfigure."
|
||||||
+ "AutoConfigurationImportSelectorTests.TestConfiguration");
|
+ "AutoConfigurationImportSelectorTests.TestConfiguration");
|
||||||
this.expected.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
selectImports(BasicEnableAutoConfiguration.class);
|
.isThrownBy(() -> selectImports(BasicEnableAutoConfiguration.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,7 @@ package org.springframework.boot.autoconfigure;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages.Registrar;
|
import org.springframework.boot.autoconfigure.AutoConfigurationPackages.Registrar;
|
||||||
import org.springframework.boot.autoconfigure.packagestest.one.FirstConfiguration;
|
import org.springframework.boot.autoconfigure.packagestest.one.FirstConfiguration;
|
||||||
|
@ -30,6 +28,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link AutoConfigurationPackages}.
|
* Tests for {@link AutoConfigurationPackages}.
|
||||||
|
@ -40,9 +39,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public class AutoConfigurationPackagesTests {
|
public class AutoConfigurationPackagesTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAndGet() {
|
public void setAndGet() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
|
@ -55,10 +51,10 @@ public class AutoConfigurationPackagesTests {
|
||||||
public void getWithoutSet() {
|
public void getWithoutSet() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
EmptyConfig.class);
|
EmptyConfig.class);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage(
|
.isThrownBy(() -> AutoConfigurationPackages.get(context.getBeanFactory()))
|
||||||
|
.withMessageContaining(
|
||||||
"Unable to retrieve @EnableAutoConfiguration base packages");
|
"Unable to retrieve @EnableAutoConfiguration base packages");
|
||||||
AutoConfigurationPackages.get(context.getBeanFactory());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -24,9 +24,7 @@ import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||||
|
@ -36,6 +34,7 @@ import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,9 +73,6 @@ public class AutoConfigurationSorterTests {
|
||||||
|
|
||||||
private static final String W2 = AutoConfigureW2.class.getName();
|
private static final String W2 = AutoConfigureW2.class.getName();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private AutoConfigurationSorter sorter;
|
private AutoConfigurationSorter sorter;
|
||||||
|
|
||||||
private AutoConfigurationMetadata autoConfigurationMetadata = mock(
|
private AutoConfigurationMetadata autoConfigurationMetadata = mock(
|
||||||
|
@ -144,9 +140,10 @@ public class AutoConfigurationSorterTests {
|
||||||
public void byAutoConfigureAfterWithCycle() {
|
public void byAutoConfigureAfterWithCycle() {
|
||||||
this.sorter = new AutoConfigurationSorter(new CachingMetadataReaderFactory(),
|
this.sorter = new AutoConfigurationSorter(new CachingMetadataReaderFactory(),
|
||||||
this.autoConfigurationMetadata);
|
this.autoConfigurationMetadata);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("AutoConfigure cycle detected");
|
.isThrownBy(
|
||||||
this.sorter.getInPriorityOrder(Arrays.asList(A, B, C, D));
|
() -> this.sorter.getInPriorityOrder(Arrays.asList(A, B, C, D)))
|
||||||
|
.withMessageContaining("AutoConfigure cycle detected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -176,9 +173,9 @@ public class AutoConfigurationSorterTests {
|
||||||
this.autoConfigurationMetadata = getAutoConfigurationMetadata(A, B, D);
|
this.autoConfigurationMetadata = getAutoConfigurationMetadata(A, B, D);
|
||||||
this.sorter = new AutoConfigurationSorter(readerFactory,
|
this.sorter = new AutoConfigurationSorter(readerFactory,
|
||||||
this.autoConfigurationMetadata);
|
this.autoConfigurationMetadata);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("AutoConfigure cycle detected");
|
.isThrownBy(() -> this.sorter.getInPriorityOrder(Arrays.asList(D, B)))
|
||||||
this.sorter.getInPriorityOrder(Arrays.asList(D, B));
|
.withMessageContaining("AutoConfigure cycle detected");
|
||||||
}
|
}
|
||||||
|
|
||||||
private AutoConfigurationMetadata getAutoConfigurationMetadata(String... classNames)
|
private AutoConfigurationMetadata getAutoConfigurationMetadata(String... classNames)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +24,7 @@ import javax.management.MalformedObjectNameException;
|
||||||
import javax.management.ObjectInstance;
|
import javax.management.ObjectInstance;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
@ -44,6 +42,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.jmx.export.MBeanExporter;
|
import org.springframework.jmx.export.MBeanExporter;
|
||||||
|
|
||||||
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.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,9 +57,6 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
|
||||||
|
|
||||||
private static final String DEFAULT_JMX_NAME = "org.springframework.boot:type=Admin,name=SpringApplication";
|
private static final String DEFAULT_JMX_NAME = "org.springframework.boot:type=Admin,name=SpringApplication";
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
|
private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
|
@ -70,10 +66,9 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notRegisteredByDefault() {
|
public void notRegisteredByDefault() {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> assertThatExceptionOfType(
|
||||||
this.thrown.expect(InstanceNotFoundException.class);
|
InstanceNotFoundException.class).isThrownBy(
|
||||||
this.server.getObjectInstance(createDefaultObjectName());
|
() -> this.server.getObjectInstance(createDefaultObjectName())));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -99,9 +94,9 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
|
||||||
catch (InstanceNotFoundException ex) {
|
catch (InstanceNotFoundException ex) {
|
||||||
fail("Admin MBean should have been exposed with custom name");
|
fail("Admin MBean should have been exposed with custom name");
|
||||||
}
|
}
|
||||||
this.thrown.expect(InstanceNotFoundException.class); // Should not be
|
assertThatExceptionOfType(InstanceNotFoundException.class)
|
||||||
// exposed
|
.isThrownBy(() -> this.server
|
||||||
this.server.getObjectInstance(createDefaultObjectName());
|
.getObjectInstance(createDefaultObjectName()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,9 +134,9 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
|
||||||
.run("--" + ENABLE_ADMIN_PROP)) {
|
.run("--" + ENABLE_ADMIN_PROP)) {
|
||||||
BeanFactoryUtils.beanOfType(parent.getBeanFactory(),
|
BeanFactoryUtils.beanOfType(parent.getBeanFactory(),
|
||||||
SpringApplicationAdminMXBeanRegistrar.class);
|
SpringApplicationAdminMXBeanRegistrar.class);
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
BeanFactoryUtils.beanOfType(child.getBeanFactory(),
|
.isThrownBy(() -> BeanFactoryUtils.beanOfType(child.getBeanFactory(),
|
||||||
SpringApplicationAdminMXBeanRegistrar.class);
|
SpringApplicationAdminMXBeanRegistrar.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,7 @@ import com.rabbitmq.client.Connection;
|
||||||
import com.rabbitmq.client.SslContextFactory;
|
import com.rabbitmq.client.SslContextFactory;
|
||||||
import com.rabbitmq.client.TrustEverythingTrustManager;
|
import com.rabbitmq.client.TrustEverythingTrustManager;
|
||||||
import org.aopalliance.aop.Advice;
|
import org.aopalliance.aop.Advice;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.amqp.core.AcknowledgeMode;
|
import org.springframework.amqp.core.AcknowledgeMode;
|
||||||
import org.springframework.amqp.core.AmqpAdmin;
|
import org.springframework.amqp.core.AmqpAdmin;
|
||||||
|
@ -69,6 +67,7 @@ import org.springframework.retry.support.RetryTemplate;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
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.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.ArgumentMatchers.isNull;
|
import static org.mockito.ArgumentMatchers.isNull;
|
||||||
|
@ -85,9 +84,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class RabbitAutoConfigurationTests {
|
public class RabbitAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(RabbitAutoConfiguration.class));
|
.withConfiguration(AutoConfigurations.of(RabbitAutoConfiguration.class));
|
||||||
|
|
||||||
|
@ -413,15 +409,14 @@ public class RabbitAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaticQueues() {
|
public void testStaticQueues() {
|
||||||
|
// There should NOT be an AmqpAdmin bean when dynamic is switch to false
|
||||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.withPropertyValues("spring.rabbitmq.dynamic:false").run((context) -> {
|
.withPropertyValues("spring.rabbitmq.dynamic:false")
|
||||||
// There should NOT be an AmqpAdmin bean when dynamic is switch to
|
.run((context) -> assertThatExceptionOfType(
|
||||||
// false
|
NoSuchBeanDefinitionException.class)
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
.isThrownBy(() -> context.getBean(AmqpAdmin.class))
|
||||||
this.thrown.expectMessage("No qualifying bean of type");
|
.withMessageContaining("No qualifying bean of type '"
|
||||||
this.thrown.expectMessage(AmqpAdmin.class.getName());
|
+ AmqpAdmin.class.getName() + "'"));
|
||||||
context.getBean(AmqpAdmin.class);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +22,7 @@ import java.util.Collections;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.batch.core.BatchStatus;
|
import org.springframework.batch.core.BatchStatus;
|
||||||
import org.springframework.batch.core.Job;
|
import org.springframework.batch.core.Job;
|
||||||
|
@ -62,6 +60,7 @@ import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link BatchAutoConfiguration}.
|
* Tests for {@link BatchAutoConfiguration}.
|
||||||
|
@ -73,9 +72,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class BatchAutoConfigurationTests {
|
public class BatchAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException expected = ExpectedException.none();
|
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(BatchAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(BatchAutoConfiguration.class,
|
||||||
TransactionAutoConfiguration.class));
|
TransactionAutoConfiguration.class));
|
||||||
|
@ -176,9 +172,9 @@ public class BatchAutoConfigurationTests {
|
||||||
assertThat(
|
assertThat(
|
||||||
context.getBean(BatchProperties.class).getInitializeSchema())
|
context.getBean(BatchProperties.class).getInitializeSchema())
|
||||||
.isEqualTo(DataSourceInitializationMode.NEVER);
|
.isEqualTo(DataSourceInitializationMode.NEVER);
|
||||||
this.expected.expect(BadSqlGrammarException.class);
|
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(
|
||||||
new JdbcTemplate(context.getBean(DataSource.class))
|
() -> new JdbcTemplate(context.getBean(DataSource.class))
|
||||||
.queryForList("select * from BATCH_JOB_EXECUTION");
|
.queryForList("select * from BATCH_JOB_EXECUTION"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,10 @@ import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.WebApplicationType;
|
import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
@ -36,8 +35,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.env.StandardEnvironment;
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ConditionalOnProperty}.
|
* Tests for {@link ConditionalOnProperty}.
|
||||||
|
@ -49,9 +47,6 @@ import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
|
||||||
*/
|
*/
|
||||||
public class ConditionalOnPropertyTests {
|
public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
private ConfigurableEnvironment environment = new StandardEnvironment();
|
private ConfigurableEnvironment environment = new StandardEnvironment();
|
||||||
|
@ -205,18 +200,22 @@ public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nameOrValueMustBeSpecified() {
|
public void nameOrValueMustBeSpecified() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectCause(hasMessage(containsString("The name or "
|
.isThrownBy(() -> load(NoNameOrValueAttribute.class, "some.property"))
|
||||||
+ "value attribute of @ConditionalOnProperty must be specified")));
|
.satisfies(causeMessageContaining(
|
||||||
load(NoNameOrValueAttribute.class, "some.property");
|
"The name or value attribute of @ConditionalOnProperty must be specified"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nameAndValueMustNotBeSpecified() {
|
public void nameAndValueMustNotBeSpecified() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectCause(hasMessage(containsString("The name and "
|
.isThrownBy(() -> load(NameAndValueAttribute.class, "some.property"))
|
||||||
+ "value attributes of @ConditionalOnProperty are exclusive")));
|
.satisfies(causeMessageContaining(
|
||||||
load(NameAndValueAttribute.class, "some.property");
|
"The name and value attributes of @ConditionalOnProperty are exclusive"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Exception> Consumer<T> causeMessageContaining(String message) {
|
||||||
|
return (ex) -> assertThat(ex.getCause()).hasMessageContaining(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.condition;
|
package org.springframework.boot.autoconfigure.condition;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -27,7 +25,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.CoreMatchers.isA;
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ConditionalOnSingleCandidate}.
|
* Tests for {@link ConditionalOnSingleCandidate}.
|
||||||
|
@ -37,9 +35,6 @@ import static org.hamcrest.CoreMatchers.isA;
|
||||||
*/
|
*/
|
||||||
public class ConditionalOnSingleCandidateTests {
|
public class ConditionalOnSingleCandidateTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -126,20 +121,20 @@ public class ConditionalOnSingleCandidateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidAnnotationTwoTypes() {
|
public void invalidAnnotationTwoTypes() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectCause(isA(IllegalArgumentException.class));
|
.isThrownBy(() -> load(OnBeanSingleCandidateTwoTypesConfiguration.class))
|
||||||
this.thrown.expectMessage(
|
.withCauseInstanceOf(IllegalArgumentException.class)
|
||||||
|
.withMessageContaining(
|
||||||
OnBeanSingleCandidateTwoTypesConfiguration.class.getName());
|
OnBeanSingleCandidateTwoTypesConfiguration.class.getName());
|
||||||
load(OnBeanSingleCandidateTwoTypesConfiguration.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidAnnotationNoType() {
|
public void invalidAnnotationNoType() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectCause(isA(IllegalArgumentException.class));
|
.isThrownBy(() -> load(OnBeanSingleCandidateNoTypeConfiguration.class))
|
||||||
this.thrown
|
.withCauseInstanceOf(IllegalArgumentException.class)
|
||||||
.expectMessage(OnBeanSingleCandidateNoTypeConfiguration.class.getName());
|
.withMessageContaining(
|
||||||
load(OnBeanSingleCandidateNoTypeConfiguration.class);
|
OnBeanSingleCandidateNoTypeConfiguration.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -16,9 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.condition;
|
package org.springframework.boot.autoconfigure.condition;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -27,6 +25,8 @@ import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link SpringBootCondition}.
|
* Tests for {@link SpringBootCondition}.
|
||||||
*
|
*
|
||||||
|
@ -35,23 +35,22 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public class SpringBootConditionTests {
|
public class SpringBootConditionTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sensibleClassException() {
|
public void sensibleClassException() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage(
|
.isThrownBy(
|
||||||
|
() -> new AnnotationConfigApplicationContext(ErrorOnClass.class))
|
||||||
|
.withMessageContaining(
|
||||||
"Error processing condition on " + ErrorOnClass.class.getName());
|
"Error processing condition on " + ErrorOnClass.class.getName());
|
||||||
new AnnotationConfigApplicationContext(ErrorOnClass.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sensibleMethodException() {
|
public void sensibleMethodException() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Error processing condition on "
|
.isThrownBy(
|
||||||
|
() -> new AnnotationConfigApplicationContext(ErrorOnMethod.class))
|
||||||
|
.withMessageContaining("Error processing condition on "
|
||||||
+ ErrorOnMethod.class.getName() + ".myBean");
|
+ ErrorOnMethod.class.getName() + ".myBean");
|
||||||
new AnnotationConfigApplicationContext(ErrorOnMethod.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +20,7 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
@ -30,6 +28,8 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.annotation.AnnotationConfigurationException;
|
import org.springframework.core.annotation.AnnotationConfigurationException;
|
||||||
|
|
||||||
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.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link EntityScanPackages}.
|
* Tests for {@link EntityScanPackages}.
|
||||||
|
@ -40,9 +40,6 @@ public class EntityScanPackagesTests {
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanup() {
|
public void cleanup() {
|
||||||
if (this.context != null) {
|
if (this.context != null) {
|
||||||
|
@ -71,33 +68,36 @@ public class EntityScanPackagesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerFromArrayWhenRegistryIsNullShouldThrowException() {
|
public void registerFromArrayWhenRegistryIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Registry must not be null");
|
.isThrownBy(() -> EntityScanPackages.register(null))
|
||||||
EntityScanPackages.register(null);
|
.withMessageContaining("Registry must not be null");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerFromArrayWhenPackageNamesIsNullShouldThrowException() {
|
public void registerFromArrayWhenPackageNamesIsNullShouldThrowException() {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("PackageNames must not be null");
|
.isThrownBy(
|
||||||
EntityScanPackages.register(this.context, (String[]) null);
|
() -> EntityScanPackages.register(this.context, (String[]) null))
|
||||||
|
.withMessageContaining("PackageNames must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerFromCollectionWhenRegistryIsNullShouldThrowException() {
|
public void registerFromCollectionWhenRegistryIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Registry must not be null");
|
.isThrownBy(
|
||||||
EntityScanPackages.register(null, Collections.emptyList());
|
() -> EntityScanPackages.register(null, Collections.emptyList()))
|
||||||
|
.withMessageContaining("Registry must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerFromCollectionWhenPackageNamesIsNullShouldThrowException() {
|
public void registerFromCollectionWhenPackageNamesIsNullShouldThrowException() {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("PackageNames must not be null");
|
.isThrownBy(() -> EntityScanPackages.register(this.context,
|
||||||
EntityScanPackages.register(this.context, (Collection<String>) null);
|
(Collection<String>) null))
|
||||||
|
.withMessageContaining("PackageNames must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -128,9 +128,9 @@ public class EntityScanPackagesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityScanAnnotationWhenHasValueAndBasePackagesAttributeShouldThrow() {
|
public void entityScanAnnotationWhenHasValueAndBasePackagesAttributeShouldThrow() {
|
||||||
this.thrown.expect(AnnotationConfigurationException.class);
|
assertThatExceptionOfType(AnnotationConfigurationException.class)
|
||||||
this.context = new AnnotationConfigApplicationContext(
|
.isThrownBy(() -> this.context = new AnnotationConfigApplicationContext(
|
||||||
EntityScanValueAndBasePackagesConfig.class);
|
EntityScanValueAndBasePackagesConfig.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +21,7 @@ import java.util.Set;
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.domain.scan.a.EmbeddableA;
|
import org.springframework.boot.autoconfigure.domain.scan.a.EmbeddableA;
|
||||||
import org.springframework.boot.autoconfigure.domain.scan.a.EntityA;
|
import org.springframework.boot.autoconfigure.domain.scan.a.EntityA;
|
||||||
|
@ -35,6 +33,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link EntityScanner}.
|
* Tests for {@link EntityScanner}.
|
||||||
|
@ -43,14 +42,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class EntityScannerTests {
|
public class EntityScannerTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenContextIsNullShouldThrowException() {
|
public void createWhenContextIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> new EntityScanner(null))
|
||||||
this.thrown.expectMessage("Context must not be null");
|
.withMessageContaining("Context must not be null");
|
||||||
new EntityScanner(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,7 @@ package org.springframework.boot.autoconfigure.h2;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.boot.test.util.TestPropertyValues;
|
import org.springframework.boot.test.util.TestPropertyValues;
|
||||||
|
@ -29,6 +27,7 @@ import org.springframework.mock.web.MockServletContext;
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link H2ConsoleAutoConfiguration}
|
* Tests for {@link H2ConsoleAutoConfiguration}
|
||||||
|
@ -41,9 +40,6 @@ public class H2ConsoleAutoConfigurationTests {
|
||||||
|
|
||||||
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setupContext() {
|
public void setupContext() {
|
||||||
this.context.setServletContext(new MockServletContext());
|
this.context.setServletContext(new MockServletContext());
|
||||||
|
@ -79,13 +75,13 @@ public class H2ConsoleAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customPathMustBeginWithASlash() {
|
public void customPathMustBeginWithASlash() {
|
||||||
this.thrown.expect(BeanCreationException.class);
|
|
||||||
this.thrown.expectMessage("Failed to bind properties under 'spring.h2.console'");
|
|
||||||
this.context.register(H2ConsoleAutoConfiguration.class);
|
this.context.register(H2ConsoleAutoConfiguration.class);
|
||||||
TestPropertyValues
|
TestPropertyValues
|
||||||
.of("spring.h2.console.enabled:true", "spring.h2.console.path:custom")
|
.of("spring.h2.console.enabled:true", "spring.h2.console.path:custom")
|
||||||
.applyTo(this.context);
|
.applyTo(this.context);
|
||||||
this.context.refresh();
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
|
.isThrownBy(this.context::refresh).withMessageContaining(
|
||||||
|
"Failed to bind properties under 'spring.h2.console'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.h2;
|
package org.springframework.boot.autoconfigure.h2;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link H2ConsoleProperties}.
|
* Tests for {@link H2ConsoleProperties}.
|
||||||
|
@ -27,33 +27,29 @@ import org.junit.rules.ExpectedException;
|
||||||
*/
|
*/
|
||||||
public class H2ConsolePropertiesTests {
|
public class H2ConsolePropertiesTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private H2ConsoleProperties properties;
|
private H2ConsoleProperties properties;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathMustNotBeEmpty() {
|
public void pathMustNotBeEmpty() {
|
||||||
this.properties = new H2ConsoleProperties();
|
this.properties = new H2ConsoleProperties();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> this.properties.setPath(""))
|
||||||
this.thrown.expectMessage("Path must have length greater than 1");
|
.withMessageContaining("Path must have length greater than 1");
|
||||||
this.properties.setPath("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathMustHaveLengthGreaterThanOne() {
|
public void pathMustHaveLengthGreaterThanOne() {
|
||||||
this.properties = new H2ConsoleProperties();
|
this.properties = new H2ConsoleProperties();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Path must have length greater than 1");
|
.isThrownBy(() -> this.properties.setPath("/"))
|
||||||
this.properties.setPath("/");
|
.withMessageContaining("Path must have length greater than 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customPathMustBeginWithASlash() {
|
public void customPathMustBeginWithASlash() {
|
||||||
this.properties = new H2ConsoleProperties();
|
this.properties = new H2ConsoleProperties();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Path must start with '/'");
|
.isThrownBy(() -> this.properties.setPath("custom"))
|
||||||
this.properties.setPath("custom");
|
.withMessageContaining("Path must start with '/'");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,7 @@ package org.springframework.boot.autoconfigure.integration;
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
@ -47,6 +45,7 @@ import org.springframework.jdbc.core.JdbcOperations;
|
||||||
import org.springframework.jmx.export.MBeanExporter;
|
import org.springframework.jmx.export.MBeanExporter;
|
||||||
|
|
||||||
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.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,9 +57,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class IntegrationAutoConfigurationTests {
|
public class IntegrationAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class,
|
||||||
IntegrationAutoConfiguration.class));
|
IntegrationAutoConfiguration.class));
|
||||||
|
@ -189,8 +185,8 @@ public class IntegrationAutoConfigurationTests {
|
||||||
assertThat(properties.getJdbc().getInitializeSchema())
|
assertThat(properties.getJdbc().getInitializeSchema())
|
||||||
.isEqualTo(DataSourceInitializationMode.NEVER);
|
.isEqualTo(DataSourceInitializationMode.NEVER);
|
||||||
JdbcOperations jdbc = context.getBean(JdbcOperations.class);
|
JdbcOperations jdbc = context.getBean(JdbcOperations.class);
|
||||||
this.thrown.expect(BadSqlGrammarException.class);
|
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(
|
||||||
jdbc.queryForList("select * from INT_MESSAGE");
|
() -> jdbc.queryForList("select * from INT_MESSAGE"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jdbc;
|
package org.springframework.boot.autoconfigure.jdbc;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
||||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DataSourceProperties}.
|
* Tests for {@link DataSourceProperties}.
|
||||||
|
@ -34,9 +33,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class DataSourcePropertiesTests {
|
public class DataSourcePropertiesTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void determineDriver() {
|
public void determineDriver() {
|
||||||
DataSourceProperties properties = new DataSourceProperties();
|
DataSourceProperties properties = new DataSourceProperties();
|
||||||
|
@ -71,9 +67,10 @@ public class DataSourcePropertiesTests {
|
||||||
properties.setBeanClassLoader(
|
properties.setBeanClassLoader(
|
||||||
new FilteredClassLoader("org.h2", "org.apache.derby", "org.hsqldb"));
|
new FilteredClassLoader("org.h2", "org.apache.derby", "org.hsqldb"));
|
||||||
properties.afterPropertiesSet();
|
properties.afterPropertiesSet();
|
||||||
this.thrown.expect(DataSourceProperties.DataSourceBeanCreationException.class);
|
assertThatExceptionOfType(
|
||||||
this.thrown.expectMessage("Failed to determine suitable jdbc url");
|
DataSourceProperties.DataSourceBeanCreationException.class)
|
||||||
properties.determineUrl();
|
.isThrownBy(properties::determineUrl)
|
||||||
|
.withMessageContaining("Failed to determine suitable jdbc url");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -38,9 +38,7 @@ import org.jooq.TransactionListenerProvider;
|
||||||
import org.jooq.TransactionalRunnable;
|
import org.jooq.TransactionalRunnable;
|
||||||
import org.jooq.VisitListener;
|
import org.jooq.VisitListener;
|
||||||
import org.jooq.VisitListenerProvider;
|
import org.jooq.VisitListenerProvider;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
|
@ -69,9 +67,6 @@ public class JooqAutoConfigurationTests {
|
||||||
.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class))
|
||||||
.withPropertyValues("spring.datasource.name:jooqtest");
|
.withPropertyValues("spring.datasource.name:jooqtest");
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noDataSource() {
|
public void noDataSource() {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -42,7 +42,7 @@ import org.springframework.mock.web.MockServletContext;
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
|
|
||||||
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.assertThatIllegalArgumentException;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,9 +155,9 @@ public class ConditionEvaluationReportLoggingListenerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listenerSupportsOnlyInfoAndDebug() {
|
public void listenerSupportsOnlyInfoAndDebug() {
|
||||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
() -> new ConditionEvaluationReportLoggingListener(LogLevel.TRACE))
|
() -> new ConditionEvaluationReportLoggingListener(LogLevel.TRACE))
|
||||||
.withMessage("LogLevel must be INFO or DEBUG");
|
.withMessageContaining("LogLevel must be INFO or DEBUG");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -24,14 +24,13 @@ import com.mongodb.MongoCredential;
|
||||||
import com.mongodb.ServerAddress;
|
import com.mongodb.ServerAddress;
|
||||||
import com.mongodb.connection.ClusterSettings;
|
import com.mongodb.connection.ClusterSettings;
|
||||||
import com.mongodb.reactivestreams.client.MongoClient;
|
import com.mongodb.reactivestreams.client.MongoClient;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -44,9 +43,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class ReactiveMongoClientFactoryTests {
|
public class ReactiveMongoClientFactoryTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private MockEnvironment environment = new MockEnvironment();
|
private MockEnvironment environment = new MockEnvironment();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -126,10 +122,9 @@ public class ReactiveMongoClientFactoryTests {
|
||||||
properties.setUri("mongodb://127.0.0.1:1234/mydb");
|
properties.setUri("mongodb://127.0.0.1:1234/mydb");
|
||||||
properties.setUsername("user");
|
properties.setUsername("user");
|
||||||
properties.setPassword("secret".toCharArray());
|
properties.setPassword("secret".toCharArray());
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(() -> createMongoClient(properties))
|
||||||
this.thrown.expectMessage("Invalid mongo configuration, "
|
.withMessageContaining("Invalid mongo configuration, "
|
||||||
+ "either uri or host/port/credentials must be specified");
|
+ "either uri or host/port/credentials must be specified");
|
||||||
createMongoClient(properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -138,10 +133,9 @@ public class ReactiveMongoClientFactoryTests {
|
||||||
properties.setUri("mongodb://127.0.0.1:1234/mydb");
|
properties.setUri("mongodb://127.0.0.1:1234/mydb");
|
||||||
properties.setHost("localhost");
|
properties.setHost("localhost");
|
||||||
properties.setPort(4567);
|
properties.setPort(4567);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(() -> createMongoClient(properties))
|
||||||
this.thrown.expectMessage("Invalid mongo configuration, "
|
.withMessageContaining("Invalid mongo configuration, "
|
||||||
+ "either uri or host/port/credentials must be specified");
|
+ "either uri or host/port/credentials must be specified");
|
||||||
createMongoClient(properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -23,9 +23,7 @@ import java.util.Map;
|
||||||
import okhttp3.mockwebserver.MockResponse;
|
import okhttp3.mockwebserver.MockResponse;
|
||||||
import okhttp3.mockwebserver.MockWebServer;
|
import okhttp3.mockwebserver.MockWebServer;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
|
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.LoginClientRegistration;
|
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.LoginClientRegistration;
|
||||||
|
@ -40,6 +38,7 @@ import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
||||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
|
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link OAuth2ClientPropertiesRegistrationAdapter}.
|
* Tests for {@link OAuth2ClientPropertiesRegistrationAdapter}.
|
||||||
|
@ -59,9 +58,6 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getClientRegistrationsWhenUsingDefinedProviderShouldAdapt() {
|
public void getClientRegistrationsWhenUsingDefinedProviderShouldAdapt() {
|
||||||
OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
||||||
|
@ -195,9 +191,10 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests {
|
||||||
OAuth2ClientProperties.LoginClientRegistration login = new OAuth2ClientProperties.LoginClientRegistration();
|
OAuth2ClientProperties.LoginClientRegistration login = new OAuth2ClientProperties.LoginClientRegistration();
|
||||||
login.setProvider("missing");
|
login.setProvider("missing");
|
||||||
properties.getRegistration().getLogin().put("registration", login);
|
properties.getRegistration().getLogin().put("registration", login);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Unknown provider ID 'missing'");
|
.isThrownBy(() -> OAuth2ClientPropertiesRegistrationAdapter
|
||||||
OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties);
|
.getClientRegistrations(properties))
|
||||||
|
.withMessageContaining("Unknown provider ID 'missing'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -276,10 +273,11 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests {
|
||||||
OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
||||||
OAuth2ClientProperties.LoginClientRegistration login = new OAuth2ClientProperties.LoginClientRegistration();
|
OAuth2ClientProperties.LoginClientRegistration login = new OAuth2ClientProperties.LoginClientRegistration();
|
||||||
properties.getRegistration().getLogin().put("missing", login);
|
properties.getRegistration().getLogin().put("missing", login);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage(
|
.isThrownBy(() -> OAuth2ClientPropertiesRegistrationAdapter
|
||||||
|
.getClientRegistrations(properties))
|
||||||
|
.withMessageContaining(
|
||||||
"Provider ID must be specified for client registration 'missing'");
|
"Provider ID must be specified for client registration 'missing'");
|
||||||
OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.security.oauth2.client;
|
package org.springframework.boot.autoconfigure.security.oauth2.client;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.AuthorizationCodeClientRegistration;
|
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.AuthorizationCodeClientRegistration;
|
||||||
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.LoginClientRegistration;
|
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.LoginClientRegistration;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link OAuth2ClientProperties}.
|
* Tests for {@link OAuth2ClientProperties}.
|
||||||
*
|
*
|
||||||
|
@ -33,18 +33,14 @@ public class OAuth2ClientPropertiesTests {
|
||||||
|
|
||||||
private OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
private OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientIdAbsentForLoginClientsThrowsException() {
|
public void clientIdAbsentForLoginClientsThrowsException() {
|
||||||
LoginClientRegistration registration = new LoginClientRegistration();
|
LoginClientRegistration registration = new LoginClientRegistration();
|
||||||
registration.setClientSecret("secret");
|
registration.setClientSecret("secret");
|
||||||
registration.setProvider("google");
|
registration.setProvider("google");
|
||||||
this.properties.getRegistration().getLogin().put("foo", registration);
|
this.properties.getRegistration().getLogin().put("foo", registration);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(this.properties::validate)
|
||||||
this.thrown.expectMessage("Client id must not be empty.");
|
.withMessageContaining("Client id must not be empty.");
|
||||||
this.properties.validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -62,9 +58,8 @@ public class OAuth2ClientPropertiesTests {
|
||||||
registration.setClientSecret("secret");
|
registration.setClientSecret("secret");
|
||||||
registration.setProvider("google");
|
registration.setProvider("google");
|
||||||
this.properties.getRegistration().getAuthorizationCode().put("foo", registration);
|
this.properties.getRegistration().getAuthorizationCode().put("foo", registration);
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(this.properties::validate)
|
||||||
this.thrown.expectMessage("Client id must not be empty.");
|
.withMessageContaining("Client id must not be empty.");
|
||||||
this.properties.validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -17,9 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.security.reactive;
|
package org.springframework.boot.autoconfigure.security.reactive;
|
||||||
|
|
||||||
import org.assertj.core.api.AssertDelegateTarget;
|
import org.assertj.core.api.AssertDelegateTarget;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.security.StaticResourceLocation;
|
import org.springframework.boot.autoconfigure.security.StaticResourceLocation;
|
||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
|
@ -35,6 +33,7 @@ import org.springframework.web.server.WebHandler;
|
||||||
import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
|
import org.springframework.web.server.adapter.HttpWebHandlerAdapter;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,9 +45,6 @@ public class StaticResourceRequestTests {
|
||||||
|
|
||||||
private StaticResourceRequest resourceRequest = StaticResourceRequest.INSTANCE;
|
private StaticResourceRequest resourceRequest = StaticResourceRequest.INSTANCE;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void atCommonLocationsShouldMatchCommonLocations() {
|
public void atCommonLocationsShouldMatchCommonLocations() {
|
||||||
ServerWebExchangeMatcher matcher = this.resourceRequest.atCommonLocations();
|
ServerWebExchangeMatcher matcher = this.resourceRequest.atCommonLocations();
|
||||||
|
@ -78,16 +74,17 @@ public class StaticResourceRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void atLocationsFromSetWhenSetIsNullShouldThrowException() {
|
public void atLocationsFromSetWhenSetIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Locations must not be null");
|
.isThrownBy(() -> this.resourceRequest.at(null))
|
||||||
this.resourceRequest.at(null);
|
.withMessageContaining("Locations must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void excludeFromSetWhenSetIsNullShouldThrowException() {
|
public void excludeFromSetWhenSetIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Locations must not be null");
|
.isThrownBy(
|
||||||
this.resourceRequest.atCommonLocations().excluding(null);
|
() -> this.resourceRequest.atCommonLocations().excluding(null))
|
||||||
|
.withMessageContaining("Locations must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
private RequestMatcherAssert assertMatcher(ServerWebExchangeMatcher matcher) {
|
private RequestMatcherAssert assertMatcher(ServerWebExchangeMatcher matcher) {
|
||||||
|
|
|
@ -19,9 +19,7 @@ package org.springframework.boot.autoconfigure.security.servlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.assertj.core.api.AssertDelegateTarget;
|
import org.assertj.core.api.AssertDelegateTarget;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.security.StaticResourceLocation;
|
import org.springframework.boot.autoconfigure.security.StaticResourceLocation;
|
||||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath;
|
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath;
|
||||||
|
@ -32,6 +30,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link StaticResourceRequest}.
|
* Tests for {@link StaticResourceRequest}.
|
||||||
|
@ -43,9 +42,6 @@ public class StaticResourceRequestTests {
|
||||||
|
|
||||||
private StaticResourceRequest resourceRequest = StaticResourceRequest.INSTANCE;
|
private StaticResourceRequest resourceRequest = StaticResourceRequest.INSTANCE;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void atCommonLocationsShouldMatchCommonLocations() {
|
public void atCommonLocationsShouldMatchCommonLocations() {
|
||||||
RequestMatcher matcher = this.resourceRequest.atCommonLocations();
|
RequestMatcher matcher = this.resourceRequest.atCommonLocations();
|
||||||
|
@ -81,16 +77,17 @@ public class StaticResourceRequestTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void atLocationsFromSetWhenSetIsNullShouldThrowException() {
|
public void atLocationsFromSetWhenSetIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Locations must not be null");
|
.isThrownBy(() -> this.resourceRequest.at(null))
|
||||||
this.resourceRequest.at(null);
|
.withMessageContaining("Locations must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void excludeFromSetWhenSetIsNullShouldThrowException() {
|
public void excludeFromSetWhenSetIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Locations must not be null");
|
.isThrownBy(
|
||||||
this.resourceRequest.atCommonLocations().excluding(null);
|
() -> this.resourceRequest.atCommonLocations().excluding(null))
|
||||||
|
.withMessageContaining("Locations must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
private RequestMatcherAssert assertMatcher(RequestMatcher matcher) {
|
private RequestMatcherAssert assertMatcher(RequestMatcher matcher) {
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.session;
|
package org.springframework.boot.autoconfigure.session;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
@ -39,6 +37,7 @@ import org.springframework.session.hazelcast.HazelcastSessionRepository;
|
||||||
import org.springframework.session.jdbc.JdbcOperationsSessionRepository;
|
import org.springframework.session.jdbc.JdbcOperationsSessionRepository;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JDBC specific tests for {@link SessionAutoConfiguration}.
|
* JDBC specific tests for {@link SessionAutoConfiguration}.
|
||||||
|
@ -49,9 +48,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
public class SessionAutoConfigurationJdbcTests
|
public class SessionAutoConfigurationJdbcTests
|
||||||
extends AbstractSessionAutoConfigurationTests {
|
extends AbstractSessionAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
|
||||||
DataSourceTransactionManagerAutoConfiguration.class,
|
DataSourceTransactionManagerAutoConfiguration.class,
|
||||||
|
@ -109,9 +105,9 @@ public class SessionAutoConfigurationJdbcTests
|
||||||
assertThat(context.getBean(JdbcSessionProperties.class)
|
assertThat(context.getBean(JdbcSessionProperties.class)
|
||||||
.getInitializeSchema())
|
.getInitializeSchema())
|
||||||
.isEqualTo(DataSourceInitializationMode.NEVER);
|
.isEqualTo(DataSourceInitializationMode.NEVER);
|
||||||
this.thrown.expect(BadSqlGrammarException.class);
|
assertThatExceptionOfType(BadSqlGrammarException.class)
|
||||||
context.getBean(JdbcOperations.class)
|
.isThrownBy(() -> context.getBean(JdbcOperations.class)
|
||||||
.queryForList("select * from SPRING_SESSION");
|
.queryForList("select * from SPRING_SESSION"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +20,7 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@ -31,6 +29,7 @@ import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
|
@ -43,9 +42,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class TemplateAvailabilityProvidersTests {
|
public class TemplateAvailabilityProvidersTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private TemplateAvailabilityProviders providers;
|
private TemplateAvailabilityProviders providers;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
@ -69,9 +65,9 @@ public class TemplateAvailabilityProvidersTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenApplicationContextIsNullShouldThrowException() {
|
public void createWhenApplicationContextIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("ClassLoader must not be null");
|
() -> new TemplateAvailabilityProviders((ApplicationContext) null))
|
||||||
new TemplateAvailabilityProviders((ApplicationContext) null);
|
.withMessageContaining("ClassLoader must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -86,9 +82,9 @@ public class TemplateAvailabilityProvidersTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenClassLoaderIsNullShouldThrowException() {
|
public void createWhenClassLoaderIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ClassLoader must not be null");
|
.isThrownBy(() -> new TemplateAvailabilityProviders((ClassLoader) null))
|
||||||
new TemplateAvailabilityProviders((ClassLoader) null);
|
.withMessageContaining("ClassLoader must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -100,10 +96,10 @@ public class TemplateAvailabilityProvidersTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenProvidersIsNullShouldThrowException() {
|
public void createWhenProvidersIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Providers must not be null");
|
.isThrownBy(() -> new TemplateAvailabilityProviders(
|
||||||
new TemplateAvailabilityProviders(
|
(Collection<TemplateAvailabilityProvider>) null))
|
||||||
(Collection<TemplateAvailabilityProvider>) null);
|
.withMessageContaining("Providers must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -115,40 +111,41 @@ public class TemplateAvailabilityProvidersTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProviderWhenApplicationContextIsNullShouldThrowException() {
|
public void getProviderWhenApplicationContextIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ApplicationContext must not be null");
|
.isThrownBy(() -> this.providers.getProvider(this.view, null))
|
||||||
this.providers.getProvider(this.view, null);
|
.withMessageContaining("ApplicationContext must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProviderWhenViewIsNullShouldThrowException() {
|
public void getProviderWhenViewIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("View must not be null");
|
.isThrownBy(() -> this.providers.getProvider(null, this.environment,
|
||||||
this.providers.getProvider(null, this.environment, this.classLoader,
|
this.classLoader, this.resourceLoader))
|
||||||
this.resourceLoader);
|
.withMessageContaining("View must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProviderWhenEnvironmentIsNullShouldThrowException() {
|
public void getProviderWhenEnvironmentIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Environment must not be null");
|
.isThrownBy(() -> this.providers.getProvider(this.view, null,
|
||||||
this.providers.getProvider(this.view, null, this.classLoader,
|
this.classLoader, this.resourceLoader))
|
||||||
this.resourceLoader);
|
.withMessageContaining("Environment must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProviderWhenClassLoaderIsNullShouldThrowException() {
|
public void getProviderWhenClassLoaderIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ClassLoader must not be null");
|
.isThrownBy(() -> this.providers.getProvider(this.view, this.environment,
|
||||||
this.providers.getProvider(this.view, this.environment, null,
|
null, this.resourceLoader))
|
||||||
this.resourceLoader);
|
.withMessageContaining("ClassLoader must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProviderWhenResourceLoaderIsNullShouldThrowException() {
|
public void getProviderWhenResourceLoaderIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ResourceLoader must not be null");
|
.isThrownBy(() -> this.providers.getProvider(this.view, this.environment,
|
||||||
this.providers.getProvider(this.view, this.environment, this.classLoader, null);
|
this.classLoader, null))
|
||||||
|
.withMessageContaining("ResourceLoader must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -36,9 +36,7 @@ import com.atomikos.icatch.jta.UserTransactionManager;
|
||||||
import com.atomikos.jms.AtomikosConnectionFactoryBean;
|
import com.atomikos.jms.AtomikosConnectionFactoryBean;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
|
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
|
||||||
|
@ -60,6 +58,7 @@ import org.springframework.transaction.jta.JtaTransactionManager;
|
||||||
import org.springframework.util.FileSystemUtils;
|
import org.springframework.util.FileSystemUtils;
|
||||||
|
|
||||||
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.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -73,9 +72,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class JtaAutoConfigurationTests {
|
public class JtaAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -94,8 +90,8 @@ public class JtaAutoConfigurationTests {
|
||||||
public void customPlatformTransactionManager() {
|
public void customPlatformTransactionManager() {
|
||||||
this.context = new AnnotationConfigApplicationContext(
|
this.context = new AnnotationConfigApplicationContext(
|
||||||
CustomTransactionManagerConfig.class, JtaAutoConfiguration.class);
|
CustomTransactionManagerConfig.class, JtaAutoConfiguration.class);
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(JtaTransactionManager.class);
|
.isThrownBy(() -> this.context.getBean(JtaTransactionManager.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -25,9 +25,7 @@ import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
@ -44,6 +42,7 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess
|
||||||
import org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean;
|
import org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean;
|
||||||
|
|
||||||
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.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,9 +53,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class ValidationAutoConfigurationTests {
|
public class ValidationAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -161,8 +157,8 @@ public class ValidationAutoConfigurationTests {
|
||||||
assertThat(this.context.getBeansOfType(Validator.class)).hasSize(1);
|
assertThat(this.context.getBeansOfType(Validator.class)).hasSize(1);
|
||||||
SampleService service = this.context.getBean(SampleService.class);
|
SampleService service = this.context.getBean(SampleService.class);
|
||||||
service.doSomething("Valid");
|
service.doSomething("Valid");
|
||||||
this.thrown.expect(ConstraintViolationException.class);
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
service.doSomething("KO");
|
.isThrownBy(() -> service.doSomething("KO"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -172,8 +168,8 @@ public class ValidationAutoConfigurationTests {
|
||||||
DefaultAnotherSampleService service = this.context
|
DefaultAnotherSampleService service = this.context
|
||||||
.getBean(DefaultAnotherSampleService.class);
|
.getBean(DefaultAnotherSampleService.class);
|
||||||
service.doSomething(42);
|
service.doSomething(42);
|
||||||
this.thrown.expect(ConstraintViolationException.class);
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
service.doSomething(2);
|
.isThrownBy(() -> service.doSomething(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -185,8 +181,8 @@ public class ValidationAutoConfigurationTests {
|
||||||
.isEmpty();
|
.isEmpty();
|
||||||
AnotherSampleService service = this.context.getBean(AnotherSampleService.class);
|
AnotherSampleService service = this.context.getBean(AnotherSampleService.class);
|
||||||
service.doSomething(42);
|
service.doSomething(42);
|
||||||
this.thrown.expect(ConstraintViolationException.class);
|
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
service.doSomething(2);
|
.isThrownBy(() -> service.doSomething(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -292,7 +292,7 @@ public class ServerPropertiesTests {
|
||||||
jetty.start();
|
jetty.start();
|
||||||
org.eclipse.jetty.server.Connector connector = jetty.getServer()
|
org.eclipse.jetty.server.Connector connector = jetty.getServer()
|
||||||
.getConnectors()[0];
|
.getConnectors()[0];
|
||||||
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
|
final AtomicReference<Throwable> failure = new AtomicReference<>();
|
||||||
connector.addBean(new HttpChannel.Listener() {
|
connector.addBean(new HttpChannel.Listener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -318,14 +318,14 @@ public class ServerPropertiesTests {
|
||||||
});
|
});
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>();
|
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||||
StringBuilder data = new StringBuilder();
|
StringBuilder data = new StringBuilder();
|
||||||
for (int i = 0; i < 250000; i++) {
|
for (int i = 0; i < 250000; i++) {
|
||||||
data.append("a");
|
data.append("a");
|
||||||
}
|
}
|
||||||
body.add("data", data.toString());
|
body.add("data", data.toString());
|
||||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<MultiValueMap<String, Object>>(
|
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(body,
|
||||||
body, headers);
|
headers);
|
||||||
template.postForEntity(
|
template.postForEntity(
|
||||||
URI.create("http://localhost:" + jetty.getPort() + "/form"), entity,
|
URI.create("http://localhost:" + jetty.getPort() + "/form"), entity,
|
||||||
Void.class);
|
Void.class);
|
||||||
|
|
|
@ -18,9 +18,7 @@ package org.springframework.boot.autoconfigure.web.reactive.error;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
@ -43,7 +41,7 @@ import org.springframework.web.server.ResponseStatusException;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for {@link DefaultErrorWebExceptionHandler}
|
* Integration tests for {@link DefaultErrorWebExceptionHandler}
|
||||||
|
@ -63,9 +61,6 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||||
"server.port=0")
|
"server.port=0")
|
||||||
.withUserConfiguration(Application.class);
|
.withUserConfiguration(Application.class);
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jsonError() {
|
public void jsonError() {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> {
|
||||||
|
@ -241,9 +236,11 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> {
|
||||||
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
||||||
.build();
|
.build();
|
||||||
this.thrown.expectCause(instanceOf(IllegalStateException.class));
|
assertThatExceptionOfType(RuntimeException.class)
|
||||||
this.thrown.expectMessage("already committed!");
|
.isThrownBy(
|
||||||
client.get().uri("/commit").exchange().expectStatus();
|
() -> client.get().uri("/commit").exchange().expectStatus())
|
||||||
|
.withCauseInstanceOf(IllegalStateException.class)
|
||||||
|
.withMessageContaining("already committed!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,13 @@ package org.springframework.boot.autoconfigure.web.servlet;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
|
||||||
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.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DispatcherServletRegistrationBean}.
|
* Tests for {@link DispatcherServletRegistrationBean}.
|
||||||
|
@ -33,14 +33,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class DispatcherServletRegistrationBeanTests {
|
public class DispatcherServletRegistrationBeanTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenPathIsNullThrowsException() {
|
public void createWhenPathIsNullThrowsException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Path must not be null");
|
.isThrownBy(() -> new DispatcherServletRegistrationBean(
|
||||||
new DispatcherServletRegistrationBean(new DispatcherServlet(), null);
|
new DispatcherServlet(), null))
|
||||||
|
.withMessageContaining("Path must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -61,16 +59,16 @@ public class DispatcherServletRegistrationBeanTests {
|
||||||
public void setUrlMappingsCannotBeCalled() {
|
public void setUrlMappingsCannotBeCalled() {
|
||||||
DispatcherServletRegistrationBean bean = new DispatcherServletRegistrationBean(
|
DispatcherServletRegistrationBean bean = new DispatcherServletRegistrationBean(
|
||||||
new DispatcherServlet(), "/test");
|
new DispatcherServlet(), "/test");
|
||||||
this.thrown.expect(UnsupportedOperationException.class);
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
bean.setUrlMappings(Collections.emptyList());
|
.isThrownBy(() -> bean.setUrlMappings(Collections.emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addUrlMappingsCannotBeCalled() {
|
public void addUrlMappingsCannotBeCalled() {
|
||||||
DispatcherServletRegistrationBean bean = new DispatcherServletRegistrationBean(
|
DispatcherServletRegistrationBean bean = new DispatcherServletRegistrationBean(
|
||||||
new DispatcherServlet(), "/test");
|
new DispatcherServlet(), "/test");
|
||||||
this.thrown.expect(UnsupportedOperationException.class);
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
bean.addUrlMappings("/test");
|
.isThrownBy(() -> bean.addUrlMappings("/test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,7 @@ import java.util.Map;
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.boot.test.util.TestPropertyValues;
|
import org.springframework.boot.test.util.TestPropertyValues;
|
||||||
|
@ -44,6 +42,7 @@ import org.springframework.web.filter.CharacterEncodingFilter;
|
||||||
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link HttpEncodingAutoConfiguration}
|
* Tests for {@link HttpEncodingAutoConfiguration}
|
||||||
|
@ -52,9 +51,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class HttpEncodingAutoConfigurationTests {
|
public class HttpEncodingAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private AnnotationConfigWebApplicationContext context;
|
private AnnotationConfigWebApplicationContext context;
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -75,8 +71,8 @@ public class HttpEncodingAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void disableConfiguration() {
|
public void disableConfiguration() {
|
||||||
load(EmptyConfiguration.class, "spring.http.encoding.enabled:false");
|
load(EmptyConfiguration.class, "spring.http.encoding.enabled:false");
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(CharacterEncodingFilter.class);
|
.isThrownBy(() -> this.context.getBean(CharacterEncodingFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +29,7 @@ import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||||
|
@ -53,6 +51,7 @@ import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
|
||||||
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.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@ -65,9 +64,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
*/
|
*/
|
||||||
public class BasicErrorControllerDirectMockMvcTests {
|
public class BasicErrorControllerDirectMockMvcTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private ConfigurableWebApplicationContext wac;
|
private ConfigurableWebApplicationContext wac;
|
||||||
|
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
@ -110,8 +106,8 @@ public class BasicErrorControllerDirectMockMvcTests {
|
||||||
setup((ConfigurableWebApplicationContext) new SpringApplication(
|
setup((ConfigurableWebApplicationContext) new SpringApplication(
|
||||||
WebMvcIncludedConfiguration.class).run("--server.port=0",
|
WebMvcIncludedConfiguration.class).run("--server.port=0",
|
||||||
"--server.error.whitelabel.enabled=false"));
|
"--server.error.whitelabel.enabled=false"));
|
||||||
this.thrown.expect(ServletException.class);
|
assertThatExceptionOfType(ServletException.class).isThrownBy(
|
||||||
this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML));
|
() -> this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +23,7 @@ import java.util.Map;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@ -44,6 +42,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
@ -59,9 +58,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
*/
|
*/
|
||||||
public class DefaultErrorViewResolverTests {
|
public class DefaultErrorViewResolverTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private DefaultErrorViewResolver resolver;
|
private DefaultErrorViewResolver resolver;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
@ -87,16 +83,16 @@ public class DefaultErrorViewResolverTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenApplicationContextIsNullShouldThrowException() {
|
public void createWhenApplicationContextIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("ApplicationContext must not be null");
|
() -> new DefaultErrorViewResolver(null, new ResourceProperties()))
|
||||||
new DefaultErrorViewResolver(null, new ResourceProperties());
|
.withMessageContaining("ApplicationContext must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWhenResourcePropertiesIsNullShouldThrowException() {
|
public void createWhenResourcePropertiesIsNullShouldThrowException() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("ResourceProperties must not be null");
|
() -> new DefaultErrorViewResolver(mock(ApplicationContext.class), null))
|
||||||
new DefaultErrorViewResolver(mock(ApplicationContext.class), null);
|
.withMessageContaining("ResourceProperties must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.webservices;
|
package org.springframework.boot.autoconfigure.webservices;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link WebServicesProperties}.
|
* Tests for {@link WebServicesProperties}.
|
||||||
|
@ -27,33 +27,29 @@ import org.junit.rules.ExpectedException;
|
||||||
*/
|
*/
|
||||||
public class WebServicesPropertiesTests {
|
public class WebServicesPropertiesTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private WebServicesProperties properties;
|
private WebServicesProperties properties;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathMustNotBeEmpty() {
|
public void pathMustNotBeEmpty() {
|
||||||
this.properties = new WebServicesProperties();
|
this.properties = new WebServicesProperties();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> this.properties.setPath(""))
|
||||||
this.thrown.expectMessage("Path must have length greater than 1");
|
.withMessageContaining("Path must have length greater than 1");
|
||||||
this.properties.setPath("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathMustHaveLengthGreaterThanOne() {
|
public void pathMustHaveLengthGreaterThanOne() {
|
||||||
this.properties = new WebServicesProperties();
|
this.properties = new WebServicesProperties();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Path must have length greater than 1");
|
.isThrownBy(() -> this.properties.setPath("/"))
|
||||||
this.properties.setPath("/");
|
.withMessageContaining("Path must have length greater than 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customPathMustBeginWithASlash() {
|
public void customPathMustBeginWithASlash() {
|
||||||
this.properties = new WebServicesProperties();
|
this.properties = new WebServicesProperties();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Path must start with '/'");
|
.isThrownBy(() -> this.properties.setPath("custom"))
|
||||||
this.properties.setPath("custom");
|
.withMessageContaining("Path must start with '/'");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.
|
||||||
|
@ -16,11 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.boot.cli;
|
package org.springframework.boot.cli;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests to exercise and reproduce specific issues.
|
* Integration tests to exercise and reproduce specific issues.
|
||||||
|
@ -34,9 +36,6 @@ public class ReproIntegrationTests {
|
||||||
@Rule
|
@Rule
|
||||||
public CliTester cli = new CliTester("src/test/resources/repro-samples/");
|
public CliTester cli = new CliTester("src/test/resources/repro-samples/");
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void grabAntBuilder() throws Exception {
|
public void grabAntBuilder() throws Exception {
|
||||||
this.cli.run("grab-ant-builder.groovy");
|
this.cli.run("grab-ant-builder.groovy");
|
||||||
|
@ -57,9 +56,9 @@ public class ReproIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jarFileExtensionNeeded() throws Exception {
|
public void jarFileExtensionNeeded() throws Exception {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatExceptionOfType(ExecutionException.class)
|
||||||
this.thrown.expectMessage("is not a JAR file");
|
.isThrownBy(() -> this.cli.jar("secure.groovy", "data-jpa.groovy"))
|
||||||
this.cli.jar("secure.groovy", "data-jpa.groovy");
|
.withMessageContaining("is not a JAR file");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +21,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@ -31,6 +29,7 @@ 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.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.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -43,9 +42,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class CommandRunnerTests {
|
public class CommandRunnerTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private CommandRunner commandRunner;
|
private CommandRunner commandRunner;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
@ -101,8 +97,8 @@ public class CommandRunnerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runWithoutArguments() throws Exception {
|
public void runWithoutArguments() throws Exception {
|
||||||
this.thrown.expect(NoArgumentsException.class);
|
assertThatExceptionOfType(NoArgumentsException.class)
|
||||||
this.commandRunner.run();
|
.isThrownBy(this.commandRunner::run);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -113,8 +109,8 @@ public class CommandRunnerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void missingCommand() throws Exception {
|
public void missingCommand() throws Exception {
|
||||||
this.thrown.expect(NoSuchCommandException.class);
|
assertThatExceptionOfType(NoSuchCommandException.class)
|
||||||
this.commandRunner.run("missing");
|
.isThrownBy(() -> this.commandRunner.run("missing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -188,14 +184,14 @@ public class CommandRunnerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void helpNoCommand() throws Exception {
|
public void helpNoCommand() throws Exception {
|
||||||
this.thrown.expect(NoHelpCommandArgumentsException.class);
|
assertThatExceptionOfType(NoHelpCommandArgumentsException.class)
|
||||||
this.commandRunner.run("help");
|
.isThrownBy(() -> this.commandRunner.run("help"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void helpUnknownCommand() throws Exception {
|
public void helpUnknownCommand() throws Exception {
|
||||||
this.thrown.expect(NoSuchCommandException.class);
|
assertThatExceptionOfType(NoSuchCommandException.class)
|
||||||
this.commandRunner.run("help", "missing");
|
.isThrownBy(() -> this.commandRunner.run("help", "missing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Call {
|
private enum Call {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,11 +18,10 @@ package org.springframework.boot.cli.command.init;
|
||||||
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
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.mockito.ArgumentMatchers.isA;
|
import static org.mockito.ArgumentMatchers.isA;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -34,9 +33,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final InitializrService invoker = new InitializrService(this.http);
|
private final InitializrService invoker = new InitializrService(this.http);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -81,18 +77,18 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
||||||
mockProjectGenerationError(400, jsonMessage);
|
mockProjectGenerationError(400, jsonMessage);
|
||||||
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
||||||
request.getDependencies().add("foo:bar");
|
request.getDependencies().add("foo:bar");
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage(jsonMessage);
|
.isThrownBy(() -> this.invoker.generate(request))
|
||||||
this.invoker.generate(request);
|
.withMessageContaining(jsonMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateProjectBadRequestNoExtraMessage() throws Exception {
|
public void generateProjectBadRequestNoExtraMessage() throws Exception {
|
||||||
mockProjectGenerationError(400, null);
|
mockProjectGenerationError(400, null);
|
||||||
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage("unexpected 400 error");
|
.isThrownBy(() -> this.invoker.generate(request))
|
||||||
this.invoker.generate(request);
|
.withMessageContaining("unexpected 400 error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -102,9 +98,9 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
||||||
mockStatus(response, 500);
|
mockStatus(response, 500);
|
||||||
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
|
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
|
||||||
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage("No content received from server");
|
.isThrownBy(() -> this.invoker.generate(request))
|
||||||
this.invoker.generate(request);
|
.withMessageContaining("No content received from server");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -112,9 +108,9 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
||||||
String jsonMessage = "whatever error on the server";
|
String jsonMessage = "whatever error on the server";
|
||||||
mockMetadataGetError(500, jsonMessage);
|
mockMetadataGetError(500, jsonMessage);
|
||||||
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage(jsonMessage);
|
.isThrownBy(() -> this.invoker.generate(request))
|
||||||
this.invoker.generate(request);
|
.withMessageContaining(jsonMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -124,9 +120,9 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
||||||
mockStatus(response, 200);
|
mockStatus(response, 200);
|
||||||
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
|
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
|
||||||
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage("Invalid content received from server");
|
.isThrownBy(() -> this.invoker.generate(request))
|
||||||
this.invoker.generate(request);
|
.withMessageContaining("Invalid content received from server");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -135,9 +131,9 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
|
||||||
mockStatus(response, 500);
|
mockStatus(response, 500);
|
||||||
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
|
given(this.http.execute(isA(HttpGet.class))).willReturn(response);
|
||||||
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
ProjectGenerationRequest request = new ProjectGenerationRequest();
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage("No content received from server");
|
.isThrownBy(() -> this.invoker.generate(request))
|
||||||
this.invoker.generate(request);
|
.withMessageContaining("No content received from server");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProjectGenerationResponse generateProject(ProjectGenerationRequest request,
|
private ProjectGenerationResponse generateProject(ProjectGenerationRequest request,
|
||||||
|
|
|
@ -25,15 +25,14 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.util.StreamUtils;
|
import org.springframework.util.StreamUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ProjectGenerationRequest}.
|
* Tests for {@link ProjectGenerationRequest}.
|
||||||
|
@ -45,9 +44,6 @@ public class ProjectGenerationRequestTests {
|
||||||
|
|
||||||
public static final Map<String, String> EMPTY_TAGS = Collections.emptyMap();
|
public static final Map<String, String> EMPTY_TAGS = Collections.emptyMap();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final ProjectGenerationRequest request = new ProjectGenerationRequest();
|
private final ProjectGenerationRequest request = new ProjectGenerationRequest();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -172,19 +168,19 @@ public class ProjectGenerationRequestTests {
|
||||||
public void buildNoMatch() throws Exception {
|
public void buildNoMatch() throws Exception {
|
||||||
InitializrServiceMetadata metadata = readMetadata();
|
InitializrServiceMetadata metadata = readMetadata();
|
||||||
setBuildAndFormat("does-not-exist", null);
|
setBuildAndFormat("does-not-exist", null);
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage("does-not-exist");
|
.isThrownBy(() -> this.request.generateUrl(metadata))
|
||||||
this.request.generateUrl(metadata);
|
.withMessageContaining("does-not-exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildMultipleMatch() throws Exception {
|
public void buildMultipleMatch() throws Exception {
|
||||||
InitializrServiceMetadata metadata = readMetadata("types-conflict");
|
InitializrServiceMetadata metadata = readMetadata("types-conflict");
|
||||||
setBuildAndFormat("gradle", null);
|
setBuildAndFormat("gradle", null);
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage("gradle-project");
|
.isThrownBy(() -> this.request.generateUrl(metadata))
|
||||||
this.thrown.expectMessage("gradle-project-2");
|
.withMessageContaining("gradle-project")
|
||||||
this.request.generateUrl(metadata);
|
.withMessageContaining("gradle-project-2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -207,15 +203,16 @@ public class ProjectGenerationRequestTests {
|
||||||
@Test
|
@Test
|
||||||
public void invalidType() {
|
public void invalidType() {
|
||||||
this.request.setType("does-not-exist");
|
this.request.setType("does-not-exist");
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.request.generateUrl(createDefaultMetadata());
|
.isThrownBy(() -> this.request.generateUrl(createDefaultMetadata()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noTypeAndNoDefault() throws Exception {
|
public void noTypeAndNoDefault() throws Exception {
|
||||||
this.thrown.expect(ReportableException.class);
|
assertThatExceptionOfType(ReportableException.class)
|
||||||
this.thrown.expectMessage("no default is defined");
|
.isThrownBy(
|
||||||
this.request.generateUrl(readMetadata("types-conflict"));
|
() -> this.request.generateUrl(readMetadata("types-conflict")))
|
||||||
|
.withMessageContaining("no default is defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static URI createUrl(String actionAndParam) {
|
private static URI createUrl(String actionAndParam) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,11 +18,9 @@ package org.springframework.boot.cli.command.run;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ -33,19 +31,16 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class SpringApplicationRunnerTests {
|
public class SpringApplicationRunnerTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exceptionMessageWhenSourcesContainsNoClasses() throws Exception {
|
public void exceptionMessageWhenSourcesContainsNoClasses() throws Exception {
|
||||||
SpringApplicationRunnerConfiguration configuration = mock(
|
SpringApplicationRunnerConfiguration configuration = mock(
|
||||||
SpringApplicationRunnerConfiguration.class);
|
SpringApplicationRunnerConfiguration.class);
|
||||||
given(configuration.getClasspath()).willReturn(new String[] { "foo", "bar" });
|
given(configuration.getClasspath()).willReturn(new String[] { "foo", "bar" });
|
||||||
given(configuration.getLogLevel()).willReturn(Level.INFO);
|
given(configuration.getLogLevel()).willReturn(Level.INFO);
|
||||||
this.thrown.expect(RuntimeException.class);
|
assertThatExceptionOfType(RuntimeException.class)
|
||||||
this.thrown.expectMessage(equalTo("No classes found in '[foo, bar]'"));
|
.isThrownBy(() -> new SpringApplicationRunner(configuration,
|
||||||
new SpringApplicationRunner(configuration, new String[] { "foo", "bar" })
|
new String[] { "foo", "bar" }).compileAndRun())
|
||||||
.compileAndRun();
|
.withMessage("No classes found in '[foo, bar]'");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,11 +17,10 @@
|
||||||
package org.springframework.boot.cli.compiler;
|
package org.springframework.boot.cli.compiler;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ExtendedGroovyClassLoader}.
|
* Tests for {@link ExtendedGroovyClassLoader}.
|
||||||
|
@ -30,9 +29,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class ExtendedGroovyClassLoaderTests {
|
public class ExtendedGroovyClassLoaderTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private ClassLoader contextClassLoader;
|
private ClassLoader contextClassLoader;
|
||||||
|
|
||||||
private ExtendedGroovyClassLoader defaultScopeGroovyClassLoader;
|
private ExtendedGroovyClassLoader defaultScopeGroovyClassLoader;
|
||||||
|
@ -54,9 +50,9 @@ public class ExtendedGroovyClassLoaderTests {
|
||||||
@Test
|
@Test
|
||||||
public void filtersNonGroovy() throws Exception {
|
public void filtersNonGroovy() throws Exception {
|
||||||
this.contextClassLoader.loadClass("org.springframework.util.StringUtils");
|
this.contextClassLoader.loadClass("org.springframework.util.StringUtils");
|
||||||
this.thrown.expect(ClassNotFoundException.class);
|
assertThatExceptionOfType(ClassNotFoundException.class)
|
||||||
this.defaultScopeGroovyClassLoader
|
.isThrownBy(() -> this.defaultScopeGroovyClassLoader
|
||||||
.loadClass("org.springframework.util.StringUtils");
|
.loadClass("org.springframework.util.StringUtils"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,7 @@ package org.springframework.boot.devtools;
|
||||||
|
|
||||||
import ch.qos.logback.classic.Logger;
|
import ch.qos.logback.classic.Logger;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@ -29,6 +27,7 @@ import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link RemoteUrlPropertyExtractor}.
|
* Tests for {@link RemoteUrlPropertyExtractor}.
|
||||||
|
@ -37,9 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class RemoteUrlPropertyExtractorTests {
|
public class RemoteUrlPropertyExtractorTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void preventRunFailuresFromPollutingLoggerContext() {
|
public void preventRunFailuresFromPollutingLoggerContext() {
|
||||||
((Logger) LoggerFactory.getLogger(RemoteUrlPropertyExtractorTests.class))
|
((Logger) LoggerFactory.getLogger(RemoteUrlPropertyExtractorTests.class))
|
||||||
|
@ -48,24 +44,23 @@ public class RemoteUrlPropertyExtractorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void missingUrl() {
|
public void missingUrl() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(() -> doTest())
|
||||||
this.thrown.expectMessage("No remote URL specified");
|
.withMessageContaining("No remote URL specified");
|
||||||
doTest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void malformedUrl() {
|
public void malformedUrl() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException().isThrownBy(() -> doTest("::://wibble"))
|
||||||
this.thrown.expectMessage("Malformed URL '::://wibble'");
|
.withMessageContaining("Malformed URL '::://wibble'");
|
||||||
doTest("::://wibble");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleUrls() {
|
public void multipleUrls() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Multiple URLs specified");
|
.isThrownBy(
|
||||||
doTest("http://localhost:8080", "http://localhost:9090");
|
() -> doTest("http://localhost:8080", "http://localhost:9090"))
|
||||||
|
.withMessageContaining("Multiple URLs specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.apache.jasper.EmbeddedServletOptions;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
|
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
|
||||||
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
@ -56,6 +55,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
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.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
|
@ -71,9 +71,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class LocalDevToolsAutoConfigurationTests {
|
public class LocalDevToolsAutoConfigurationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public MockRestarter mockRestarter = new MockRestarter();
|
public MockRestarter mockRestarter = new MockRestarter();
|
||||||
|
|
||||||
|
@ -168,8 +165,8 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
properties.put("spring.devtools.livereload.enabled", false);
|
properties.put("spring.devtools.livereload.enabled", false);
|
||||||
this.context = initializeAndRun(Config.class, properties);
|
this.context = initializeAndRun(Config.class, properties);
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(OptionalLiveReloadServer.class);
|
.isThrownBy(() -> this.context.getBean(OptionalLiveReloadServer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -203,8 +200,8 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
properties.put("spring.devtools.restart.enabled", false);
|
properties.put("spring.devtools.restart.enabled", false);
|
||||||
this.context = initializeAndRun(Config.class, properties);
|
this.context = initializeAndRun(Config.class, properties);
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(ClassPathFileSystemWatcher.class);
|
.isThrownBy(() -> this.context.getBean(ClassPathFileSystemWatcher.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,7 +20,6 @@ import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||||
|
@ -41,6 +40,7 @@ import org.springframework.mock.web.MockServletContext;
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
|
|
||||||
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.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,9 +58,6 @@ public class RemoteDevToolsAutoConfigurationTests {
|
||||||
@Rule
|
@Rule
|
||||||
public MockRestarter mockRestarter = new MockRestarter();
|
public MockRestarter mockRestarter = new MockRestarter();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private AnnotationConfigWebApplicationContext context;
|
private AnnotationConfigWebApplicationContext context;
|
||||||
|
|
||||||
private MockHttpServletRequest request;
|
private MockHttpServletRequest request;
|
||||||
|
@ -86,8 +83,8 @@ public class RemoteDevToolsAutoConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void disabledIfRemoteSecretIsMissing() {
|
public void disabledIfRemoteSecretIsMissing() {
|
||||||
loadContext("a:b");
|
loadContext("a:b");
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(DispatcherFilter.class);
|
.isThrownBy(() -> this.context.getBean(DispatcherFilter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -144,8 +141,8 @@ public class RemoteDevToolsAutoConfigurationTests {
|
||||||
public void disableRestart() {
|
public void disableRestart() {
|
||||||
loadContext("spring.devtools.remote.secret:supersecret",
|
loadContext("spring.devtools.remote.secret:supersecret",
|
||||||
"spring.devtools.remote.restart.enabled:false");
|
"spring.devtools.remote.restart.enabled:false");
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean("remoteRestartHandlerMapper");
|
.isThrownBy(() -> this.context.getBean("remoteRestartHandlerMapper"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.io.File;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link TriggerFileFilter}.
|
* Tests for {@link TriggerFileFilter}.
|
||||||
|
@ -32,17 +32,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class TriggerFileFilterTests {
|
public class TriggerFileFilterTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temp = new TemporaryFolder();
|
public TemporaryFolder temp = new TemporaryFolder();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nameMustNotBeNull() {
|
public void nameMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> new TriggerFileFilter(null))
|
||||||
this.thrown.expectMessage("Name must not be null");
|
.withMessageContaining("Name must not be null");
|
||||||
new TriggerFileFilter(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,13 +19,12 @@ package org.springframework.boot.devtools.classpath;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.boot.devtools.filewatch.ChangedFiles;
|
import org.springframework.boot.devtools.filewatch.ChangedFiles;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ClassPathChangedEvent}.
|
* Tests for {@link ClassPathChangedEvent}.
|
||||||
|
@ -34,16 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class ClassPathChangedEventTests {
|
public class ClassPathChangedEventTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private Object source = new Object();
|
private Object source = new Object();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void changeSetMustNotBeNull() {
|
public void changeSetMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("ChangeSet must not be null");
|
.isThrownBy(() -> new ClassPathChangedEvent(this.source, null, false))
|
||||||
new ClassPathChangedEvent(this.source, null, false);
|
.withMessageContaining("ChangeSet must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +22,7 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
@ -37,6 +35,7 @@ import org.springframework.context.ApplicationEvent;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -48,9 +47,6 @@ import static org.mockito.Mockito.verify;
|
||||||
*/
|
*/
|
||||||
public class ClassPathFileChangeListenerTests {
|
public class ClassPathFileChangeListenerTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ApplicationEventPublisher eventPublisher;
|
private ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
|
@ -70,18 +66,18 @@ public class ClassPathFileChangeListenerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void eventPublisherMustNotBeNull() {
|
public void eventPublisherMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("EventPublisher must not be null");
|
.isThrownBy(() -> new ClassPathFileChangeListener(null,
|
||||||
new ClassPathFileChangeListener(null, this.restartStrategy,
|
this.restartStrategy, this.fileSystemWatcher))
|
||||||
this.fileSystemWatcher);
|
.withMessageContaining("EventPublisher must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void restartStrategyMustNotBeNull() {
|
public void restartStrategyMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("RestartStrategy must not be null");
|
.isThrownBy(() -> new ClassPathFileChangeListener(this.eventPublisher,
|
||||||
new ClassPathFileChangeListener(this.eventPublisher, null,
|
null, this.fileSystemWatcher))
|
||||||
this.fileSystemWatcher);
|
.withMessageContaining("RestartStrategy must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import org.springframework.boot.devtools.filewatch.FileSystemWatcher;
|
import org.springframework.boot.devtools.filewatch.FileSystemWatcher;
|
||||||
|
@ -40,6 +39,7 @@ import org.springframework.core.env.MapPropertySource;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,19 +49,16 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class ClassPathFileSystemWatcherTests {
|
public class ClassPathFileSystemWatcherTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temp = new TemporaryFolder();
|
public TemporaryFolder temp = new TemporaryFolder();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void urlsMustNotBeNull() {
|
public void urlsMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Urls must not be null");
|
.isThrownBy(() -> new ClassPathFileSystemWatcher(
|
||||||
URL[] urls = null;
|
mock(FileSystemWatcherFactory.class),
|
||||||
new ClassPathFileSystemWatcher(mock(FileSystemWatcherFactory.class),
|
mock(ClassPathRestartStrategy.class), (URL[]) null))
|
||||||
mock(ClassPathRestartStrategy.class), urls);
|
.withMessageContaining("Urls must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -21,9 +21,7 @@ import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@ -38,6 +36,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for the configuration of development-time properties
|
* Integration tests for the configuration of development-time properties
|
||||||
|
@ -46,9 +45,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class DevToolPropertiesIntegrationTests {
|
public class DevToolPropertiesIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -90,8 +86,8 @@ public class DevToolPropertiesIntegrationTests {
|
||||||
BeanConditionConfiguration.class);
|
BeanConditionConfiguration.class);
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
application.setWebApplicationType(WebApplicationType.NONE);
|
||||||
this.context = application.run();
|
this.context = application.run();
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(MyBean.class);
|
.isThrownBy(() -> this.context.getBean(MyBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.io.File;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ChangedFile}.
|
* Tests for {@link ChangedFile}.
|
||||||
|
@ -34,31 +34,28 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class ChangedFileTests {
|
public class ChangedFileTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temp = new TemporaryFolder();
|
public TemporaryFolder temp = new TemporaryFolder();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sourceFolderMustNotBeNull() throws Exception {
|
public void sourceFolderMustNotBeNull() throws Exception {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("SourceFolder must not be null");
|
.isThrownBy(() -> new ChangedFile(null, this.temp.newFile(), Type.ADD))
|
||||||
new ChangedFile(null, this.temp.newFile(), Type.ADD);
|
.withMessageContaining("SourceFolder must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fileMustNotBeNull() throws Exception {
|
public void fileMustNotBeNull() throws Exception {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("File must not be null");
|
.isThrownBy(() -> new ChangedFile(this.temp.newFolder(), null, Type.ADD))
|
||||||
new ChangedFile(this.temp.newFolder(), null, Type.ADD);
|
.withMessageContaining("File must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void typeMustNotBeNull() throws Exception {
|
public void typeMustNotBeNull() throws Exception {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("Type must not be null");
|
() -> new ChangedFile(this.temp.newFile(), this.temp.newFolder(), null))
|
||||||
new ChangedFile(this.temp.newFile(), this.temp.newFolder(), null);
|
.withMessageContaining("Type must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,12 +23,12 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link FileSnapshot}.
|
* Tests for {@link FileSnapshot}.
|
||||||
|
@ -42,24 +42,20 @@ public class FileSnapshotTests {
|
||||||
private static final long MODIFIED = new Date().getTime()
|
private static final long MODIFIED = new Date().getTime()
|
||||||
- TimeUnit.DAYS.toMillis(10);
|
- TimeUnit.DAYS.toMillis(10);
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fileMustNotBeNull() {
|
public void fileMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> new FileSnapshot(null))
|
||||||
this.thrown.expectMessage("File must not be null");
|
.withMessageContaining("File must not be null");
|
||||||
new FileSnapshot(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fileMustNotBeAFolder() throws Exception {
|
public void fileMustNotBeAFolder() throws Exception {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("File must not be a folder");
|
.isThrownBy(() -> new FileSnapshot(this.temporaryFolder.newFolder()))
|
||||||
new FileSnapshot(this.temporaryFolder.newFolder());
|
.withMessageContaining("File must not be a folder");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -30,13 +30,14 @@ import java.util.Set;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,9 +47,6 @@ import static org.mockito.Mockito.mock;
|
||||||
*/
|
*/
|
||||||
public class FileSystemWatcherTests {
|
public class FileSystemWatcherTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private FileSystemWatcher watcher;
|
private FileSystemWatcher watcher;
|
||||||
|
|
||||||
private List<Set<ChangedFiles>> changes = Collections
|
private List<Set<ChangedFiles>> changes = Collections
|
||||||
|
@ -64,62 +62,66 @@ public class FileSystemWatcherTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pollIntervalMustBePositive() {
|
public void pollIntervalMustBePositive() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("PollInterval must be positive");
|
.isThrownBy(() -> new FileSystemWatcher(true, Duration.ofMillis(0),
|
||||||
new FileSystemWatcher(true, Duration.ofMillis(0), Duration.ofMillis(1));
|
Duration.ofMillis(1)))
|
||||||
|
.withMessageContaining("PollInterval must be positive");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void quietPeriodMustBePositive() {
|
public void quietPeriodMustBePositive() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("QuietPeriod must be positive");
|
.isThrownBy(() -> new FileSystemWatcher(true, Duration.ofMillis(1),
|
||||||
new FileSystemWatcher(true, Duration.ofMillis(1), Duration.ofMillis(0));
|
Duration.ofMillis(0)))
|
||||||
|
.withMessageContaining("QuietPeriod must be positive");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pollIntervalMustBeGreaterThanQuietPeriod() {
|
public void pollIntervalMustBeGreaterThanQuietPeriod() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("PollInterval must be greater than QuietPeriod");
|
.isThrownBy(() -> new FileSystemWatcher(true, Duration.ofMillis(1),
|
||||||
new FileSystemWatcher(true, Duration.ofMillis(1), Duration.ofMillis(1));
|
Duration.ofMillis(1)))
|
||||||
|
.withMessageContaining("PollInterval must be greater than QuietPeriod");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void listenerMustNotBeNull() {
|
public void listenerMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("FileChangeListener must not be null");
|
.isThrownBy(() -> this.watcher.addListener(null))
|
||||||
this.watcher.addListener(null);
|
.withMessageContaining("FileChangeListener must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cannotAddListenerToStartedListener() {
|
public void cannotAddListenerToStartedListener() {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
|
||||||
this.thrown.expectMessage("FileSystemWatcher already started");
|
|
||||||
this.watcher.start();
|
this.watcher.start();
|
||||||
this.watcher.addListener(mock(FileChangeListener.class));
|
assertThatIllegalStateException()
|
||||||
|
.isThrownBy(
|
||||||
|
() -> this.watcher.addListener(mock(FileChangeListener.class)))
|
||||||
|
.withMessageContaining("FileSystemWatcher already started");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sourceFolderMustNotBeNull() {
|
public void sourceFolderMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Folder must not be null");
|
.isThrownBy(() -> this.watcher.addSourceFolder(null))
|
||||||
this.watcher.addSourceFolder(null);
|
.withMessageContaining("Folder must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sourceFolderMustNotBeAFile() {
|
public void sourceFolderMustNotBeAFile() {
|
||||||
File folder = new File("pom.xml");
|
File folder = new File("pom.xml");
|
||||||
assertThat(folder.isFile()).isTrue();
|
assertThat(folder.isFile()).isTrue();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Folder 'pom.xml' must not be a file");
|
.isThrownBy(() -> this.watcher.addSourceFolder(new File("pom.xml")))
|
||||||
this.watcher.addSourceFolder(new File("pom.xml"));
|
.withMessageContaining("Folder 'pom.xml' must not be a file");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cannotAddSourceFolderToStartedListener() throws Exception {
|
public void cannotAddSourceFolderToStartedListener() throws Exception {
|
||||||
this.thrown.expect(IllegalStateException.class);
|
|
||||||
this.thrown.expectMessage("FileSystemWatcher already started");
|
|
||||||
this.watcher.start();
|
this.watcher.start();
|
||||||
this.watcher.addSourceFolder(this.temp.newFolder());
|
assertThatIllegalStateException()
|
||||||
|
.isThrownBy(() -> this.watcher.addSourceFolder(this.temp.newFolder()))
|
||||||
|
.withMessageContaining("FileSystemWatcher already started");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -22,13 +22,13 @@ import java.io.IOException;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
import org.springframework.boot.devtools.filewatch.ChangedFile.Type;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link FolderSnapshot}.
|
* Tests for {@link FolderSnapshot}.
|
||||||
|
@ -37,9 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class FolderSnapshotTests {
|
public class FolderSnapshotTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
|
||||||
|
@ -55,17 +52,15 @@ public class FolderSnapshotTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void folderMustNotBeNull() {
|
public void folderMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> new FolderSnapshot(null))
|
||||||
this.thrown.expectMessage("Folder must not be null");
|
.withMessageContaining("Folder must not be null");
|
||||||
new FolderSnapshot(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void folderMustNotBeFile() throws Exception {
|
public void folderMustNotBeFile() throws Exception {
|
||||||
File file = this.temporaryFolder.newFile();
|
File file = this.temporaryFolder.newFile();
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> new FolderSnapshot(file))
|
||||||
this.thrown.expectMessage("Folder '" + file + "' must not be a file");
|
.withMessageContaining("Folder '" + file + "' must not be a file");
|
||||||
new FolderSnapshot(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -106,17 +101,18 @@ public class FolderSnapshotTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getChangedFilesSnapshotMustNotBeNull() {
|
public void getChangedFilesSnapshotMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Snapshot must not be null");
|
.isThrownBy(() -> this.initialSnapshot.getChangedFiles(null, null))
|
||||||
this.initialSnapshot.getChangedFiles(null, null);
|
.withMessageContaining("Snapshot must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getChangedFilesSnapshotMustBeTheSameSourceFolder() throws Exception {
|
public void getChangedFilesSnapshotMustBeTheSameSourceFolder() throws Exception {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Snapshot source folder must be '" + this.folder + "'");
|
.isThrownBy(() -> this.initialSnapshot.getChangedFiles(
|
||||||
this.initialSnapshot
|
new FolderSnapshot(createTestFolderStructure()), null))
|
||||||
.getChangedFiles(new FolderSnapshot(createTestFolderStructure()), null);
|
.withMessageContaining(
|
||||||
|
"Snapshot source folder must be '" + this.folder + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,11 +21,10 @@ import java.io.FilterInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ConnectionInputStream}.
|
* Tests for {@link ConnectionInputStream}.
|
||||||
|
@ -37,9 +36,6 @@ public class ConnectionInputStreamTests {
|
||||||
|
|
||||||
private static final byte[] NO_BYTES = {};
|
private static final byte[] NO_BYTES = {};
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readHeader() throws Exception {
|
public void readHeader() throws Exception {
|
||||||
String header = "";
|
String header = "";
|
||||||
|
@ -68,19 +64,18 @@ public class ConnectionInputStreamTests {
|
||||||
public void checkedRead() throws Exception {
|
public void checkedRead() throws Exception {
|
||||||
ConnectionInputStream inputStream = new ConnectionInputStream(
|
ConnectionInputStream inputStream = new ConnectionInputStream(
|
||||||
new ByteArrayInputStream(NO_BYTES));
|
new ByteArrayInputStream(NO_BYTES));
|
||||||
this.thrown.expect(IOException.class);
|
assertThatIOException().isThrownBy(inputStream::checkedRead)
|
||||||
this.thrown.expectMessage("End of stream");
|
.withMessageContaining("End of stream");
|
||||||
inputStream.checkedRead();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkedReadArray() throws Exception {
|
public void checkedReadArray() throws Exception {
|
||||||
|
byte[] buffer = new byte[100];
|
||||||
ConnectionInputStream inputStream = new ConnectionInputStream(
|
ConnectionInputStream inputStream = new ConnectionInputStream(
|
||||||
new ByteArrayInputStream(NO_BYTES));
|
new ByteArrayInputStream(NO_BYTES));
|
||||||
this.thrown.expect(IOException.class);
|
assertThatIOException()
|
||||||
this.thrown.expectMessage("End of stream");
|
.isThrownBy(() -> inputStream.checkedRead(buffer, 0, buffer.length))
|
||||||
byte[] buffer = new byte[100];
|
.withMessageContaining("End of stream");
|
||||||
inputStream.checkedRead(buffer, 0, buffer.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LimitedInputStream extends FilterInputStream {
|
private static class LimitedInputStream extends FilterInputStream {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link Frame}.
|
* Tests for {@link Frame}.
|
||||||
|
@ -33,21 +33,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class FrameTests {
|
public class FrameTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void payloadMustNotBeNull() {
|
public void payloadMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(() -> new Frame((String) null))
|
||||||
this.thrown.expectMessage("Payload must not be null");
|
.withMessageContaining("Payload must not be null");
|
||||||
new Frame((String) null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void typeMustNotBeNull() {
|
public void typeMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Type must not be null");
|
.isThrownBy(() -> new Frame((Frame.Type) null))
|
||||||
new Frame((Frame.Type) null);
|
.withMessageContaining("Type must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -92,17 +88,17 @@ public class FrameTests {
|
||||||
@Test
|
@Test
|
||||||
public void readFragmentedNotSupported() throws Exception {
|
public void readFragmentedNotSupported() throws Exception {
|
||||||
byte[] bytes = new byte[] { 0x0F };
|
byte[] bytes = new byte[] { 0x0F };
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Fragmented frames are not supported");
|
.isThrownBy(() -> Frame.read(newConnectionInputStream(bytes)))
|
||||||
Frame.read(newConnectionInputStream(bytes));
|
.withMessageContaining("Fragmented frames are not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readLargeFramesNotSupported() throws Exception {
|
public void readLargeFramesNotSupported() throws Exception {
|
||||||
byte[] bytes = new byte[] { (byte) 0x80, (byte) 0xFF };
|
byte[] bytes = new byte[] { (byte) 0x80, (byte) 0xFF };
|
||||||
this.thrown.expect(IllegalStateException.class);
|
assertThatIllegalStateException()
|
||||||
this.thrown.expectMessage("Large frames are not supported");
|
.isThrownBy(() -> Frame.read(newConnectionInputStream(bytes)))
|
||||||
Frame.read(newConnectionInputStream(bytes));
|
.withMessageContaining("Large frames are not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -29,7 +29,6 @@ import java.util.Set;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import org.springframework.boot.devtools.classpath.ClassPathChangedEvent;
|
import org.springframework.boot.devtools.classpath.ClassPathChangedEvent;
|
||||||
|
@ -46,6 +45,7 @@ import org.springframework.mock.http.client.MockClientHttpRequest;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ClassPathChangeUploader}.
|
* Tests for {@link ClassPathChangeUploader}.
|
||||||
|
@ -55,9 +55,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class ClassPathChangeUploaderTests {
|
public class ClassPathChangeUploaderTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temp = new TemporaryFolder();
|
public TemporaryFolder temp = new TemporaryFolder();
|
||||||
|
|
||||||
|
@ -74,30 +71,32 @@ public class ClassPathChangeUploaderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void urlMustNotBeNull() {
|
public void urlMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("URL must not be empty");
|
.isThrownBy(() -> new ClassPathChangeUploader(null, this.requestFactory))
|
||||||
new ClassPathChangeUploader(null, this.requestFactory);
|
.withMessageContaining("URL must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void urlMustNotBeEmpty() {
|
public void urlMustNotBeEmpty() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("URL must not be empty");
|
.isThrownBy(() -> new ClassPathChangeUploader("", this.requestFactory))
|
||||||
new ClassPathChangeUploader("", this.requestFactory);
|
.withMessageContaining("URL must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestFactoryMustNotBeNull() {
|
public void requestFactoryMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("RequestFactory must not be null");
|
.isThrownBy(
|
||||||
new ClassPathChangeUploader("http://localhost:8080", null);
|
() -> new ClassPathChangeUploader("http://localhost:8080", null))
|
||||||
|
.withMessageContaining("RequestFactory must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void urlMustNotBeMalformed() {
|
public void urlMustNotBeMalformed() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Malformed URL 'htttttp:///ttest'");
|
.isThrownBy(() -> new ClassPathChangeUploader("htttttp:///ttest",
|
||||||
new ClassPathChangeUploader("htttttp:///ttest", this.requestFactory);
|
this.requestFactory))
|
||||||
|
.withMessageContaining("Malformed URL 'htttttp:///ttest'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,9 +20,7 @@ import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@ -34,6 +32,7 @@ import org.springframework.http.client.ClientHttpRequestFactory;
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@ -47,9 +46,6 @@ public class DelayedLiveReloadTriggerTests {
|
||||||
|
|
||||||
private static final String URL = "http://localhost:8080";
|
private static final String URL = "http://localhost:8080";
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private OptionalLiveReloadServer liveReloadServer;
|
private OptionalLiveReloadServer liveReloadServer;
|
||||||
|
|
||||||
|
@ -84,30 +80,32 @@ public class DelayedLiveReloadTriggerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void liveReloadServerMustNotBeNull() {
|
public void liveReloadServerMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("LiveReloadServer must not be null");
|
() -> new DelayedLiveReloadTrigger(null, this.requestFactory, URL))
|
||||||
new DelayedLiveReloadTrigger(null, this.requestFactory, URL);
|
.withMessageContaining("LiveReloadServer must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestFactoryMustNotBeNull() {
|
public void requestFactoryMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException().isThrownBy(
|
||||||
this.thrown.expectMessage("RequestFactory must not be null");
|
() -> new DelayedLiveReloadTrigger(this.liveReloadServer, null, URL))
|
||||||
new DelayedLiveReloadTrigger(this.liveReloadServer, null, URL);
|
.withMessageContaining("RequestFactory must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void urlMustNotBeNull() {
|
public void urlMustNotBeNull() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("URL must not be empty");
|
.isThrownBy(() -> new DelayedLiveReloadTrigger(this.liveReloadServer,
|
||||||
new DelayedLiveReloadTrigger(this.liveReloadServer, this.requestFactory, null);
|
this.requestFactory, null))
|
||||||
|
.withMessageContaining("URL must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void urlMustNotBeEmpty() {
|
public void urlMustNotBeEmpty() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("URL must not be empty");
|
.isThrownBy(() -> new DelayedLiveReloadTrigger(this.liveReloadServer,
|
||||||
new DelayedLiveReloadTrigger(this.liveReloadServer, this.requestFactory, "");
|
this.requestFactory, ""))
|
||||||
|
.withMessageContaining("URL must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 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,7 @@ package org.springframework.boot.devtools.remote.client;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
@ -32,6 +30,7 @@ import org.springframework.http.server.ServletServerHttpRequest;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,9 +41,6 @@ import static org.mockito.BDDMockito.given;
|
||||||
*/
|
*/
|
||||||
public class HttpHeaderInterceptorTests {
|
public class HttpHeaderInterceptorTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
@ -77,30 +73,30 @@ public class HttpHeaderInterceptorTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorNullHeaderName() {
|
public void constructorNullHeaderName() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Name must not be empty");
|
.isThrownBy(() -> new HttpHeaderInterceptor(null, this.value))
|
||||||
new HttpHeaderInterceptor(null, this.value);
|
.withMessageContaining("Name must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorEmptyHeaderName() {
|
public void constructorEmptyHeaderName() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Name must not be empty");
|
.isThrownBy(() -> new HttpHeaderInterceptor("", this.value))
|
||||||
new HttpHeaderInterceptor("", this.value);
|
.withMessageContaining("Name must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorNullHeaderValue() {
|
public void constructorNullHeaderValue() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Value must not be empty");
|
.isThrownBy(() -> new HttpHeaderInterceptor(this.name, null))
|
||||||
new HttpHeaderInterceptor(this.name, null);
|
.withMessageContaining("Value must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorEmptyHeaderValue() {
|
public void constructorEmptyHeaderValue() {
|
||||||
this.thrown.expect(IllegalArgumentException.class);
|
assertThatIllegalArgumentException()
|
||||||
this.thrown.expectMessage("Value must not be empty");
|
.isThrownBy(() -> new HttpHeaderInterceptor(this.name, ""))
|
||||||
new HttpHeaderInterceptor(this.name, "");
|
.withMessageContaining("Value must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
@ -49,6 +48,7 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||||
import org.springframework.http.server.ServerHttpResponse;
|
import org.springframework.http.server.ServerHttpResponse;
|
||||||
|
|
||||||
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.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.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
@ -67,9 +67,6 @@ public class RemoteClientConfigurationTests {
|
||||||
@Rule
|
@Rule
|
||||||
public OutputCapture output = new OutputCapture();
|
public OutputCapture output = new OutputCapture();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private AnnotationConfigServletWebServerApplicationContext context;
|
private AnnotationConfigServletWebServerApplicationContext context;
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext clientContext;
|
private AnnotationConfigApplicationContext clientContext;
|
||||||
|
@ -104,9 +101,9 @@ public class RemoteClientConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void failIfNoSecret() {
|
public void failIfNoSecret() {
|
||||||
this.thrown.expect(BeanCreationException.class);
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
this.thrown.expectMessage("required to secure your connection");
|
.isThrownBy(() -> configure("http://localhost", false))
|
||||||
configure("http://localhost", false);
|
.withMessageContaining("required to secure your connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -126,15 +123,15 @@ public class RemoteClientConfigurationTests {
|
||||||
@Test
|
@Test
|
||||||
public void liveReloadDisabled() {
|
public void liveReloadDisabled() {
|
||||||
configure("spring.devtools.livereload.enabled:false");
|
configure("spring.devtools.livereload.enabled:false");
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(OptionalLiveReloadServer.class);
|
.isThrownBy(() -> this.context.getBean(OptionalLiveReloadServer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void remoteRestartDisabled() {
|
public void remoteRestartDisabled() {
|
||||||
configure("spring.devtools.remote.restart.enabled:false");
|
configure("spring.devtools.remote.restart.enabled:false");
|
||||||
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
|
||||||
this.context.getBean(ClassPathFileSystemWatcher.class);
|
.isThrownBy(() -> this.context.getBean(ClassPathFileSystemWatcher.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configure(String... pairs) {
|
private void configure(String... pairs) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue