groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [1/3] groovy git commit: Add more constructors for `GProperties`
Date Sun, 04 Nov 2018 15:43:46 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 8e24158b0 -> 31dac5003


Add more constructors for `GProperties`


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

Branch: refs/heads/master
Commit: 31dac50038832dc9936c7a40b4ae2f670b0d96e5
Parents: 88ed93e
Author: Daniel Sun <sunlan@apache.org>
Authored: Sun Nov 4 23:29:36 2018 +0800
Committer: Daniel Sun <sunlan@apache.org>
Committed: Sun Nov 4 23:43:06 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/util/GProperties.groovy | 22 ++++++++++++++++++-
 src/test/groovy/util/GPropertiesTest.groovy    | 24 +++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/31dac500/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 2a0686c..bbd916e 100644
--- a/src/main/groovy/groovy/util/GProperties.groovy
+++ b/src/main/groovy/groovy/util/GProperties.groovy
@@ -93,13 +93,33 @@ class GProperties extends Properties {
     private final List<GProperties> importPropertiesList = new LinkedList<>()
 
     GProperties() {
-        this(null)
+        this((Properties) null)
+    }
+
+    GProperties(Reader reader) throws IOException {
+        this()
+        load(reader)
+    }
+
+    GProperties(InputStream inStream) throws IOException {
+        this()
+        load(inStream)
     }
 
     GProperties(Properties defaults) {
         super(defaults)
     }
 
+    GProperties(Properties defaults, Reader reader) throws IOException {
+        this(defaults)
+        load(reader)
+    }
+
+    GProperties(Properties defaults, InputStream inStream) throws IOException {
+        this(defaults)
+        load(inStream)
+    }
+
     @Override
     String getProperty(String key) {
         String value = super.getProperty(key)

http://git-wip-us.apache.org/repos/asf/groovy/blob/31dac500/src/test/groovy/util/GPropertiesTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/GPropertiesTest.groovy b/src/test/groovy/util/GPropertiesTest.groovy
index 65a9c61..329d16f 100644
--- a/src/test/groovy/util/GPropertiesTest.groovy
+++ b/src/test/groovy/util/GPropertiesTest.groovy
@@ -189,4 +189,28 @@ class GPropertiesTest extends GroovyTestCase {
         assert new Boolean(true) == gp.getBoolean('property.boolean', false)
         assert new Boolean(false) == gp.getBoolean('property.boolean.missing', false)
     }
+
+    void testConstructor() {
+        def gp = new GProperties(new InputStreamReader(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties')))
+
+        assert 'Hello' == gp.getProperty('greeting.word')
+    }
+
+    void testConstructor2() {
+        def gp = new GProperties(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert 'Hello' == gp.getProperty('greeting.word')
+    }
+
+    void testConstructor3() {
+        def gp = new GProperties(new Properties(['property.missing': 'Missing']), new InputStreamReader(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties')))
+
+        assert 'Missing' == gp.getProperty('property.missing')
+    }
+
+    void testConstructor4() {
+        def gp = new GProperties(new Properties(['property.missing': 'Missing']), GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert 'Missing' == gp.getProperty('property.missing')
+    }
 }


Mime
View raw message