diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/util/random/CachedRandomPropertySource.java b/spring-cloud-context/src/main/java/org/springframework/cloud/util/random/CachedRandomPropertySource.java index f276632d..351f21d0 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/util/random/CachedRandomPropertySource.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/util/random/CachedRandomPropertySource.java @@ -19,15 +19,13 @@ package org.springframework.cloud.util.random; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.springframework.boot.env.RandomValuePropertySource; import org.springframework.core.env.PropertySource; import org.springframework.util.StringUtils; /** * @author Ryan Baxter */ -public class CachedRandomPropertySource - extends PropertySource { +public class CachedRandomPropertySource extends PropertySource { private static final String NAME = "cachedrandom"; @@ -35,13 +33,12 @@ public class CachedRandomPropertySource private static Map> cache = new ConcurrentHashMap<>(); - public CachedRandomPropertySource( - RandomValuePropertySource randomValuePropertySource) { + public CachedRandomPropertySource(PropertySource randomValuePropertySource) { super(NAME, randomValuePropertySource); } - CachedRandomPropertySource(RandomValuePropertySource randomValuePropertySource, + CachedRandomPropertySource(PropertySource randomValuePropertySource, Map> cache) { super(NAME, randomValuePropertySource); this.cache = cache; diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/util/random/CachedRandomPropertySourceAutoConfiguration.java b/spring-cloud-context/src/main/java/org/springframework/cloud/util/random/CachedRandomPropertySourceAutoConfiguration.java index 5158e9e9..b18fb692 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/util/random/CachedRandomPropertySourceAutoConfiguration.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/util/random/CachedRandomPropertySourceAutoConfiguration.java @@ -40,8 +40,7 @@ public class CachedRandomPropertySourceAutoConfiguration { PropertySource propertySource = propertySources .get(RandomValuePropertySource.RANDOM_PROPERTY_SOURCE_NAME); if (propertySource != null) { - propertySources.addLast(new CachedRandomPropertySource( - RandomValuePropertySource.class.cast(propertySource))); + propertySources.addLast(new CachedRandomPropertySource(propertySource)); } } diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/util/random/CachedRandomPropertySourceTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/util/random/CachedRandomPropertySourceTests.java index 9de4fcb4..f97d1455 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/util/random/CachedRandomPropertySourceTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/util/random/CachedRandomPropertySourceTests.java @@ -26,7 +26,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.boot.env.RandomValuePropertySource; +import org.springframework.core.env.PropertySource; import org.springframework.test.annotation.DirtiesContext; import static org.assertj.core.api.BDDAssertions.then; @@ -45,20 +45,19 @@ import static org.mockito.Mockito.when; public class CachedRandomPropertySourceTests { @Mock - RandomValuePropertySource randomValuePropertySource; + private PropertySource randomValuePropertySource; @Before public void setup() { - - when(randomValuePropertySource.getProperty(eq("random.long"))) - .thenReturn(new Long(1234)); + when(randomValuePropertySource.getProperty(eq("random.long"))).thenReturn(1234L); } + @SuppressWarnings("unchecked") @Test public void getProperty() { Map> cache = new HashMap<>(); Map typeCache = new HashMap<>(); - typeCache.put("long", new Long(5678)); + typeCache.put("long", 5678L); Map spyedTypeCache = spy(typeCache); cache.put("foo", spyedTypeCache); Map> spyedCache = spy(cache); @@ -69,9 +68,9 @@ public class CachedRandomPropertySourceTests { then(cachedRandomPropertySource.getProperty("cachedrandom.app")).isNull(); then(cachedRandomPropertySource.getProperty("cachedrandom.app.long")) - .isEqualTo(new Long(1234)); + .isEqualTo(1234L); then(cachedRandomPropertySource.getProperty("cachedrandom.foo.long")) - .isEqualTo(new Long(5678)); + .isEqualTo(5678L); verify(spyedCache, times(1)).computeIfAbsent(eq("app"), isA(Function.class)); verify(spyedTypeCache, times(1)).computeIfAbsent(eq("long"), isA(Function.class)); }