You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/11/04 16:05:24 UTC

groovy git commit: Add 2 more constructors for `GProperties`

Repository: groovy
Updated Branches:
  refs/heads/master 31dac5003 -> 98e856479


Add 2 more constructors for `GProperties`

The 2 constructors is very useful for testing


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/98e85647
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/98e85647
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/98e85647

Branch: refs/heads/master
Commit: 98e856479efbdbd6034018e551531a8176618aee
Parents: 31dac50
Author: Daniel Sun <su...@apache.org>
Authored: Mon Nov 5 00:00:51 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Mon Nov 5 00:05:01 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/util/GProperties.groovy | 10 ++++++++++
 src/test/groovy/util/GPropertiesTest.groovy    | 16 ++++++++++++++++
 2 files changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/98e85647/src/main/groovy/groovy/util/GProperties.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/util/GProperties.groovy b/src/main/groovy/groovy/util/GProperties.groovy
index bbd916e..0ed3239 100644
--- a/src/main/groovy/groovy/util/GProperties.groovy
+++ b/src/main/groovy/groovy/util/GProperties.groovy
@@ -101,6 +101,11 @@ class GProperties extends Properties {
         load(reader)
     }
 
+    GProperties(CharSequence content) {
+        this()
+        load(new StringReader(content.toString()))
+    }
+
     GProperties(InputStream inStream) throws IOException {
         this()
         load(inStream)
@@ -115,6 +120,11 @@ class GProperties extends Properties {
         load(reader)
     }
 
+    GProperties(Properties defaults, CharSequence content) {
+        this(defaults)
+        load(new StringReader(content.toString()))
+    }
+
     GProperties(Properties defaults, InputStream inStream) throws IOException {
         this(defaults)
         load(inStream)

http://git-wip-us.apache.org/repos/asf/groovy/blob/98e85647/src/test/groovy/util/GPropertiesTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/GPropertiesTest.groovy b/src/test/groovy/util/GPropertiesTest.groovy
index 329d16f..9a1186a 100644
--- a/src/test/groovy/util/GPropertiesTest.groovy
+++ b/src/test/groovy/util/GPropertiesTest.groovy
@@ -213,4 +213,20 @@ class GPropertiesTest extends GroovyTestCase {
 
         assert 'Missing' == gp.getProperty('property.missing')
     }
+
+    void testConstructor5() {
+        def gp = new GProperties('''
+greeting.world=Hello,world!
+        ''')
+
+        assert 'Hello,world!' == gp.getProperty('greeting.world')
+    }
+
+    void testConstructor6() {
+        def gp = new GProperties(new Properties(['property.missing': 'Missing']), '''
+greeting.world=Hello,world!
+        ''')
+
+        assert 'Missing' == gp.getProperty('property.missing')
+    }
 }