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