pull/20857/head
Phillip Webb 5 years ago
parent 1640add8be
commit 3ca896e63f

@ -45,7 +45,6 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnBean(RestClient.class)
@ConditionalOnEnabledHealthIndicator("elasticsearch")
@AutoConfigureAfter(RestClientAutoConfiguration.class)
@SuppressWarnings("deprecation")
public class ElasticSearchRestHealthContributorAutoConfiguration
extends CompositeHealthContributorConfiguration<ElasticsearchRestHealthIndicator, RestClient> {

@ -164,11 +164,11 @@ public final class EndpointRequest {
}
private EndpointServerWebExchangeMatcher(Class<?>[] endpoints, boolean includeLinks) {
this(Arrays.asList(endpoints), Collections.emptyList(), includeLinks);
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(), includeLinks);
}
private EndpointServerWebExchangeMatcher(String[] endpoints, boolean includeLinks) {
this(Arrays.asList(endpoints), Collections.emptyList(), includeLinks);
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(), includeLinks);
}
private EndpointServerWebExchangeMatcher(List<Object> includes, List<Object> excludes, boolean includeLinks) {

@ -196,11 +196,11 @@ public final class EndpointRequest {
}
private EndpointRequestMatcher(Class<?>[] endpoints, boolean includeLinks) {
this(Arrays.asList(endpoints), Collections.emptyList(), includeLinks);
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(), includeLinks);
}
private EndpointRequestMatcher(String[] endpoints, boolean includeLinks) {
this(Arrays.asList(endpoints), Collections.emptyList(), includeLinks);
this(Arrays.asList((Object[]) endpoints), Collections.emptyList(), includeLinks);
}
private EndpointRequestMatcher(List<Object> includes, List<Object> excludes, boolean includeLinks) {

@ -186,7 +186,7 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
* @param prefix the prefix
* @return the serialized instance
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({ "unchecked" })
private Map<String, Object> safeSerialize(ObjectMapper mapper, Object bean, String prefix) {
try {
return new HashMap<>(mapper.convertValue(bean, Map.class));

@ -162,12 +162,10 @@ public class JerseyEndpointResourceFactory {
}
}
@SuppressWarnings("unchecked")
private Map<String, Object> extractBodyArguments(ContainerRequestContext data) {
Map<String, Object> entity = ((ContainerRequest) data).readEntity(Map.class);
if (entity == null) {
return Collections.emptyMap();
}
return entity;
return (entity != null) ? entity : Collections.emptyMap();
}
private Map<String, Object> extractPathParameters(ContainerRequestContext requestContext) {

@ -20,8 +20,10 @@ import com.couchbase.client.java.env.ClusterEnvironment;
/**
* Callback interface that can be implemented by beans wishing to customize the
* {@link ClusterEnvironment} via a {@link ClusterEnvironment.Builder} whilst retaining
* default auto-configuration.whilst retaining default auto-configuration.
* {@link ClusterEnvironment} via a
* {@link com.couchbase.client.java.env.ClusterEnvironment.Builder
* ClusterEnvironment.Builder} whilst retaining default auto-configuration.whilst
* retaining default auto-configuration.
*
* @author Stephane Nicoll
* @since 2.3.0
@ -30,7 +32,8 @@ import com.couchbase.client.java.env.ClusterEnvironment;
public interface ClusterEnvironmentBuilderCustomizer {
/**
* Customize the {@link ClusterEnvironment.Builder}.
* Customize the {@link com.couchbase.client.java.env.ClusterEnvironment.Builder
* ClusterEnvironment.Builder}.
* @param builder the builder to customize
*/
void customize(ClusterEnvironment.Builder builder);

@ -33,6 +33,7 @@ import org.springframework.util.Assert;
/**
* Base class for setup that is common to MongoDB client factories.
*
* @param <T> the mongo client type
* @author Christoph Strobl
* @author Scott Frederick
* @since 2.3.0

@ -136,8 +136,8 @@ public final class ConnectionFactoryBuilder {
static class ConnectionFactoryOptionsInitializer {
/**
* Initialize a {@link ConnectionFactoryOptions.Builder} using the specified
* properties.
* Initialize a {@link io.r2dbc.spi.ConnectionFactoryOptions.Builder
* ConnectionFactoryOptions.Builder} using the specified properties.
* @param properties the properties to use to initialize the builder
* @param embeddedDatabaseConnection the embedded connection to use as a fallback
* @return an initialized builder

@ -169,6 +169,7 @@ public class UndertowWebServerFactoryCustomizer
return (value) -> this.factory.addBuilderCustomizers((builder) -> builder.setSocketOption(option, value));
}
@SuppressWarnings("unchecked")
<T> Consumer<Map<String, String>> forEach(Function<Option<T>, Consumer<T>> function) {
return (map) -> map.forEach((key, value) -> {
Option<T> option = (Option<T>) NAME_LOOKUP.get(getCanonicalName(key));

@ -19,9 +19,6 @@ package org.springframework.boot.autoconfigure.web.format;
import java.time.format.DateTimeFormatter;
import java.time.format.ResolverStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.format.datetime.DateFormatterRegistrar;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
@ -49,8 +46,6 @@ public class WebConversionService extends DefaultFormattingConversionService {
private static final boolean JSR_354_PRESENT = ClassUtils.isPresent("javax.money.MonetaryAmount",
WebConversionService.class.getClassLoader());
private static final Log logger = LogFactory.getLog(WebConversionService.class);
private final String dateFormat;
/**

@ -64,6 +64,7 @@ import static org.testcontainers.shaded.org.apache.commons.codec.binary.Base64.e
* Temporary copy of TestContainers's Couchbase support until it works against Couchbase
* SDK v3.
*/
@SuppressWarnings("resource")
class CouchbaseContainer extends GenericContainer<CouchbaseContainer> {
public static final String VERSION = "5.5.1";
@ -198,7 +199,6 @@ class CouchbaseContainer extends GenericContainer<CouchbaseContainer> {
}
@Override
@SuppressWarnings({ "unchecked", "ConstantConditions" })
public void stop() {
try {
stopCluster();

@ -667,6 +667,7 @@ class KafkaAutoConfigurationTests {
@Configuration(proxyBeanMethods = false)
static class ConsumerFactoryConfiguration {
@SuppressWarnings("unchecked")
private final ConsumerFactory<String, Object> consumerFactory = mock(ConsumerFactory.class);
@Bean

@ -42,6 +42,7 @@ import static org.mockito.Mockito.verify;
/**
* Tests for {@link MongoClientFactorySupport}.
*
* @param <T> the mongo client type
* @author Phillip Webb
* @author Andy Wilkinson
* @author Stephane Nicoll

@ -167,10 +167,8 @@ class R2dbcAutoConfigurationTests {
this.contextRunner.withPropertyValues("spring.r2dbc.pool.enabled=false", "spring.r2dbc.url:r2dbc:simple://foo",
"spring.r2dbc.properties.test=value", "spring.r2dbc.properties.another=2").run((context) -> {
SimpleTestConnectionFactory connectionFactory = context.getBean(SimpleTestConnectionFactory.class);
assertThat((Object) connectionFactory.options.getRequiredValue(Option.valueOf("test")))
.isEqualTo("value");
assertThat((Object) connectionFactory.options.getRequiredValue(Option.valueOf("another")))
.isEqualTo("2");
assertThat(getRequiredOptionsValue(connectionFactory, "test")).isEqualTo("value");
assertThat(getRequiredOptionsValue(connectionFactory, "another")).isEqualTo("2");
});
}
@ -181,13 +179,15 @@ class R2dbcAutoConfigurationTests {
assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class);
SimpleTestConnectionFactory connectionFactory = (SimpleTestConnectionFactory) context
.getBean(ConnectionPool.class).unwrap();
assertThat((Object) connectionFactory.options.getRequiredValue(Option.valueOf("test")))
.isEqualTo("value");
assertThat((Object) connectionFactory.options.getRequiredValue(Option.valueOf("another")))
.isEqualTo("2");
assertThat(getRequiredOptionsValue(connectionFactory, "test")).isEqualTo("value");
assertThat(getRequiredOptionsValue(connectionFactory, "another")).isEqualTo("2");
});
}
private Object getRequiredOptionsValue(SimpleTestConnectionFactory connectionFactory, String name) {
return connectionFactory.options.getRequiredValue(Option.valueOf(name));
}
@Test
void configureWithoutUrlShouldCreateEmbeddedConnectionPoolByDefault() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ConnectionFactory.class)

@ -350,7 +350,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests {
.run((context) -> {
assertThat(context).hasSingleBean(ReactiveJwtDecoder.class);
ReactiveJwtDecoder reactiveJwtDecoder = context.getBean(ReactiveJwtDecoder.class);
DelegatingOAuth2TokenValidator<Jwt> jwtValidator = (DelegatingOAuth2TokenValidator) ReflectionTestUtils
DelegatingOAuth2TokenValidator<Jwt> jwtValidator = (DelegatingOAuth2TokenValidator<Jwt>) ReflectionTestUtils
.getField(reactiveJwtDecoder, "jwtValidator");
Collection<OAuth2TokenValidator<Jwt>> tokenValidators = (Collection<OAuth2TokenValidator<Jwt>>) ReflectionTestUtils
.getField(jwtValidator, "tokenValidators");

@ -338,7 +338,7 @@ class OAuth2ResourceServerAutoConfigurationTests {
.run((context) -> {
assertThat(context).hasSingleBean(JwtDecoder.class);
JwtDecoder jwtDecoder = context.getBean(JwtDecoder.class);
DelegatingOAuth2TokenValidator<Jwt> jwtValidator = (DelegatingOAuth2TokenValidator) ReflectionTestUtils
DelegatingOAuth2TokenValidator<Jwt> jwtValidator = (DelegatingOAuth2TokenValidator<Jwt>) ReflectionTestUtils
.getField(jwtDecoder, "jwtValidator");
Collection<OAuth2TokenValidator<Jwt>> tokenValidators = (Collection<OAuth2TokenValidator<Jwt>>) ReflectionTestUtils
.getField(jwtValidator, "tokenValidators");

@ -376,6 +376,7 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
* @param consumer the consumer of the created {@link ApplicationContext}
* @return this instance
*/
@SuppressWarnings("unchecked")
public SELF run(ContextConsumer<? super A> consumer) {
withContextClassLoader(this.classLoader, () -> this.systemProperties.applyToSystemProperties(() -> {
try (A context = createAssertableContext()) {

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import org.hamcrest.Matcher;
import org.junit.Assert;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
@ -70,7 +70,7 @@ public class OutputCaptureRule implements TestRule, CapturedOutput {
try {
if (!OutputCaptureRule.this.matchers.isEmpty()) {
String output = OutputCaptureRule.this.delegate.toString();
Assert.assertThat(output, allOf(OutputCaptureRule.this.matchers));
MatcherAssert.assertThat(output, allOf(OutputCaptureRule.this.matchers));
}
}
finally {

@ -30,6 +30,7 @@ public class GenericBuilderProperties<T extends GenericBuilderProperties<T>> {
return this.number;
}
@SuppressWarnings("unchecked")
public T setNumber(int number) {
this.number = number;
return (T) this;

@ -24,6 +24,7 @@ import org.springframework.boot.configurationsample.ConfigurationProperties;
*
* @author Stephane Nicoll
*/
@SuppressWarnings("unused")
public class SingleConstructorMethodConfig {
@ConfigurationProperties(prefix = "foo")

@ -24,6 +24,7 @@ import org.springframework.boot.configurationsample.MetaConstructorBinding;
* @author Stephane Nicoll
*/
@MetaConstructorBinding
@SuppressWarnings("unused")
public class TwoConstructorsClassConstructorBindingExample {
private String name;

@ -240,10 +240,6 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
|| (this.systemPropertyVariables != null && !this.systemPropertyVariables.isEmpty());
}
private boolean hasEnvVariables() {
return (this.environmentVariables != null && !this.environmentVariables.isEmpty());
}
private boolean hasWorkingDirectorySet() {
return this.workingDirectory != null;
}

@ -41,6 +41,7 @@ class JacksonJsonParserTests extends AbstractJsonParserTests {
}
@Test
@SuppressWarnings("unchecked")
void instanceWithSpecificObjectMapper() throws IOException {
ObjectMapper objectMapper = spy(new ObjectMapper());
new JacksonJsonParser(objectMapper).parseMap("{}");

@ -77,7 +77,7 @@ class LogbackConfigurationTests {
Appender<ILoggingEvent> appender = context.getLogger("ROOT").getAppender("FILE");
assertThat(appender).isInstanceOf(RollingFileAppender.class);
RollingPolicy rollingPolicy = ((RollingFileAppender<?>) appender).getRollingPolicy();
String fileNamePattern = ((SizeAndTimeBasedRollingPolicy) rollingPolicy).getFileNamePattern();
String fileNamePattern = ((SizeAndTimeBasedRollingPolicy<?>) rollingPolicy).getFileNamePattern();
assertThat(fileNamePattern).endsWith("spring.log.%d{yyyy-MM-dd}.%i.gz");
}
@ -90,7 +90,7 @@ class LogbackConfigurationTests {
Appender<ILoggingEvent> appender = context.getLogger("ROOT").getAppender("FILE");
assertThat(appender).isInstanceOf(RollingFileAppender.class);
RollingPolicy rollingPolicy = ((RollingFileAppender<?>) appender).getRollingPolicy();
String fileNamePattern = ((SizeAndTimeBasedRollingPolicy) rollingPolicy).getFileNamePattern();
String fileNamePattern = ((SizeAndTimeBasedRollingPolicy<?>) rollingPolicy).getFileNamePattern();
assertThat(fileNamePattern).endsWith("my.log.%d{yyyyMMdd}.%i.gz");
}

@ -37,6 +37,7 @@ import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.valves.RemoteIpValve;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@ -46,7 +47,6 @@ import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFac
import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests;
import org.springframework.boot.web.server.PortInUseException;
import org.springframework.boot.web.server.Shutdown;
import org.springframework.boot.web.server.Ssl;
import org.springframework.boot.web.server.WebServerException;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.util.SocketUtils;
@ -55,7 +55,6 @@ import org.springframework.web.reactive.function.client.WebClient;
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.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
@ -75,14 +74,16 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
return new TomcatReactiveWebServerFactory(0);
}
@Override
@Test
@Disabled("gh-19702")
void compressionOfResponseToGetRequest() {
protected void compressionOfResponseToGetRequest() {
}
@Override
@Test
@Disabled("gh-19702")
void compressionOfResponseToPostRequest() {
protected void compressionOfResponseToPostRequest() {
}
@Test
@ -248,18 +249,9 @@ class TomcatReactiveWebServerFactoryTests extends AbstractReactiveWebServerFacto
});
}
@Test
void sslWithInvalidAliasFailsDuringStartup() {
String keyStore = "classpath:test.jks";
String keyPassword = "password";
AbstractReactiveWebServerFactory factory = getFactory();
Ssl ssl = new Ssl();
ssl.setKeyStore(keyStore);
ssl.setKeyPassword(keyPassword);
ssl.setKeyAlias("test-alias-404");
factory.setSsl(ssl);
assertThatThrownBy(() -> factory.getWebServer(new EchoHandler()).start())
.isInstanceOf(WebServerException.class);
@Override
protected void assertThatSslWithInvalidAliasCallFails(ThrowingCallable call) {
assertThatExceptionOfType(WebServerException.class).isThrownBy(call);
}
@Test

@ -65,18 +65,16 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.jasper.servlet.JspServlet;
import org.apache.tomcat.JarScanFilter;
import org.apache.tomcat.JarScanType;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.springframework.boot.testsupport.system.CapturedOutput;
import org.springframework.boot.testsupport.web.servlet.ExampleServlet;
import org.springframework.boot.web.server.PortInUseException;
import org.springframework.boot.web.server.Shutdown;
import org.springframework.boot.web.server.Ssl;
import org.springframework.boot.web.server.WebServerException;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests;
import org.springframework.core.io.ByteArrayResource;
@ -93,7 +91,6 @@ 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.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
@ -555,14 +552,9 @@ class TomcatServletWebServerFactoryTests extends AbstractServletWebServerFactory
this.webServer.start();
}
@Test
void sslWithInvalidAliasFailsDuringStartup() {
AbstractServletWebServerFactory factory = getFactory();
Ssl ssl = getSsl(null, "password", "test-alias-404", "src/test/resources/test.jks");
factory.setSsl(ssl);
ServletRegistrationBean<ExampleServlet> registration = new ServletRegistrationBean<>(
new ExampleServlet(true, false), "/hello");
assertThatThrownBy(() -> factory.getWebServer(registration).start()).isInstanceOf(WebServerException.class);
@Override
protected void assertThatSslWithInvalidAliasCallFails(ThrowingCallable call) {
assertThatExceptionOfType(WebServerException.class).isThrownBy(call);
}
@Test

@ -43,6 +43,7 @@ import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
@ -178,8 +179,11 @@ public abstract class AbstractReactiveWebServerFactoryTests {
ssl.setKeyPassword(keyPassword);
ssl.setKeyAlias("test-alias-404");
factory.setSsl(ssl);
assertThatThrownBy(() -> factory.getWebServer(new EchoHandler()).start())
.hasStackTraceContaining("Keystore does not contain specified alias 'test-alias-404'");
assertThatSslWithInvalidAliasCallFails(() -> factory.getWebServer(new EchoHandler()).start());
}
protected void assertThatSslWithInvalidAliasCallFails(ThrowingCallable call) {
assertThatThrownBy(call).hasStackTraceContaining("Keystore does not contain specified alias 'test-alias-404'");
}
protected ReactorClientHttpConnector buildTrustAllSslConnector() {
@ -280,7 +284,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
}
@Test
void compressionOfResponseToGetRequest() {
protected void compressionOfResponseToGetRequest() {
WebClient client = prepareCompressionTest();
ResponseEntity<Void> response = client.get().exchange().flatMap((res) -> res.toEntity(Void.class))
.block(Duration.ofSeconds(30));
@ -288,7 +292,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
}
@Test
void compressionOfResponseToPostRequest() {
protected void compressionOfResponseToPostRequest() {
WebClient client = prepareCompressionTest();
ResponseEntity<Void> response = client.post().exchange().flatMap((res) -> res.toEntity(Void.class))
.block(Duration.ofSeconds(30));

@ -95,6 +95,7 @@ import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import org.apache.jasper.EmbeddedServletOptions;
import org.apache.jasper.servlet.JspServlet;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
@ -469,8 +470,12 @@ public abstract class AbstractServletWebServerFactoryTests {
factory.setSsl(ssl);
ServletRegistrationBean<ExampleServlet> registration = new ServletRegistrationBean<>(
new ExampleServlet(true, false), "/hello");
assertThatThrownBy(() -> factory.getWebServer(registration).start())
.hasStackTraceContaining("Keystore does not contain specified alias 'test-alias-404'");
ThrowingCallable call = () -> factory.getWebServer(registration).start();
assertThatSslWithInvalidAliasCallFails(call);
}
protected void assertThatSslWithInvalidAliasCallFails(ThrowingCallable call) {
assertThatThrownBy(call).hasStackTraceContaining("Keystore does not contain specified alias 'test-alias-404'");
}
@Test

Loading…
Cancel
Save