Browse Source

Clean up warnings in tests

pull/28156/merge
Sam Brannen 1 year ago
parent
commit
170d6bfdad
  1. 25
      spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheManagerTests.java
  2. 22
      spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java
  3. 3
      spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java
  4. 3
      spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java

25
spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheManagerTests.java vendored

@ -36,10 +36,11 @@ import static org.mockito.Mockito.mock; @@ -36,10 +36,11 @@ import static org.mockito.Mockito.mock;
* @author Juergen Hoeller
* @author Stephane Nicoll
*/
public class CaffeineCacheManagerTests {
class CaffeineCacheManagerTests {
@Test
public void testDynamicMode() {
@SuppressWarnings("cast")
void dynamicMode() {
CacheManager cm = new CaffeineCacheManager();
Cache cache1 = cm.getCache("c1");
@ -77,7 +78,8 @@ public class CaffeineCacheManagerTests { @@ -77,7 +78,8 @@ public class CaffeineCacheManagerTests {
}
@Test
public void testStaticMode() {
@SuppressWarnings("cast")
void staticMode() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1", "c2");
Cache cache1 = cm.getCache("c1");
@ -136,7 +138,8 @@ public class CaffeineCacheManagerTests { @@ -136,7 +138,8 @@ public class CaffeineCacheManagerTests {
}
@Test
public void testAsyncMode() {
@SuppressWarnings("cast")
void asyncMode() {
CaffeineCacheManager cm = new CaffeineCacheManager();
cm.setAsyncCacheMode(true);
@ -182,7 +185,7 @@ public class CaffeineCacheManagerTests { @@ -182,7 +185,7 @@ public class CaffeineCacheManagerTests {
}
@Test
public void changeCaffeineRecreateCache() {
void changeCaffeineRecreateCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
Cache cache1 = cm.getCache("c1");
@ -197,7 +200,7 @@ public class CaffeineCacheManagerTests { @@ -197,7 +200,7 @@ public class CaffeineCacheManagerTests {
}
@Test
public void changeCaffeineSpecRecreateCache() {
void changeCaffeineSpecRecreateCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
Cache cache1 = cm.getCache("c1");
@ -207,7 +210,7 @@ public class CaffeineCacheManagerTests { @@ -207,7 +210,7 @@ public class CaffeineCacheManagerTests {
}
@Test
public void changeCacheSpecificationRecreateCache() {
void changeCacheSpecificationRecreateCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
Cache cache1 = cm.getCache("c1");
@ -217,7 +220,7 @@ public class CaffeineCacheManagerTests { @@ -217,7 +220,7 @@ public class CaffeineCacheManagerTests {
}
@Test
public void changeCacheLoaderRecreateCache() {
void changeCacheLoaderRecreateCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
Cache cache1 = cm.getCache("c1");
@ -234,7 +237,7 @@ public class CaffeineCacheManagerTests { @@ -234,7 +237,7 @@ public class CaffeineCacheManagerTests {
}
@Test
public void setCacheNameNullRestoreDynamicMode() {
void setCacheNameNullRestoreDynamicMode() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
assertThat(cm.getCache("someCache")).isNull();
cm.setCacheNames(null);
@ -242,7 +245,7 @@ public class CaffeineCacheManagerTests { @@ -242,7 +245,7 @@ public class CaffeineCacheManagerTests {
}
@Test
public void cacheLoaderUseLoadingCache() {
void cacheLoaderUseLoadingCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
cm.setCacheLoader(key -> {
if ("ping".equals(key)) {
@ -260,7 +263,7 @@ public class CaffeineCacheManagerTests { @@ -260,7 +263,7 @@ public class CaffeineCacheManagerTests {
}
@Test
public void customCacheRegistration() {
void customCacheRegistration() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
com.github.benmanes.caffeine.cache.Cache<Object, Object> nc = Caffeine.newBuilder().build();
cm.registerCustomCache("c2", nc);

22
spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@ -33,17 +33,18 @@ class SimpleAsyncTaskExecutorTests { @@ -33,17 +33,18 @@ class SimpleAsyncTaskExecutorTests {
@Test
void cannotExecuteWhenConcurrencyIsSwitchedOff() {
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY);
assertThat(executor.isThrottleActive()).isTrue();
assertThatIllegalStateException().isThrownBy(() ->
executor.execute(new NoOpRunnable()));
try (SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor()) {
executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY);
assertThat(executor.isThrottleActive()).isTrue();
assertThatIllegalStateException().isThrownBy(() -> executor.execute(new NoOpRunnable()));
}
}
@Test
void throttleIsNotActiveByDefault() {
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
assertThat(executor.isThrottleActive()).as("Concurrency throttle must not default to being active (on)").isFalse();
try (SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor()) {
assertThat(executor.isThrottleActive()).as("Concurrency throttle must not default to being active (on)").isFalse();
}
}
@Test
@ -67,8 +68,9 @@ class SimpleAsyncTaskExecutorTests { @@ -67,8 +68,9 @@ class SimpleAsyncTaskExecutorTests {
@Test
void throwsExceptionWhenSuppliedWithNullRunnable() {
assertThatIllegalArgumentException().isThrownBy(() ->
new SimpleAsyncTaskExecutor().execute(null));
try (SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor()) {
assertThatIllegalArgumentException().isThrownBy(() -> executor.execute(null));
}
}
private void executeAndWait(SimpleAsyncTaskExecutor executor, Runnable task, Object monitor) {

3
spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java

@ -47,7 +47,6 @@ import org.springframework.http.client.ClientHttpResponse; @@ -47,7 +47,6 @@ import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import org.springframework.http.client.JettyClientHttpRequestFactory;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.http.client.ReactorNettyClientRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.CollectionUtils;
@ -77,7 +76,7 @@ class RestClientIntegrationTests { @@ -77,7 +76,7 @@ class RestClientIntegrationTests {
return Stream.of(
named("JDK HttpURLConnection", new SimpleClientHttpRequestFactory()),
named("HttpComponents", new HttpComponentsClientHttpRequestFactory()),
named("OkHttp", new OkHttp3ClientHttpRequestFactory()),
named("OkHttp", new org.springframework.http.client.OkHttp3ClientHttpRequestFactory()),
named("Jetty", new JettyClientHttpRequestFactory()),
named("JDK HttpClient", new JdkClientHttpRequestFactory()),
named("Reactor Netty", new ReactorNettyClientRequestFactory())

3
spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java

@ -50,7 +50,6 @@ import org.springframework.http.client.ClientHttpRequestFactory; @@ -50,7 +50,6 @@ import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import org.springframework.http.client.JettyClientHttpRequestFactory;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.http.client.ReactorNettyClientRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.FormHttpMessageConverter;
@ -96,7 +95,7 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests { @@ -96,7 +95,7 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
return Stream.of(
named("JDK HttpURLConnection", new SimpleClientHttpRequestFactory()),
named("HttpComponents", new HttpComponentsClientHttpRequestFactory()),
named("OkHttp", new OkHttp3ClientHttpRequestFactory()),
named("OkHttp", new org.springframework.http.client.OkHttp3ClientHttpRequestFactory()),
named("Jetty", new JettyClientHttpRequestFactory()),
named("JDK HttpClient", new JdkClientHttpRequestFactory()),
named("Reactor Netty", new ReactorNettyClientRequestFactory())

Loading…
Cancel
Save