This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git

commit 9323ea8c20569b34eeb0bd5c2260f602e4af5e3f
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Sep 24 09:36:55 2022 -0400

    Sort members
---
 .../commons/text/lookup/StringLookupFactory.java   | 212 ++++++++++-----------
 .../text/similarity/IntersectionSimilarity.java    |   6 +-
 ...ubstitutorWithInterpolatorStringLookupTest.java |  36 ++--
 .../text/lookup/StringLookupFactoryTest.java       | 196 +++++++++----------
 4 files changed, 225 insertions(+), 225 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java 
b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
index bd397f87..bc98f75d 100644
--- a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
+++ b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
@@ -205,6 +205,103 @@ import org.apache.commons.text.StringSubstitutor;
  */
 public final class StringLookupFactory {
 
+    /**
+     * Internal class used to construct the default {@link StringLookup} map 
used by
+     * {@link StringLookupFactory#addDefaultStringLookups(Map)}.
+     */
+    static final class DefaultStringLookupsHolder {
+
+        /** Singleton instance, initialized with the system properties. */
+        static final DefaultStringLookupsHolder INSTANCE = new 
DefaultStringLookupsHolder(System.getProperties());
+
+        /**
+         * Add the key and string lookup from {@code lookup} to {@code map}, 
also adding any additional
+         * key aliases if needed. Keys are normalized using the {@link 
#toKey(String)} method.
+         * @param lookup lookup to add
+         * @param map map to add to
+         */
+        private static void addLookup(final DefaultStringLookup lookup, final 
Map<String, StringLookup> map) {
+            map.put(toKey(lookup.getKey()), lookup.getStringLookup());
+
+            if (DefaultStringLookup.BASE64_DECODER.equals(lookup)) {
+                // "base64" is deprecated in favor of KEY_BASE64_DECODER.
+                map.put(toKey("base64"), lookup.getStringLookup());
+            }
+        }
+
+        /**
+         * Create the lookup map used when the user has requested no 
customization.
+         * @return default lookup map
+         */
+        private static Map<String, StringLookup> createDefaultStringLookups() {
+            final Map<String, StringLookup> lookupMap = new HashMap<>();
+
+            addLookup(DefaultStringLookup.BASE64_DECODER, lookupMap);
+            addLookup(DefaultStringLookup.BASE64_ENCODER, lookupMap);
+            addLookup(DefaultStringLookup.CONST, lookupMap);
+            addLookup(DefaultStringLookup.DATE, lookupMap);
+            addLookup(DefaultStringLookup.ENVIRONMENT, lookupMap);
+            addLookup(DefaultStringLookup.FILE, lookupMap);
+            addLookup(DefaultStringLookup.JAVA, lookupMap);
+            addLookup(DefaultStringLookup.LOCAL_HOST, lookupMap);
+            addLookup(DefaultStringLookup.PROPERTIES, lookupMap);
+            addLookup(DefaultStringLookup.RESOURCE_BUNDLE, lookupMap);
+            addLookup(DefaultStringLookup.SYSTEM_PROPERTIES, lookupMap);
+            addLookup(DefaultStringLookup.URL_DECODER, lookupMap);
+            addLookup(DefaultStringLookup.URL_ENCODER, lookupMap);
+            addLookup(DefaultStringLookup.XML, lookupMap);
+
+            return lookupMap;
+        }
+
+        /**
+         * Construct a lookup map by parsing the given string. The string is 
expected to contain
+         * comma or space-separated names of values from the {@link 
DefaultStringLookup} enum. If
+         * the given string is null or empty, an empty map is returned.
+         * @param str string to parse; may be null or empty
+         * @return lookup map parsed from the given string
+         */
+        private static Map<String, StringLookup> parseStringLookups(final 
String str) {
+            final Map<String, StringLookup> lookupMap = new HashMap<>();
+
+            try {
+                for (final String lookupName : str.split("[\\s,]+")) {
+                    if (!lookupName.isEmpty()) {
+                        
addLookup(DefaultStringLookup.valueOf(lookupName.toUpperCase()), lookupMap);
+                    }
+                }
+            } catch (IllegalArgumentException exc) {
+                throw new IllegalArgumentException("Invalid default string 
lookups definition: " + str, exc);
+            }
+
+            return lookupMap;
+        }
+
+        /** Default string lookup map. */
+        private final Map<String, StringLookup> defaultStringLookups;
+
+        /**
+         * Construct a new instance initialized with the given properties.
+         * @param props initialization properties
+         */
+        DefaultStringLookupsHolder(final Properties props) {
+            final Map<String, StringLookup> lookups =
+                    
props.containsKey(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY)
+                        ? 
parseStringLookups(props.getProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY))
+                        : createDefaultStringLookups();
+
+            defaultStringLookups = Collections.unmodifiableMap(lookups);
+        }
+
+        /**
+         * Get the default string lookups map.
+         * @return default string lookups map
+         */
+        Map<String, StringLookup> getDefaultStringLookups() {
+            return defaultStringLookups;
+        }
+    }
+
     /**
      * Defines the singleton for this class.
      */
@@ -429,6 +526,15 @@ public final class StringLookupFactory {
         ConstantStringLookup.clear();
     }
 
+    /**
+     * Get a string suitable for use as a key in the string lookup map.
+     * @param key string to convert to a string lookup map key
+     * @return string lookup map key
+     */
+    static String toKey(final String key) {
+        return key.toLowerCase(Locale.ROOT);
+    }
+
     /**
      * Returns the given map if the input is non-null or an empty immutable 
map if the input is null.
      *
@@ -1210,110 +1316,4 @@ public final class StringLookupFactory {
     public StringLookup xmlStringLookup() {
         return XmlStringLookup.INSTANCE;
     }
-
-    /**
-     * Get a string suitable for use as a key in the string lookup map.
-     * @param key string to convert to a string lookup map key
-     * @return string lookup map key
-     */
-    static String toKey(final String key) {
-        return key.toLowerCase(Locale.ROOT);
-    }
-
-    /**
-     * Internal class used to construct the default {@link StringLookup} map 
used by
-     * {@link StringLookupFactory#addDefaultStringLookups(Map)}.
-     */
-    static final class DefaultStringLookupsHolder {
-
-        /** Singleton instance, initialized with the system properties. */
-        static final DefaultStringLookupsHolder INSTANCE = new 
DefaultStringLookupsHolder(System.getProperties());
-
-        /** Default string lookup map. */
-        private final Map<String, StringLookup> defaultStringLookups;
-
-        /**
-         * Construct a new instance initialized with the given properties.
-         * @param props initialization properties
-         */
-        DefaultStringLookupsHolder(final Properties props) {
-            final Map<String, StringLookup> lookups =
-                    
props.containsKey(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY)
-                        ? 
parseStringLookups(props.getProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY))
-                        : createDefaultStringLookups();
-
-            defaultStringLookups = Collections.unmodifiableMap(lookups);
-        }
-
-        /**
-         * Get the default string lookups map.
-         * @return default string lookups map
-         */
-        Map<String, StringLookup> getDefaultStringLookups() {
-            return defaultStringLookups;
-        }
-
-        /**
-         * Create the lookup map used when the user has requested no 
customization.
-         * @return default lookup map
-         */
-        private static Map<String, StringLookup> createDefaultStringLookups() {
-            final Map<String, StringLookup> lookupMap = new HashMap<>();
-
-            addLookup(DefaultStringLookup.BASE64_DECODER, lookupMap);
-            addLookup(DefaultStringLookup.BASE64_ENCODER, lookupMap);
-            addLookup(DefaultStringLookup.CONST, lookupMap);
-            addLookup(DefaultStringLookup.DATE, lookupMap);
-            addLookup(DefaultStringLookup.ENVIRONMENT, lookupMap);
-            addLookup(DefaultStringLookup.FILE, lookupMap);
-            addLookup(DefaultStringLookup.JAVA, lookupMap);
-            addLookup(DefaultStringLookup.LOCAL_HOST, lookupMap);
-            addLookup(DefaultStringLookup.PROPERTIES, lookupMap);
-            addLookup(DefaultStringLookup.RESOURCE_BUNDLE, lookupMap);
-            addLookup(DefaultStringLookup.SYSTEM_PROPERTIES, lookupMap);
-            addLookup(DefaultStringLookup.URL_DECODER, lookupMap);
-            addLookup(DefaultStringLookup.URL_ENCODER, lookupMap);
-            addLookup(DefaultStringLookup.XML, lookupMap);
-
-            return lookupMap;
-        }
-
-        /**
-         * Construct a lookup map by parsing the given string. The string is 
expected to contain
-         * comma or space-separated names of values from the {@link 
DefaultStringLookup} enum. If
-         * the given string is null or empty, an empty map is returned.
-         * @param str string to parse; may be null or empty
-         * @return lookup map parsed from the given string
-         */
-        private static Map<String, StringLookup> parseStringLookups(final 
String str) {
-            final Map<String, StringLookup> lookupMap = new HashMap<>();
-
-            try {
-                for (final String lookupName : str.split("[\\s,]+")) {
-                    if (!lookupName.isEmpty()) {
-                        
addLookup(DefaultStringLookup.valueOf(lookupName.toUpperCase()), lookupMap);
-                    }
-                }
-            } catch (IllegalArgumentException exc) {
-                throw new IllegalArgumentException("Invalid default string 
lookups definition: " + str, exc);
-            }
-
-            return lookupMap;
-        }
-
-        /**
-         * Add the key and string lookup from {@code lookup} to {@code map}, 
also adding any additional
-         * key aliases if needed. Keys are normalized using the {@link 
#toKey(String)} method.
-         * @param lookup lookup to add
-         * @param map map to add to
-         */
-        private static void addLookup(final DefaultStringLookup lookup, final 
Map<String, StringLookup> map) {
-            map.put(toKey(lookup.getKey()), lookup.getStringLookup());
-
-            if (DefaultStringLookup.BASE64_DECODER.equals(lookup)) {
-                // "base64" is deprecated in favor of KEY_BASE64_DECODER.
-                map.put(toKey("base64"), lookup.getStringLookup());
-            }
-        }
-    }
 }
