diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java index d1af85bda7..f4389ca844 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java @@ -157,7 +157,7 @@ class JavaConventions { args.add("-parameters"); } if (JavaVersion.current() == JavaVersion.VERSION_1_8) { - args.add("-Werror"); + args.addAll(Arrays.asList("-Werror", "-Xlint:unchecked")); } }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java index 0fa0c8e2ef..9dc54b2e1a 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/trace/http/reactive/HttpTraceWebFilterTests.java @@ -89,9 +89,10 @@ class HttpTraceWebFilterTests { executeFilter(new ServerWebExchangeDecorator( MockServerWebExchange.from(MockServerHttpRequest.get("https://api.example.com"))) { + @SuppressWarnings("unchecked") @Override - public Mono getPrincipal() { - return Mono.just(principal); + public Mono getPrincipal() { + return Mono.just((T) principal); } }, (exchange) -> { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index 70cecb92a4..ec86125d84 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -42,6 +42,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider; +import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider.MockCacheManager; import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; @@ -354,8 +355,9 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { assertThat(cacheManager.getCacheNames()).containsOnly("one", "two"); CompleteConfiguration defaultCacheConfiguration = context .getBean(CompleteConfiguration.class); - verify(cacheManager.getCacheManager()).createCache("one", defaultCacheConfiguration); - verify(cacheManager.getCacheManager()).createCache("two", defaultCacheConfiguration); + MockCacheManager mockCacheManager = (MockCacheManager) cacheManager.getCacheManager(); + assertThat(mockCacheManager.getConfigurations()).containsEntry("one", defaultCacheConfiguration) + .containsEntry("two", defaultCacheConfiguration); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/support/MockCachingProvider.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/support/MockCachingProvider.java index 9c6380355f..d1e3e982c8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/support/MockCachingProvider.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/support/MockCachingProvider.java @@ -27,8 +27,6 @@ import javax.cache.configuration.Configuration; import javax.cache.configuration.OptionalFeature; import javax.cache.spi.CachingProvider; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -41,25 +39,8 @@ import static org.mockito.Mockito.mock; public class MockCachingProvider implements CachingProvider { @Override - @SuppressWarnings("rawtypes") public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) { - CacheManager cacheManager = mock(CacheManager.class); - given(cacheManager.getURI()).willReturn(uri); - given(cacheManager.getClassLoader()).willReturn(classLoader); - final Map caches = new HashMap<>(); - given(cacheManager.getCacheNames()).willReturn(caches.keySet()); - given(cacheManager.getCache(anyString())).willAnswer((invocation) -> { - String cacheName = invocation.getArgument(0); - return caches.get(cacheName); - }); - given(cacheManager.createCache(anyString(), any(Configuration.class))).will((invocation) -> { - String cacheName = invocation.getArgument(0); - Cache cache = mock(Cache.class); - given(cache.getName()).willReturn(cacheName); - caches.put(cacheName, cache); - return cache; - }); - return cacheManager; + return new MockCacheManager(uri, classLoader, properties); } @Override @@ -104,4 +85,108 @@ public class MockCachingProvider implements CachingProvider { return false; } + public static class MockCacheManager implements CacheManager { + + private final Map> configurations = new HashMap<>(); + + private final Map> caches = new HashMap<>(); + + private final URI uri; + + private final ClassLoader classLoader; + + private final Properties properties; + + private boolean closed; + + public MockCacheManager(URI uri, ClassLoader classLoader, Properties properties) { + this.uri = uri; + this.classLoader = classLoader; + this.properties = properties; + } + + @Override + public CachingProvider getCachingProvider() { + throw new UnsupportedOperationException(); + } + + @Override + public URI getURI() { + return this.uri; + } + + @Override + public ClassLoader getClassLoader() { + return this.classLoader; + } + + @Override + public Properties getProperties() { + return this.properties; + } + + @Override + @SuppressWarnings("unchecked") + public > Cache createCache(String cacheName, C configuration) + throws IllegalArgumentException { + this.configurations.put(cacheName, configuration); + Cache cache = mock(Cache.class); + given(cache.getName()).willReturn(cacheName); + this.caches.put(cacheName, cache); + return cache; + } + + @Override + @SuppressWarnings("unchecked") + public Cache getCache(String cacheName, Class keyType, Class valueType) { + return (Cache) this.caches.get(cacheName); + } + + @Override + @SuppressWarnings("unchecked") + public Cache getCache(String cacheName) { + return (Cache) this.caches.get(cacheName); + } + + @Override + public Iterable getCacheNames() { + return this.caches.keySet(); + } + + @Override + public void destroyCache(String cacheName) { + this.caches.remove(cacheName); + } + + @Override + public void enableManagement(String cacheName, boolean enabled) { + throw new UnsupportedOperationException(); + } + + @Override + public void enableStatistics(String cacheName, boolean enabled) { + throw new UnsupportedOperationException(); + } + + @Override + public void close() { + this.closed = true; + } + + @Override + public boolean isClosed() { + return this.closed; + } + + @Override + public T unwrap(Class clazz) { + throw new UnsupportedOperationException(); + } + + public Map> getConfigurations() { + return this.configurations; + } + + } + } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/DependencyFilter.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/DependencyFilter.java index d5b0c8ab2b..69fdd36d8c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/DependencyFilter.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/DependencyFilter.java @@ -46,11 +46,10 @@ public abstract class DependencyFilter extends AbstractArtifactsFilter { } @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Set filter(Set artifacts) throws ArtifactFilterException { - Set result = new HashSet(); - for (Object artifact : artifacts) { - if (!filter((Artifact) artifact)) { + public Set filter(Set artifacts) throws ArtifactFilterException { + Set result = new HashSet<>(); + for (Artifact artifact : artifacts) { + if (!filter(artifact)) { result.add(artifact); } }