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 15:43:46 UTC

[1/3] groovy git commit: Add more constructors for `GProperties`

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 <su...@apache.org>
Authored: Sun Nov 4 23:29:36 2018 +0800
Committer: Daniel Sun <su...@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')
+    }
 }


[3/3] groovy git commit: Abandon evaluating script to avoid security issues

Posted by su...@apache.org.
Abandon evaluating script to avoid security issues


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

Branch: refs/heads/master
Commit: 1d20e307251aedde4f73abe879e2b548f2d16a17
Parents: 8e24158
Author: Daniel Sun <su...@apache.org>
Authored: Sun Nov 4 22:07:32 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Sun Nov 4 23:43:06 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/util/GProperties.groovy  | 66 +++++---------------
 .../groovy/util/gproperties.properties          |  6 +-
 .../groovy/util/gproperties_import2.properties  |  2 +-
 src/test/groovy/util/GPropertiesTest.groovy     | 38 ++---------
 4 files changed, 21 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/1d20e307/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 500baf5..fe42982 100644
--- a/src/main/groovy/groovy/util/GProperties.groovy
+++ b/src/main/groovy/groovy/util/GProperties.groovy
@@ -57,26 +57,15 @@ import java.util.regex.Pattern
  *      assert 'Hello,Daniel' == gp.getProperty('greeting.daniel')
  * </pre>
  *
- * 3) Evaluating with ${...}, e.g.
+ * 3) Escaping with {{...}}, e.g.
  * <pre>
  *      # gproperties.properties
- *      greeting.daniel=Hello,Daniel in ${new java.text.SimpleDateFormat('yyyyMMdd').format(new Date())}
+ *      greeting.daniel={{groovy.greeting}},{{some.name}}
  *
  *      // groovy script
- *      def gp = new GProperties(true) // Note: we should enable evaluating script manually
- *      gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
- *      assert 'Hello,Daniel in 2018' == gp.getProperty('greeting.daniel') // Given running the script in 2018
- * </pre>
- *
- * 4) Escaping with {{...}}, ${{...}}, e.g.
- * <pre>
- *      # gproperties.properties
- *      greeting.daniel={{groovy.greeting}},{{some.name}} in ${{new java.text.SimpleDateFormat('yyyyMMdd').format(new Date())}}
- *
- *      // groovy script
- *      def gp = new GProperties(true)
+ *      def gp = new GProperties()
  *      gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
- *      assert '{groovy.greeting},{some.name} in ${new java.text.SimpleDateFormat('yyyyMMdd').format(new Date())}' == gp.getProperty('greeting.daniel')
+ *      assert '{groovy.greeting},{some.name}' == gp.getProperty('greeting.daniel')
  * </pre>
  *
  * @since 3.0.0