diff --git 
a/src/main/java/org/apache/commons/text/similarity/IntersectionSimilarity.java 
b/src/main/java/org/apache/commons/text/similarity/IntersectionSimilarity.java
index 496af222..c62e9b5f 100644
--- 
a/src/main/java/org/apache/commons/text/similarity/IntersectionSimilarity.java
+++ 
b/src/main/java/org/apache/commons/text/similarity/IntersectionSimilarity.java
@@ -45,12 +45,12 @@ public class IntersectionSimilarity<T> implements 
SimilarityScore<IntersectionRe
         /** Private, mutable but must be used as immutable. */
         private static final BagCount ZERO = new BagCount();
 
+        /** The count. */
+        int count;
+
         private BagCount() {
             this.count = 0;
         }
-
-        /** The count. */
-        int count;
     }
 
     // The following is adapted from commons-collections for a Bag.
diff --git 
a/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java
 
b/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java
index e19e7f0d..f9ccc623 100644
--- 
a/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java
+++ 
b/src/test/java/org/apache/commons/text/StringSubstitutorWithInterpolatorStringLookupTest.java
@@ -32,6 +32,15 @@ import org.junit.jupiter.api.Test;
 
 public class StringSubstitutorWithInterpolatorStringLookupTest {
 
+    private static StringLookup createInterpolatorWithLookups(final 
DefaultStringLookup... lookups) {
+        final Map<String, StringLookup> lookupMap = new HashMap<>();
+        for (final DefaultStringLookup lookup : lookups) {
+            lookupMap.put(lookup.getKey().toLowerCase(), 
lookup.getStringLookup());
+        }
+
+        return 
StringLookupFactory.INSTANCE.interpolatorStringLookup(lookupMap, null, false);
+    }
+
     @Test
     public void testCustomFunctionWithDefaults() {
         testCustomFunctionWithDefaults(true);
@@ -86,7 +95,6 @@ public class 
StringSubstitutorWithInterpolatorStringLookupTest {
     public void testCustomMapWithoutDefaults() {
         testCustomMapWithDefaults(false);
     }
-
     @Test
     public void testDefaultInterpolator() {
         // Used to cut and paste into the docs.
@@ -117,6 +125,7 @@ public class 
StringSubstitutorWithInterpolatorStringLookupTest {
         Assertions.assertFalse(text.contains("${urlEncoder:Hello World!}"));
         
Assertions.assertFalse(text.contains("${resourceBundle:org.apache.commons.text.example.testResourceBundleLookup:mykey}"));
     }
+
     @Test
     public void testDefaultValueForMissingKeyInResourceBundle() {
         final StringLookup interpolatorStringLookup = 
StringLookupFactory.INSTANCE.interpolatorStringLookup(
@@ -136,6 +145,14 @@ public class 
StringSubstitutorWithInterpolatorStringLookupTest {
             strSubst.replace("${dns:" + hostName + "}"));
     }
 
+    @Test
+    public void testDnsLookup_disabledByDefault() throws UnknownHostException {
+        final StringSubstitutor strSubst = 
StringSubstitutor.createInterpolator();
+        final String hostName = InetAddress.getLocalHost().getHostName();
+        final String input = "${dns:" + hostName + "}";
+        Assertions.assertEquals(input, strSubst.replace(input));
+    }
+
     @Test
     public void testDnsLookupAddress() throws UnknownHostException {
         final StringSubstitutor strSubst =
@@ -180,14 +197,6 @@ public class 
StringSubstitutorWithInterpolatorStringLookupTest {
         Assertions.assertEquals(unknown, strSubst.replace(unknown));
     }
 
-    @Test
-    public void testDnsLookup_disabledByDefault() throws UnknownHostException {
-        final StringSubstitutor strSubst = 
StringSubstitutor.createInterpolator();
-        final String hostName = InetAddress.getLocalHost().getHostName();
-        final String input = "${dns:" + hostName + "}";
-        Assertions.assertEquals(input, strSubst.replace(input));
-    }
-
     @Test
     public void testJavaScript() {
         final StringSubstitutor strSubst =
@@ -251,13 +260,4 @@ public class 
StringSubstitutorWithInterpolatorStringLookupTest {
         Assertions.assertEquals(System.getProperty(spKey), 
strSubst.replace("${" + spKey + "}"));
         Assertions.assertEquals(System.getProperty(spKey), 
strSubst.replace("${sys:" + spKey + "}"));
     }
-
-    private static StringLookup createInterpolatorWithLookups(final 
DefaultStringLookup... lookups) {
-        final Map<String, StringLookup> lookupMap = new HashMap<>();
-        for (final DefaultStringLookup lookup : lookups) {
-            lookupMap.put(lookup.getKey().toLowerCase(), 
lookup.getStringLookup());
-        }
-
-        return 
StringLookupFactory.INSTANCE.interpolatorStringLookup(lookupMap, null, false);
-    }
 }
diff --git 
a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java 
b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
index 20614bfb..682cdbd9 100644
--- a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
+++ b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
@@ -50,6 +50,42 @@ public class StringLookupFactoryTest {
                 StringLookupFactory.KEY_XML);
     }
 
+    private static void assertMappedLookups(final Map<String, StringLookup> 
lookupMap, final String... keys) {
+        final Set<String> remainingKeys = new HashSet<>(lookupMap.keySet());
+
+        for (final String key : keys) {
+            final String normalizedKey = StringLookupFactory.toKey(key);
+            Assertions.assertNotNull(normalizedKey, () -> "Expected map to 
contain string lookup for key " + key);
+
+            remainingKeys.remove(normalizedKey);
+        }
+
+        Assertions.assertTrue(remainingKeys.isEmpty(), () -> "Unexpected keys 
in lookup map: " + remainingKeys);
+    }
+
+    private static void checkDefaultStringLookupsHolder(final Properties 
props, final String... keys) {
+        final StringLookupFactory.DefaultStringLookupsHolder holder =
+                new StringLookupFactory.DefaultStringLookupsHolder(props);
+
+        final Map<String, StringLookup> lookupMap = 
holder.getDefaultStringLookups();
+
+        assertMappedLookups(lookupMap, keys);
+    }
+
+    /**
+     * Main method used to verify the default string lookups resolved during 
JVM execution.
+     * @param args
+     */
+    public static void main(final String[] args) {
+        final Map<String, StringLookup> lookupMap = new HashMap<>();
+        StringLookupFactory.INSTANCE.addDefaultStringLookups(lookupMap);
+
+        System.out.println("Default string lookups");
+        for (final String key : lookupMap.keySet()) {
+            System.out.println("- " + key);
+        }
+    }
+
     @Test
     public void testAddDefaultStringLookupsMap() {
         final Map<String, StringLookup> stringLookupMap = new HashMap<>();
@@ -62,38 +98,15 @@ public class StringLookupFactoryTest {
         StringLookupFactory.INSTANCE.addDefaultStringLookups(null);
     }
 
-    /**
-     * Tests that we return the singleton.
-     */
     @Test
-    public void testSingletons() {
-        final StringLookupFactory stringLookupFactory = 
StringLookupFactory.INSTANCE;
-        Assertions.assertSame(StringLookupFactory.INSTANCE_BASE64_DECODER,
-            stringLookupFactory.base64DecoderStringLookup());
-        Assertions.assertSame(StringLookupFactory.INSTANCE_BASE64_ENCODER,
-            stringLookupFactory.base64EncoderStringLookup());
-        Assertions.assertSame(ConstantStringLookup.INSTANCE, 
stringLookupFactory.constantStringLookup());
-        Assertions.assertSame(DateStringLookup.INSTANCE, 
stringLookupFactory.dateStringLookup());
-        Assertions.assertSame(DnsStringLookup.INSTANCE, 
stringLookupFactory.dnsStringLookup());
-        
Assertions.assertSame(StringLookupFactory.INSTANCE_ENVIRONMENT_VARIABLES,
-            stringLookupFactory.environmentVariableStringLookup());
-        Assertions.assertSame(InterpolatorStringLookup.INSTANCE, 
stringLookupFactory.interpolatorStringLookup());
-        Assertions.assertSame(JavaPlatformStringLookup.INSTANCE, 
stringLookupFactory.javaPlatformStringLookup());
-        Assertions.assertSame(LocalHostStringLookup.INSTANCE, 
stringLookupFactory.localHostStringLookup());
-        Assertions.assertSame(StringLookupFactory.INSTANCE_NULL, 
stringLookupFactory.nullStringLookup());
-        Assertions.assertSame(ResourceBundleStringLookup.INSTANCE, 
stringLookupFactory.resourceBundleStringLookup());
-        Assertions.assertSame(ScriptStringLookup.INSTANCE, 
stringLookupFactory.scriptStringLookup());
-        Assertions.assertSame(StringLookupFactory.INSTANCE_SYSTEM_PROPERTIES,
-            stringLookupFactory.systemPropertyStringLookup());
-        Assertions.assertSame(UrlDecoderStringLookup.INSTANCE, 
stringLookupFactory.urlDecoderStringLookup());
-        Assertions.assertSame(UrlEncoderStringLookup.INSTANCE, 
stringLookupFactory.urlEncoderStringLookup());
-        Assertions.assertSame(UrlStringLookup.INSTANCE, 
stringLookupFactory.urlStringLookup());
-        Assertions.assertSame(XmlStringLookup.INSTANCE, 
stringLookupFactory.xmlStringLookup());
-    }
+    public void testDefaultStringLookupsHolder_allLookups() {
+        final Properties props = new Properties();
+        props.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY,
+                "BASE64_DECODER BASE64_ENCODER const, date, dns, environment "
+                + "file ,java, local_host properties, 
resource_bundle,script,system_properties "
+                + "url url_decoder  , url_encoder, xml");
 
-    @Test
-    public void testDefaultStringLookupsHolder_lookupsPropertyNotPresent() {
-        checkDefaultStringLookupsHolder(new Properties(),
+        checkDefaultStringLookupsHolder(props,
                 "base64",
                 StringLookupFactory.KEY_BASE64_DECODER,
                 StringLookupFactory.KEY_BASE64_ENCODER,
@@ -108,20 +121,11 @@ public class StringLookupFactoryTest {
                 StringLookupFactory.KEY_SYS,
                 StringLookupFactory.KEY_URL_DECODER,
                 StringLookupFactory.KEY_URL_ENCODER,
-                StringLookupFactory.KEY_XML);
-    }
-
-    @Test
-    public void testDefaultStringLookupsHolder_lookupsPropertyEmptyAndBlank() {
-        final Properties propsWithNull = new Properties();
-        
propsWithNull.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, 
"");
-
-        checkDefaultStringLookupsHolder(propsWithNull);
-
-        final Properties propsWithBlank = new Properties();
-        
propsWithBlank.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, 
" ");
+                StringLookupFactory.KEY_XML,
 
-        checkDefaultStringLookupsHolder(propsWithBlank);
+                StringLookupFactory.KEY_DNS,
+                StringLookupFactory.KEY_URL,
+                StringLookupFactory.KEY_SCRIPT);
     }
 
     @Test
@@ -143,25 +147,31 @@ public class StringLookupFactoryTest {
     }
 
     @Test
-    public void testDefaultStringLookupsHolder_multipleLookups() {
+    public void testDefaultStringLookupsHolder_invalidLookupsDefinition() {
         final Properties props = new Properties();
-        props.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, 
"dns, url script ");
+        props.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, 
"base64_encoder nope");
 
-        checkDefaultStringLookupsHolder(props,
-                StringLookupFactory.KEY_DNS,
-                StringLookupFactory.KEY_URL,
-                StringLookupFactory.KEY_SCRIPT);
+        final Exception exc = 
Assertions.assertThrows(IllegalArgumentException.class,
+                () -> new 
StringLookupFactory.DefaultStringLookupsHolder(props));
+        Assertions.assertEquals("Invalid default string lookups definition: 
base64_encoder nope", exc.getMessage());
     }
 
     @Test
-    public void testDefaultStringLookupsHolder_allLookups() {
-        final Properties props = new Properties();
-        props.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY,
-                "BASE64_DECODER BASE64_ENCODER const, date, dns, environment "
-                + "file ,java, local_host properties, 
resource_bundle,script,system_properties "
-                + "url url_decoder  , url_encoder, xml");
+    public void testDefaultStringLookupsHolder_lookupsPropertyEmptyAndBlank() {
+        final Properties propsWithNull = new Properties();
+        
propsWithNull.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, 
"");
 
-        checkDefaultStringLookupsHolder(props,
+        checkDefaultStringLookupsHolder(propsWithNull);
+
+        final Properties propsWithBlank = new Properties();
+        
propsWithBlank.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, 
" ");
+
+        checkDefaultStringLookupsHolder(propsWithBlank);
+    }
+
+    @Test
+    public void testDefaultStringLookupsHolder_lookupsPropertyNotPresent() {
+        checkDefaultStringLookupsHolder(new Properties(),
                 "base64",
                 StringLookupFactory.KEY_BASE64_DECODER,
                 StringLookupFactory.KEY_BASE64_ENCODER,
@@ -176,56 +186,46 @@ public class StringLookupFactoryTest {
                 StringLookupFactory.KEY_SYS,
                 StringLookupFactory.KEY_URL_DECODER,
                 StringLookupFactory.KEY_URL_ENCODER,
-                StringLookupFactory.KEY_XML,
-
-                StringLookupFactory.KEY_DNS,
-                StringLookupFactory.KEY_URL,
-                StringLookupFactory.KEY_SCRIPT);
+                StringLookupFactory.KEY_XML);
     }
 
     @Test
-    public void testDefaultStringLookupsHolder_invalidLookupsDefinition() {
+    public void testDefaultStringLookupsHolder_multipleLookups() {
         final Properties props = new Properties();
-        props.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, 
"base64_encoder nope");
-
-        final Exception exc = 
Assertions.assertThrows(IllegalArgumentException.class,
-                () -> new 
StringLookupFactory.DefaultStringLookupsHolder(props));
-        Assertions.assertEquals("Invalid default string lookups definition: 
base64_encoder nope", exc.getMessage());
-    }
-
-    private static void checkDefaultStringLookupsHolder(final Properties 
props, final String... keys) {
-        final StringLookupFactory.DefaultStringLookupsHolder holder =
-                new StringLookupFactory.DefaultStringLookupsHolder(props);
-
-        final Map<String, StringLookup> lookupMap = 
holder.getDefaultStringLookups();
-
-        assertMappedLookups(lookupMap, keys);
-    }
-
-    private static void assertMappedLookups(final Map<String, StringLookup> 
lookupMap, final String... keys) {
-        final Set<String> remainingKeys = new HashSet<>(lookupMap.keySet());
-
-        for (final String key : keys) {
-            final String normalizedKey = StringLookupFactory.toKey(key);
-            Assertions.assertNotNull(normalizedKey, () -> "Expected map to 
contain string lookup for key " + key);
-
-            remainingKeys.remove(normalizedKey);
-        }
+        props.setProperty(StringLookupFactory.DEFAULT_STRING_LOOKUPS_PROPERTY, 
"dns, url script ");
 
-        Assertions.assertTrue(remainingKeys.isEmpty(), () -> "Unexpected keys 
in lookup map: " + remainingKeys);
+        checkDefaultStringLookupsHolder(props,
+                StringLookupFactory.KEY_DNS,
+                StringLookupFactory.KEY_URL,
+                StringLookupFactory.KEY_SCRIPT);
     }
 
     /**
-     * Main method used to verify the default string lookups resolved during 
JVM execution.
-     * @param args
+     * Tests that we return the singleton.
      */
-    public static void main(final String[] args) {
-        final Map<String, StringLookup> lookupMap = new HashMap<>();
-        StringLookupFactory.INSTANCE.addDefaultStringLookups(lookupMap);
-
-        System.out.println("Default string lookups");
-        for (final String key : lookupMap.keySet()) {
-            System.out.println("- " + key);
-        }
+    @Test
+    public void testSingletons() {
+        final StringLookupFactory stringLookupFactory = 
StringLookupFactory.INSTANCE;
+        Assertions.assertSame(StringLookupFactory.INSTANCE_BASE64_DECODER,
+            stringLookupFactory.base64DecoderStringLookup());
+        Assertions.assertSame(StringLookupFactory.INSTANCE_BASE64_ENCODER,
+            stringLookupFactory.base64EncoderStringLookup());
+        Assertions.assertSame(ConstantStringLookup.INSTANCE, 
stringLookupFactory.constantStringLookup());
+        Assertions.assertSame(DateStringLookup.INSTANCE, 
stringLookupFactory.dateStringLookup());
+        Assertions.assertSame(DnsStringLookup.INSTANCE, 
stringLookupFactory.dnsStringLookup());
+        
Assertions.assertSame(StringLookupFactory.INSTANCE_ENVIRONMENT_VARIABLES,
+            stringLookupFactory.environmentVariableStringLookup());
+        Assertions.assertSame(InterpolatorStringLookup.INSTANCE, 
stringLookupFactory.interpolatorStringLookup());
+        Assertions.assertSame(JavaPlatformStringLookup.INSTANCE, 
stringLookupFactory.javaPlatformStringLookup());
+        Assertions.assertSame(LocalHostStringLookup.INSTANCE, 
stringLookupFactory.localHostStringLookup());
+        Assertions.assertSame(StringLookupFactory.INSTANCE_NULL, 
stringLookupFactory.nullStringLookup());
+        Assertions.assertSame(ResourceBundleStringLookup.INSTANCE, 
stringLookupFactory.resourceBundleStringLookup());
+        Assertions.assertSame(ScriptStringLookup.INSTANCE, 
stringLookupFactory.scriptStringLookup());
+        Assertions.assertSame(StringLookupFactory.INSTANCE_SYSTEM_PROPERTIES,
+            stringLookupFactory.systemPropertyStringLookup());
+        Assertions.assertSame(UrlDecoderStringLookup.INSTANCE, 
stringLookupFactory.urlDecoderStringLookup());
+        Assertions.assertSame(UrlEncoderStringLookup.INSTANCE, 
stringLookupFactory.urlEncoderStringLookup());
+        Assertions.assertSame(UrlStringLookup.INSTANCE, 
stringLookupFactory.urlStringLookup());
+        Assertions.assertSame(XmlStringLookup.INSTANCE, 
stringLookupFactory.xmlStringLookup());
     }
 }

Reply via email to