From bfbe8f878064b5d3d4e6a99521ca3f95d7bdf67c Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 28 Jul 2019 15:38:14 +0200 Subject: [PATCH] Polish MergedTestPropertySources --- .../test/context/support/MergedTestPropertySources.java | 9 +++++---- .../test/context/support/TestPropertySourceUtils.java | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java b/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java index 7f444aed662..ad520a007d9 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java @@ -30,7 +30,7 @@ import org.springframework.util.Assert; */ class MergedTestPropertySources { - private static final String[] EMPTY_STRING_ARRAY = new String[0]; + private static final MergedTestPropertySources empty = new MergedTestPropertySources(new String[0], new String[0]); private final String[] locations; @@ -38,12 +38,13 @@ class MergedTestPropertySources { /** - * Create an empty {@code MergedTestPropertySources} instance. + * Factory for an empty {@code MergedTestPropertySources} instance. */ - MergedTestPropertySources() { - this(EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY); + static MergedTestPropertySources empty() { + return empty; } + /** * Create a {@code MergedTestPropertySources} instance with the supplied * {@code locations} and {@code properties}. diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index 31d6395e9ff..2b40af93615 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -92,7 +92,7 @@ public abstract class TestPropertySourceUtils { static MergedTestPropertySources buildMergedTestPropertySources(Class testClass) { MergedAnnotations mergedAnnotations = MergedAnnotations.from(testClass, SearchStrategy.EXHAUSTIVE); return (mergedAnnotations.isPresent(TestPropertySource.class) ? mergeTestPropertySources(mergedAnnotations) : - new MergedTestPropertySources()); + MergedTestPropertySources.empty()); } private static MergedTestPropertySources mergeTestPropertySources(MergedAnnotations mergedAnnotations) {