Clean up warnings in tests

This commit is contained in:
Sam Brannen 2023-07-31 16:17:48 +03:00
parent 2f7046f572
commit 170d6bfdad
4 changed files with 28 additions and 25 deletions

View File

@ -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 {
}
@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 {
}
@Test
public void testAsyncMode() {
@SuppressWarnings("cast")
void asyncMode() {
CaffeineCacheManager cm = new CaffeineCacheManager();
cm.setAsyncCacheMode(true);
@ -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 {
}
@Test
public void changeCaffeineSpecRecreateCache() {
void changeCaffeineSpecRecreateCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
Cache cache1 = cm.getCache("c1");
@ -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 {
}
@Test
public void changeCacheLoaderRecreateCache() {
void changeCacheLoaderRecreateCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
Cache cache1 = cm.getCache("c1");
@ -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 {
}
@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 {
}
@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);

View File

@ -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 {
@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 {
@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) {

View File

@ -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 {
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())

View File

@ -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 {
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())