diff --git a/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheManagerTests.java b/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheManagerTests.java index a9f9858087..261ab391b1 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheManagerTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheManagerTests.java @@ -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 nc = Caffeine.newBuilder().build(); cm.registerCustomCache("c2", nc); diff --git a/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java b/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java index fbdf751435..81bd8b6996 100644 --- a/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java +++ b/spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java @@ -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) { diff --git a/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java index a249ef1dda..217d08bb4a 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestClientIntegrationTests.java @@ -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()) diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java index 9598da14f5..7e8829e275 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java @@ -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())