Repository: commons-text
Updated Branches:
  refs/heads/master 9e3eafcf0 -> 6c23a516a


[TEXT-146]
org.apache.commons.text.lookup.StringLookupFactory.interpolatorStringLookup()
should reuse a singleton instance. Ensure that all factory methods that
should return a singleton does.

Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/6c23a516
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/6c23a516
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/6c23a516

Branch: refs/heads/master
Commit: 6c23a516a288e62604e0d9a0abdda587244b9e09
Parents: 9e3eafc
Author: Gary Gregory <ggreg...@rocketsoftware.com>
Authored: Thu Oct 4 13:43:18 2018 -0600
Committer: Gary Gregory <ggreg...@rocketsoftware.com>
Committed: Thu Oct 4 13:43:18 2018 -0600

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../text/lookup/InterpolatorStringLookup.java   |  7 +++
 .../text/lookup/StringLookupFactory.java        |  2 +-
 .../text/lookup/StringLookupFactoryTest.java    | 50 ++++++++++++++++++++
 4 files changed, 59 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/6c23a516/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0f988c3..d0067ef 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -48,6 +48,7 @@ The <action> type attribute can be add,update,fix,remove.
   <release version="1.6" date="2018-MM-DD" description="Release 1.6">
     <action issue="TEXT-144" type="update" dev="ggregory">Add the resource 
string bundle string lookup to the default set of lookups</action>
     <action issue="TEXT-145" type="update" dev="ggregory">Add 
StringLookupFactory methods for the URL encoder and decoder string 
lookups</action>
+    <action issue="TEXT-146" type="update" 
dev="ggregory">org.apache.commons.text.lookup.StringLookupFactory.interpolatorStringLookup()
 should reuse a singleton instance</action>
   </release>
 
   <release version="1.5" date="2018-09-29" description="Release 1.5">

http://git-wip-us.apache.org/repos/asf/commons-text/blob/6c23a516/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java 
b/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
index 8f996cb..6cd09d2 100644
--- a/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/InterpolatorStringLookup.java
@@ -44,6 +44,13 @@ import java.util.Map.Entry;
  */
 class InterpolatorStringLookup extends AbstractStringLookup {
 
+    /**
+     * Defines the singleton for this class.
+     * 
+     * @since 1.6
+     */
+    static final AbstractStringLookup INSTANCE = new 
InterpolatorStringLookup();
+
     /** Constant for the prefix separator. */
     private static final char PREFIX_SEPARATOR = ':';
 

http://git-wip-us.apache.org/repos/asf/commons-text/blob/6c23a516/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
----------------------------------------------------------------------
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 dd26809..3b75103 100644
--- a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
+++ b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
@@ -193,7 +193,7 @@ public final class StringLookupFactory {
      * @return a new InterpolatorStringLookup.
      */
     public StringLookup interpolatorStringLookup() {
-        return new InterpolatorStringLookup();
+        return InterpolatorStringLookup.INSTANCE;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-text/blob/6c23a516/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java 
b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
new file mode 100644
index 0000000..caa6ee3
--- /dev/null
+++ b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.commons.text.lookup;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link StringLookupFactory}.
+ */
+public class StringLookupFactoryTest {
+
+    /**
+     * Tests that we return the singleton.
+     */
+    @Test
+    public void testSingletons() {
+        final StringLookupFactory stringLookupFactory = 
StringLookupFactory.INSTANCE;
+        Assertions.assertEquals(Base64StringLookup.INSTANCE, 
stringLookupFactory.base64StringLookup());
+        Assertions.assertEquals(ConstantStringLookup.INSTANCE, 
stringLookupFactory.constantStringLookup());
+        Assertions.assertEquals(DateStringLookup.INSTANCE, 
stringLookupFactory.dateStringLookup());
+        Assertions.assertEquals(EnvironmentVariableStringLookup.INSTANCE,
+                stringLookupFactory.environmentVariableStringLookup());
+        Assertions.assertEquals(InterpolatorStringLookup.INSTANCE, 
stringLookupFactory.interpolatorStringLookup());
+        Assertions.assertEquals(JavaPlatformStringLookup.INSTANCE, 
stringLookupFactory.javaPlatformStringLookup());
+        Assertions.assertEquals(LocalHostStringLookup.INSTANCE, 
stringLookupFactory.localHostStringLookup());
+        Assertions.assertEquals(NullStringLookup.INSTANCE, 
stringLookupFactory.nullStringLookup());
+        Assertions.assertEquals(ResourceBundleStringLookup.INSTANCE, 
stringLookupFactory.resourceBundleStringLookup());
+        Assertions.assertEquals(ScriptStringLookup.INSTANCE, 
stringLookupFactory.scriptStringLookup());
+        Assertions.assertEquals(SystemPropertyStringLookup.INSTANCE, 
stringLookupFactory.systemPropertyStringLookup());
+        Assertions.assertEquals(UrlDecoderStringLookup.INSTANCE, 
stringLookupFactory.urlDecoderStringLookup());
+        Assertions.assertEquals(UrlEncoderStringLookup.INSTANCE, 
stringLookupFactory.urlEncoderStringLookup());
+        Assertions.assertEquals(UrlStringLookup.INSTANCE, 
stringLookupFactory.urlStringLookup());
+        Assertions.assertEquals(XmlStringLookup.INSTANCE, 
stringLookupFactory.xmlStringLookup());
+    }
+}

Reply via email to