@@ -85,63 +74,46 @@ import java.util.regex.Pattern
 class GProperties extends Properties {
     private static final long serialVersionUID = 6112578636029876860L
     public static final String IMPORT_PROPERTIES_KEY = 'import.properties'
-    public static final String VAR_KEY = 'key'
-    public static final String VAR_PROPERTIES = 'properties'
-    private static final Pattern GROOVY_SCRIPT_PATTERN = Pattern.compile(/[$][{]\s*(.+?)\s*[}]/)
-    private static final Pattern INTERPOLATE_PATTERN = Pattern.compile(/[{]\s*(.+?)\s*[}]/)
+    private static final Pattern INTERPOLATE_PATTERN = Pattern.compile(/[{](.+?)[}]/)
     private static final Pattern ESCAPE_PATTERN = Pattern.compile(/[{]([{].+?[}])[}]/)
     private static final String LEFT_CURLY_BRACE = '{'
     private static final String RIGHT_CURLY_BRACE = '}'
     private static final String COMMA = ','
-    private final boolean evaluateScriptEnabled
-    private final GroovyShell groovyShell
-    private final List<GProperties> importPropertiesList = new ArrayList<>()
+    private final List<GProperties> importPropertiesList = new LinkedList<>()
 
-    GProperties(boolean evaluateScriptEnabled=false, GroovyShell groovyShell=new GroovyShell()) {
-        this(null, evaluateScriptEnabled, groovyShell)
+    GProperties() {
+        this(null)
     }
 
-    GProperties(Properties defaults, boolean evaluateScriptEnabled=false, GroovyShell groovyShell=new GroovyShell()) {
+    GProperties(Properties defaults) {
         super(defaults)
-        this.evaluateScriptEnabled = evaluateScriptEnabled
-        this.groovyShell = groovyShell
     }
 
     @Override
     String getProperty(String key) {
         String value = super.getProperty(key)
 
-        if (!value) {
+        if (null == value) {
             for (GProperties importProperties : importPropertiesList) {
                 value = importProperties.getProperty(key)
 
-                if (value) {
+                if (null != value) {
                     break
                 }
             }
         }
 
-        if (!value) {
+        if (null == value) {
             return value
         }
 
-        if (evaluateScriptEnabled) {
-            value = value.replaceAll(GROOVY_SCRIPT_PATTERN) { String _0, String _1 ->
-                if (_1.startsWith(LEFT_CURLY_BRACE) && _1.endsWith(RIGHT_CURLY_BRACE)) {
-                    return _0
-                }
-                processImplicitVariables(key) {
-                    groovyShell.evaluate(_1)
-                }
-            }
-        }
-
         value = value.replaceAll(INTERPOLATE_PATTERN) { String _0, String _1 ->
             if (_1.startsWith(LEFT_CURLY_BRACE) && _1.endsWith(RIGHT_CURLY_BRACE)) {
                 return _0
             }
 
-            this.getProperty(_1) ?: _0
+            def p = this.getProperty(_1.trim())
+            null == p ? _0 : p
         }
 
         value.replaceAll(ESCAPE_PATTERN) { String _0, String _1 ->
@@ -191,14 +163,4 @@ class GProperties extends Properties {
             importPropertiesList << importProperties
         }
     }
-
-    private synchronized Object processImplicitVariables(String key, Closure c) {
-        groovyShell.setVariable(VAR_KEY, key)
-        groovyShell.setVariable(VAR_PROPERTIES, this)
-        def v = c()
-        groovyShell.removeVariable(VAR_PROPERTIES)
-        groovyShell.removeVariable(VAR_KEY)
-
-        return v
-    }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/1d20e307/src/test-resources/groovy/util/gproperties.properties
----------------------------------------------------------------------
diff --git a/src/test-resources/groovy/util/gproperties.properties b/src/test-resources/groovy/util/gproperties.properties
index e4f488d..f7f7db3 100644
--- a/src/test-resources/groovy/util/gproperties.properties
+++ b/src/test-resources/groovy/util/gproperties.properties
@@ -20,9 +20,5 @@
 import.properties=/groovy/util/gproperties_import.properties,/groovy/util/gproperties_import3.properties
 groovy.greeting={greeting.word},{some.name}
 groovy.greeting.with.smile={groovy.greeting} :)
-groovy.greeting.with.time={groovy.greeting.with.smile} in ${new java.text.SimpleDateFormat('yyyyMMdd').format(new Date())}
 groovy.greeting.with.missing=Hello,{none} {0}
-groovy.greeting.with.script=Hello,${properties.getProperty('some.name')}
-groovy.greeting.with.key=Hello,${key}
-groovy.greeting.with.escapes=Hello,{{some.name}}
-groovy.greeting.with.escapes2=Hello,${{properties.getProperty('some.name')}}
\ No newline at end of file
+groovy.greeting.with.escapes=Hello,{{some.name}}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/groovy/blob/1d20e307/src/test-resources/groovy/util/gproperties_import2.properties
----------------------------------------------------------------------
diff --git a/src/test-resources/groovy/util/gproperties_import2.properties b/src/test-resources/groovy/util/gproperties_import2.properties
index 7d41c9f..99a9f7a 100644
--- a/src/test-resources/groovy/util/gproperties_import2.properties
+++ b/src/test-resources/groovy/util/gproperties_import2.properties
@@ -17,4 +17,4 @@
 #  under the License.
 #
 
-greeting.word=H${'ell'}o
+greeting.word=Hello

http://git-wip-us.apache.org/repos/asf/groovy/blob/1d20e307/src/test/groovy/util/GPropertiesTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/GPropertiesTest.groovy b/src/test/groovy/util/GPropertiesTest.groovy
index fe9ae0d..8967d66 100644
--- a/src/test/groovy/util/GPropertiesTest.groovy
+++ b/src/test/groovy/util/GPropertiesTest.groovy
@@ -20,7 +20,7 @@ package groovy.util
 
 class GPropertiesTest extends GroovyTestCase {
     void testImportProperties() {
-        def gp = new GProperties(true)
+        def gp = new GProperties()
         gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
 
         assert '/groovy/util/gproperties_import.properties,/groovy/util/gproperties_import3.properties' == gp.getProperty('import.properties')
@@ -30,14 +30,14 @@ class GPropertiesTest extends GroovyTestCase {
     }
 
     void testInterpolate() {
-        def gp = new GProperties(true)
+        def gp = new GProperties()
         gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
 
         assert 'Hello,Daniel' == gp.getProperty('groovy.greeting')
     }
 
     void testInterpolate2() {
-        def gp = new GProperties(true)
+        def gp = new GProperties()
         gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
 
         assert 'Hello,Daniel :)' == gp.getProperty('groovy.greeting.with.smile')
@@ -51,7 +51,7 @@ class GPropertiesTest extends GroovyTestCase {
     }
 
     void testInterpolate4() {
-        def gp = new GProperties(true)
+        def gp = new GProperties()
         gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
 
         assert 'Hello,Daniel' == gp.getProperty('greeting.daniel')
@@ -61,7 +61,7 @@ class GPropertiesTest extends GroovyTestCase {
         def gp = new GProperties()
         gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
 
-        assert '''H${'ell'}o,Daniel''' == gp.getProperty('greeting.daniel')
+        assert '''Hello,Daniel''' == gp.getProperty('greeting.daniel')
     }
 
     void testEscape() {
@@ -70,32 +70,4 @@ class GPropertiesTest extends GroovyTestCase {
 
         assert 'Hello,{some.name}' == gp.getProperty('groovy.greeting.with.escapes')
     }
-
-    void testEscape2() {
-        def gp = new GProperties()
-        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
-
-        assert '''Hello,${properties.getProperty('some.name')}''' == gp.getProperty('groovy.greeting.with.escapes2')
-    }
-
-    void testInterpolateGroovyScript() {
-        def gp = new GProperties(true)
-        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
-
-        assert "Hello,Daniel :) in ${new java.text.SimpleDateFormat('yyyyMMdd').format(new Date())}" == gp.getProperty('groovy.greeting.with.time')
-    }
-
-    void testInterpolateGroovyScript2() {
-        def gp = new GProperties(true)
-        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
-
-        assert "Hello,Daniel" == gp.getProperty('groovy.greeting.with.script')
-    }
-
-    void testInterpolateGroovyScript3() {
-        def gp = new GProperties(true)
-        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
-
-        assert "Hello,groovy.greeting.with.key" == gp.getProperty('groovy.greeting.with.key')
-    }
 }


[2/3] groovy git commit: Make `GProperties` support getting property with specified type

Posted by su...@apache.org.
Make `GProperties` support getting property with specified type


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

Branch: refs/heads/master
Commit: 88ed93e7c8d77a9c5c9263ba7039d68f420a69b4
Parents: 1d20e30
Author: Daniel Sun <su...@apache.org>
Authored: Sun Nov 4 23:17:47 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Sun Nov 4 23:43:06 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/util/GProperties.groovy  | 109 +++++++++++++++++
 .../groovy/util/gproperties.properties          |  10 +-
 src/test/groovy/util/GPropertiesTest.groovy     | 119 +++++++++++++++++++
 3 files changed, 237 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/88ed93e7/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 fe42982..2a0686c 100644
--- a/src/main/groovy/groovy/util/GProperties.groovy
+++ b/src/main/groovy/groovy/util/GProperties.groovy
@@ -68,6 +68,17 @@ import java.util.regex.Pattern
  *      assert '{groovy.greeting},{some.name}' == gp.getProperty('greeting.daniel')
  * </pre>
  *
+ * 4) Getting property with the specified type(integer, long, boolean, etc.), e.g.
+ * <pre>
+ *      # gproperties.properties
+ *      property.integer=1104
+ *
+ *      // groovy script
+ *      def gp = new GProperties()
+ *      gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+ *      assert new Integer(1104) == gp.getInteger('property.integer')
+ * </pre>
+ *
  * @since 3.0.0
  */
 @CompileStatic
@@ -121,6 +132,104 @@ class GProperties extends Properties {
         }
     }
 
+    Character getCharacter(String key) {
+        getPropertyWithType(key) { String p ->
+            if (!p || p.length() > 1) {
+                throw new IllegalArgumentException("Invalid character: ${p}")
+            }
+
+            Character.valueOf(p as char)
+        }
+    }
+
+    Character getCharacter(String key, Character defaultValue) {
+        getDefaultIfAbsent(key, defaultValue) {
+            getCharacter(key)
+        }
+    }
+
+    Short getShort(String key) {
+        getPropertyWithType(key) { String p ->
+            Short.valueOf(p)
+        }
+    }
+
+    Short getShort(String key, Short defaultValue) {
+        getDefaultIfAbsent(key, defaultValue) {
+            getShort(key)
+        }
+    }
+
+    Integer getInteger(String key) {
+        getPropertyWithType(key) { String p ->
+            Integer.valueOf(p)
+        }
+    }
+
+    Integer getInteger(String key, Integer defaultValue) {
+        getDefaultIfAbsent(key, defaultValue) {
+            getInteger(key)
+        }
+    }
+
+    Long getLong(String key) {
+        getPropertyWithType(key) { String p ->
+            Long.valueOf(p)
+        }
+    }
+
+    Long getLong(String key, Long defaultValue) {
+        getDefaultIfAbsent(key, defaultValue) {
+            getLong(key)
+        }
+    }
+
+    Float getFloat(String key) {
+        getPropertyWithType(key) { String p ->
+            Float.valueOf(p)
+        }
+    }
+
+    Float getFloat(String key, Float defaultValue) {
+        getDefaultIfAbsent(key, defaultValue) {
+            getFloat(key)
+        }
+    }
+
+    Double getDouble(String key) {
+        getPropertyWithType(key) { String p ->
+            Double.valueOf(p)
+        }
+    }
+
+    Double getDouble(String key, Double defaultValue) {
+        getDefaultIfAbsent(key, defaultValue) {
+            getDouble(key)
+        }
+    }
+
+    Boolean getBoolean(String key) {
+        getPropertyWithType(key) { String p ->
+            Boolean.valueOf(p)
+        }
+    }
+
+    Boolean getBoolean(String key, Boolean defaultValue) {
+        getDefaultIfAbsent(key, defaultValue) {
+            getBoolean(key)
+        }
+    }
+
+    private <V> V getPropertyWithType(String key, Closure<V> c) {
+        def p = getProperty(key)
+        null == p ? null : c(p)
+    }
+
+    private <V> V getDefaultIfAbsent(String key, V defaultValue, Closure<V> c) {
+        def p = c(key)
+        null == p ? defaultValue : p
+    }
+
     @Override
     synchronized void load(Reader reader) throws IOException {
         reader.withReader { it ->

http://git-wip-us.apache.org/repos/asf/groovy/blob/88ed93e7/src/test-resources/groovy/util/gproperties.properties
----------------------------------------------------------------------
diff --git a/src/test-resources/groovy/util/gproperties.properties b/src/test-resources/groovy/util/gproperties.properties
index f7f7db3..93f69d5 100644
--- a/src/test-resources/groovy/util/gproperties.properties
+++ b/src/test-resources/groovy/util/gproperties.properties
@@ -21,4 +21,12 @@ import.properties=/groovy/util/gproperties_import.properties,/groovy/util/gprope
 groovy.greeting={greeting.word},{some.name}
 groovy.greeting.with.smile={groovy.greeting} :)
 groovy.greeting.with.missing=Hello,{none} {0}
-groovy.greeting.with.escapes=Hello,{{some.name}}
\ No newline at end of file
+groovy.greeting.with.escapes=Hello,{{some.name}}
+property.character=a
+property.character.invalid=abc
+property.short=126
+property.integer=1104
+property.long=181104
+property.float=18.1104f
+property.double=18.1104d
+property.boolean=true

http://git-wip-us.apache.org/repos/asf/groovy/blob/88ed93e7/src/test/groovy/util/GPropertiesTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/GPropertiesTest.groovy b/src/test/groovy/util/GPropertiesTest.groovy
index 8967d66..65a9c61 100644
--- a/src/test/groovy/util/GPropertiesTest.groovy
+++ b/src/test/groovy/util/GPropertiesTest.groovy
@@ -70,4 +70,123 @@ class GPropertiesTest extends GroovyTestCase {
 
         assert 'Hello,{some.name}' == gp.getProperty('groovy.greeting.with.escapes')
     }
+
+    void testGetCharacter() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Character('a' as char) == gp.getCharacter('property.character')
+        assert null == gp.getCharacter('property.character.missing')
+
+        try {
+            gp.getCharacter('property.character.invalid')
+            assert false
+        } catch (IllegalArgumentException e) {
+            assert e.message.contains('Invalid character')
+        }
+    }
+
+    void testGetCharacterWithDefault() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Character('a' as char) == gp.getCharacter('property.character', 'b' as char)
+        assert new Character('b' as char) == gp.getCharacter('property.character.missing', 'b' as char)
+    }
+
+    void testGetShort() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Short(126 as short) == gp.getShort('property.short')
+        assert null == gp.getShort('property.short.missing')
+    }
+
+    void testGetShortWithDefault() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Short(126 as short) == gp.getShort('property.short', 125 as short)
+        assert new Short(125 as short) == gp.getShort('property.short.missing', 125 as short)
+    }
+
+    void testGetInteger() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Integer(1104) == gp.getInteger('property.integer')
+        assert null == gp.getInteger('property.integer.missing')
+    }
+
+    void testGetIntegerWithDefault() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Integer(1104) == gp.getInteger('property.integer', 1101)
+        assert new Integer(1101) == gp.getInteger('property.integer.missing', 1101)
+    }
+
+    void testGetLong() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Long(181104) == gp.getLong('property.long')
+        assert null == gp.getLong('property.long.missing')
+    }
+
+    void testGetLongWithDefault() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Long(181104) == gp.getLong('property.long', 181101)
+        assert new Long(181101) == gp.getLong('property.long.missing', 181101)
+    }
+
+    void testGetFloat() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Float(18.1104f) == gp.getFloat('property.float')
+        assert null == gp.getFloat('property.float.missing')
+    }
+
+    void testGetFloatWithDefault() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Float(18.1104f) == gp.getFloat('property.float', 18.1101f)
+        assert new Float(18.1101f) == gp.getFloat('property.float.missing', 18.1101f)
+    }
+
+    void testGetDouble() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Double(18.1104d) == gp.getDouble('property.double')
+        assert null == gp.getDouble('property.double.missing')
+    }
+
+    void testGetDoubleWithDefault() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Double(18.1104d) == gp.getDouble('property.double', 18.1101d)
+        assert new Double(18.1101d) == gp.getDouble('property.double.missing', 18.1101d)
+    }
+
+    void testGetBoolean() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Boolean(true) == gp.getBoolean('property.boolean')
+        assert null == gp.getBoolean('property.boolean.missing')
+    }
+
+    void testGetBooleanWithDefault() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert new Boolean(true) == gp.getBoolean('property.boolean', false)
+        assert new Boolean(false) == gp.getBoolean('property.boolean.missing', false)
+    }
 }