You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/07/13 12:43:03 UTC

groovy git commit: remove usage of a deprecated class plus minor refactoring

Repository: groovy
Updated Branches:
  refs/heads/master 97a0c03b0 -> 11ced4307


remove usage of a deprecated class plus minor refactoring


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

Branch: refs/heads/master
Commit: 11ced430748e7646f50215afbcf2188624dc2f3a
Parents: 97a0c03
Author: Paul King <pa...@asert.com.au>
Authored: Fri Jul 13 22:42:56 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Fri Jul 13 22:42:56 2018 +1000

----------------------------------------------------------------------
 .../groovy/tools/LoaderConfigurationTest.groovy | 72 +++++++++++---------
 1 file changed, 38 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/11ced430/src/test/org/codehaus/groovy/tools/LoaderConfigurationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/tools/LoaderConfigurationTest.groovy b/src/test/org/codehaus/groovy/tools/LoaderConfigurationTest.groovy
index 54e3376..4090fa9 100644
--- a/src/test/org/codehaus/groovy/tools/LoaderConfigurationTest.groovy
+++ b/src/test/org/codehaus/groovy/tools/LoaderConfigurationTest.groovy
@@ -25,7 +25,7 @@ class LoaderConfigurationTest extends GroovyTestCase {
 
         def config = new LoaderConfiguration()
         config.requireMain = false
-        config.configure(new StringBufferInputStream(txt))
+        configFromString(config, txt)
 
         assert config.classPathUrls.length == 0
     }
@@ -37,40 +37,31 @@ class LoaderConfigurationTest extends GroovyTestCase {
 
         def config = new LoaderConfiguration()
         config.requireMain = false
-        config.configure(new StringBufferInputStream(txt))
+        configFromString(config, txt)
 
         assert config.classPathUrls.length == 1
         assert config.classPathUrls[0].sameFile(file.toURI().toURL())
     }
 
-    void testNonexistingPath() {
+    void testNonExistingPath() {
         // generate a load instruction with a non-existing path
-        def file = getNonexistantFile(new File("."))
+        def file = getNonExistingFile(new File("."))
 
         def txt = "load $file"
 
         def config = new LoaderConfiguration()
         config.requireMain = false
-        config.configure(new StringBufferInputStream(txt))
+        configFromString(config, txt)
 
         assert config.classPathUrls.length == 0
     }
 
-    private File getNonexistantFile(File base) {
-        def number = "0"
-        while (base.exists()) {
-            base = new File(base, number)
-            number++
-        }
-        return base
-    }
-
     void testExistingProperty() {
         def txt = 'load ${java.home}'
 
         def config = new LoaderConfiguration()
         config.requireMain = false
-        config.configure(new StringBufferInputStream(txt))
+        configFromString(config, txt)
 
         assert config.classPathUrls.length == 1
         def url1 = config.classPathUrls[0]
@@ -78,58 +69,71 @@ class LoaderConfigurationTest extends GroovyTestCase {
         assert url1.sameFile(url2)
     }
 
-    void testPropertyDefn() {
+    void testPropertyDefinition() {
         System.setProperty('myprop', 'baz')
         def txt = 'property foo1=bar\nproperty foo2=${myprop}\nproperty foo3=!{myprop}'
 
         def config = new LoaderConfiguration()
         config.requireMain = false
-        config.configure(new StringBufferInputStream(txt))
+        configFromString(config, txt)
         assert System.getProperty('foo1') == 'bar'
         assert System.getProperty('foo2') == 'baz'
         assert System.getProperty('foo3') == 'baz'
     }
 
-    void testNonexistingProperty() {
-        String name = getNonexistingPropertyName("foo")
+    void testNonExistingProperty() {
+        String name = getNonExistingPropertyName("foo")
 
         def txt = 'load !{' + name + '}'
 
         def config = new LoaderConfiguration()
         config.requireMain = false
         shouldFail {
-            config.configure(new StringBufferInputStream(txt))
+            configFromString(config, txt)
         }
 
         txt = 'load ${' + name + '}'
 
         config = new LoaderConfiguration()
         config.requireMain = false
-        config.configure(new StringBufferInputStream(txt))
+        configFromString(config, txt)
 
         assert config.classPathUrls.length == 0
     }
 
-    private getNonexistingPropertyName(String base) {
-        while (System.getProperty(base) != null) {
-            base += "x"
-        }
-        return base
-    }
-    
     void testSlashCorrection() {
-        def prop = getNonexistingPropertyName("nope")
-        System.setProperty("prop",'/')
-        
-        def txt = 'load ${prop}/'
+        def prop = getNonExistingPropertyName("nope")
+        System.setProperty(prop,'/')
+
+        def txt = "load \${$prop}/"
 
         def config = new LoaderConfiguration()
         config.requireMain = false
-        config.configure(new StringBufferInputStream(txt))
+        configFromString(config, txt)
 
         assert config.classPathUrls.length == 1
         def url = config.classPathUrls[0]
         assert !url.path.endsWith("//")
-        System.setProperty("prop","")
+        System.setProperty(prop, "")
+    }
+
+    private static configFromString(LoaderConfiguration config, String txt) {
+        config.configure(new ByteArrayInputStream(txt.bytes))
+    }
+
+    private static getNonExistingPropertyName(String base) {
+        while (System.getProperty(base) != null) {
+            base += "x"
+        }
+        return base
+    }
+
+    private static File getNonExistingFile(File base) {
+        def number = "0"
+        while (base.exists()) {
+            base = new File(base, number)
+            number++
+        }
+        return base
     }
 }
\ No newline at end of file