Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 47972d89b -> d9406e58f


TAMAYA-328: Let CharConverter parse a single apostrophe character

CharConverter uses paired apostrophes (') to delimit multi-character
strings and pulls the first into a Character object as needed.  That
works great, but has made it to where a single apostrophe by itself
cannot be used directly.  Entertainingly, "'''" works, but "'" throws an
exception.  This adds a simple check if the string is 1 character long
after having determined that it starts with an apostrophe.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a606c878
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a606c878
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a606c878

Branch: refs/heads/master
Commit: a606c878003a954d8888dc66aaf891f6193e3149
Parents: ca4de3d
Author: William Lieurance <william.lieura...@namikoda.com>
Authored: Sun Feb 11 19:38:31 2018 -0600
Committer: William Lieurance <william.lieura...@namikoda.com>
Committed: Sun Feb 11 19:38:31 2018 -0600

----------------------------------------------------------------------
 .../tamaya/core/internal/converters/CharConverter.java       | 3 +++
 .../tamaya/core/internal/converters/CharConverterTest.java   | 8 ++++++++
 .../internal/converters/ConverterTestsPropertySource.java    | 2 ++
 3 files changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a606c878/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
----------------------------------------------------------------------
diff --git 
a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
 
b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
index 3895969..7958ac3 100644
--- 
a/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
+++ 
b/code/core/src/main/java/org/apache/tamaya/core/internal/converters/CharConverter.java
@@ -49,6 +49,9 @@ public class CharConverter implements 
PropertyConverter<Character>{
         }
         if(trimmed.startsWith("'")) {
             try {
+                if (trimmed.length() == 1){
+                    return '\'';
+                }
                 trimmed = trimmed.substring(1, trimmed.length() - 1);
                 if (trimmed.isEmpty()) {
                     return null;

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a606c878/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
----------------------------------------------------------------------
diff --git 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
index c420fcd..12810cf 100644
--- 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
+++ 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/CharConverterTest.java
@@ -54,6 +54,14 @@ public class CharConverterTest {
     }
 
     @Test
+    public void testConvert_Character_SingleQuote() throws Exception {
+        Configuration config = ConfigurationProvider.getConfiguration();
+        Character valueRead = config.get("tests.converter.char.single-quote", 
Character.class);
+        assertThat(valueRead).isNotNull();
+        assertEquals(valueRead.charValue(), '\'');
+    }
+
+    @Test
     public void testConvert_Character_WithWhitespace_Before() throws Exception 
{
         Configuration config = ConfigurationProvider.getConfiguration();
         Character valueRead = config.get("tests.converter.char.f-before", 
Character.class);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a606c878/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
----------------------------------------------------------------------
diff --git 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
index d09ed8d..dd7649f 100644
--- 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
+++ 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
@@ -101,6 +101,8 @@ public class ConverterTestsPropertySource implements 
PropertySource{
                 return PropertyValue.of(key, "f", getName());
             case "tests.converter.char.d":
                 return PropertyValue.of(key, "'d'", getName());
+            case "tests.converter.char.single-quote":
+                return PropertyValue.of(key, "'", getName());
             case "tests.converter.char.f-before":
                 return PropertyValue.of(key, "  f", getName());
             case "tests.converter.char.f-after":

Reply via email to