groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] branch master updated: JUnit 4 refactor
Date Fri, 30 Aug 2019 19:28:26 GMT
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c3da9c  JUnit 4 refactor
4c3da9c is described below

commit 4c3da9c84ffeb17a62bce0f7c5302f04092f7fc4
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Fri Aug 30 14:19:47 2019 -0500

    JUnit 4 refactor
---
 src/test/groovy/bugs/Groovy3311.groovy             | 55 ++++++++++++++++++++++
 src/test/groovy/bugs/Groovy3311Bug.groovy          | 33 -------------
 .../{Groovy8943Bug.groovy => Groovy8943.groovy}    | 10 +++-
 .../{Groovy8947Bug.groovy => Groovy8947.groovy}    | 39 ++++++++-------
 .../{Groovy9215Bug.groovy => Groovy9215.groovy}    | 49 +++++++++++--------
 .../{Groovy9217Bug.groovy => Groovy9217.groovy}    | 21 ++++++---
 .../{Groovy9226Bug.groovy => Groovy9226.groovy}    | 17 +++++--
 7 files changed, 143 insertions(+), 81 deletions(-)

diff --git a/src/test/groovy/bugs/Groovy3311.groovy b/src/test/groovy/bugs/Groovy3311.groovy
new file mode 100644
index 0000000..b95c4c4
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy3311.groovy
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class Groovy3311 {
+
+    @Test
+    void testStaticInitUsingOwnConstructor() {
+        assertScript '''
+            class Day extends Date {
+                static Day get(_date) {
+                    return new Day(new java.text.SimpleDateFormat('MM.dd.yyyy').parse(_date))
+                }
+                Day(Date _date) {
+                    super(_date.time)
+                    def time = getTime()
+                    24.times { hour ->
+                        hoursOfTheDay << new Date(time + hour*1000*60*60)
+                    }
+                }
+                List<Date> hoursOfTheDay = []
+
+                @Override String toString() {
+                    this.format('MM.dd.yyyy')
+                }
+
+                static def period = (1..3).collect { get "12.3${it}.1999" }
+            }
+
+            assert Day.period*.toString() == ['12.31.1999', '01.01.2000', '01.02.2000']
+        '''
+    }
+}
diff --git a/src/test/groovy/bugs/Groovy3311Bug.groovy b/src/test/groovy/bugs/Groovy3311Bug.groovy
deleted file mode 100644
index 9b41244..0000000
--- a/src/test/groovy/bugs/Groovy3311Bug.groovy
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-package groovy.bugs
-
-class Groovy3311Bug extends GroovyTestCase {
-    static period = new Groovy3311Bug()
-    static period2 = 24
-
-    def Groovy3311Bug() {
-        // the pre-defined constant for 24 should be correctly init before next statement
-        assert (24 != null)
-    }
-
-    def void testStaticInitUsingOwnConstructorUsingAPredefinedConstant() {
-        assert (Groovy3311Bug.period2 == 24)
-    }
-}
diff --git a/src/test/groovy/bugs/Groovy8943Bug.groovy b/src/test/groovy/bugs/Groovy8943.groovy
similarity index 88%
rename from src/test/groovy/bugs/Groovy8943Bug.groovy
rename to src/test/groovy/bugs/Groovy8943.groovy
index 1721bba..69fd9d2 100644
--- a/src/test/groovy/bugs/Groovy8943Bug.groovy
+++ b/src/test/groovy/bugs/Groovy8943.groovy
@@ -18,7 +18,15 @@
  */
 package groovy.bugs
 
-class Groovy8943Bug extends GroovyTestCase {
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class Groovy8943 {
+
+    @Test
     void testImplicitGetAtInStaticMethod() {
         assertScript '''
             class Pippo {
diff --git a/src/test/groovy/bugs/Groovy8947Bug.groovy b/src/test/groovy/bugs/Groovy8947.groovy
similarity index 87%
rename from src/test/groovy/bugs/Groovy8947Bug.groovy
rename to src/test/groovy/bugs/Groovy8947.groovy
index 5c858b3..d7f8c6c 100644
--- a/src/test/groovy/bugs/Groovy8947Bug.groovy
+++ b/src/test/groovy/bugs/Groovy8947.groovy
@@ -18,13 +18,21 @@
  */
 package groovy.bugs
 
-class Groovy8947Bug extends GroovyTestCase {
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+import static groovy.test.GroovyAssert.shouldFail
+
+@CompileStatic
+final class Groovy8947 {
+
+    @Test
     void testResolvingNonStaticInnerClass() {
         assertScript '''
             public class Computer {
                 public class Cpu {
                     int coreNumber
-            
                     public Cpu(int coreNumber) {
                         this.coreNumber = coreNumber
                     }
@@ -33,60 +41,57 @@ class Groovy8947Bug extends GroovyTestCase {
                     return new Computer().new Cpu(coreNumber)
                 }
             }
-            
+
             assert 4 == new Computer().new Cpu(4).coreNumber
-            
             assert 4 == Computer.newCpuInstance(4).coreNumber
             assert 0 == new HashSet(new ArrayList()).size()
         '''
     }
 
+    @Test
     void testResolvingNonStaticInnerClass2() {
         assertScript '''
             public class Computer {
                 public class Cpu {
                     int coreNumber
-            
                     public Cpu(int coreNumber) {
                         this.coreNumber = coreNumber
                     }
                 }
-                
                 static newComputerInstance() {
                     return new Computer()
                 }
-                
                 static newCpuInstance(int coreNumber) {
                     // `new Cpu(coreNumber)` is inside of the outer class `Computer`, so
we can resolve `Cpu`
                     return newComputerInstance().new Cpu(coreNumber)
-                } 
+                }
             }
-            
-            assert 4 == Computer.newCpuInstance(4).coreNumber 
+
+            assert 4 == Computer.newCpuInstance(4).coreNumber
         '''
     }
 
+    @Test
     void testResolvingNonStaticInnerClass3() {
-        def errMsg = shouldFail '''
+        def err = shouldFail '''
             public class Computer {
                 public class Cpu {
                     int coreNumber
-            
+
                     public Cpu(int coreNumber) {
                         this.coreNumber = coreNumber
                     }
                 }
             }
-            
             def newComputerInstance() {
                 return new Computer()
             }
-            
-            // `new Cpu(4)` is outside of outer class `Computer` and the return type of `newComputerInstance()`
can not be resolved, 
+
+            // `new Cpu(4)` is outside of outer class `Computer` and the return type of `newComputerInstance()`
can not be resolved,
             // so we does not support this syntax outside of outer class
-            assert 4 == newComputerInstance().new Cpu(4).coreNumber 
+            assert 4 == newComputerInstance().new Cpu(4).coreNumber
         '''
 
-        assert errMsg.contains('unable to resolve class Cpu')
+        assert err =~ 'unable to resolve class Cpu'
     }
 }
diff --git a/src/test/groovy/bugs/Groovy9215Bug.groovy b/src/test/groovy/bugs/Groovy9215.groovy
similarity index 93%
rename from src/test/groovy/bugs/Groovy9215Bug.groovy
rename to src/test/groovy/bugs/Groovy9215.groovy
index d534515..ebbb695 100644
--- a/src/test/groovy/bugs/Groovy9215Bug.groovy
+++ b/src/test/groovy/bugs/Groovy9215.groovy
@@ -19,12 +19,20 @@
 
 package groovy.bugs
 
-class Groovy9215Bug extends GroovyTestCase {
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class Groovy9215 {
+
+    @Test
     void testDuplicatedAnnotations1() {
         assertScript '''
             import groovy.transform.CompileStatic
             import groovy.transform.TypeChecked
-            
+
             @TypeChecked
             @CompileStatic
             class Data {
@@ -32,16 +40,16 @@ class Groovy9215Bug extends GroovyTestCase {
                     c("hello")
                 }
             }
-            
+
             @CompileStatic
             @CompileStatic
             class Op {
                 public Data d = new Data()
-            
+
                 void aFunc(Closure c){
                     c()
                 }
-            
+
                 void broken() {
                     aFunc({
                         d.getThing({ String res ->
@@ -50,16 +58,17 @@ class Groovy9215Bug extends GroovyTestCase {
                     })
                 }
             }
-            
+
             assert Op.class
         '''
     }
 
+    @Test
     void testDuplicatedAnnotations2() {
         assertScript '''
             import groovy.transform.CompileStatic
             import groovy.transform.TypeChecked
-            
+
             @TypeChecked
             @CompileStatic
             class Data {
@@ -67,16 +76,16 @@ class Groovy9215Bug extends GroovyTestCase {
                     c("hello")
                 }
             }
-            
+
             @TypeChecked
             @CompileStatic
             class Op {
                 public Data d = new Data()
-            
+
                 void aFunc(Closure c){
                     c()
                 }
-            
+
                 void broken() {
                     aFunc({
                         d.getThing({ String res ->
@@ -85,16 +94,17 @@ class Groovy9215Bug extends GroovyTestCase {
                     })
                 }
             }
-            
+
             assert Op.class
         '''
     }
 
+    @Test
     void testDuplicatedAnnotations3() {
         assertScript '''
             import groovy.transform.CompileStatic
             import groovy.transform.TypeChecked
-            
+
             @TypeChecked
             @CompileStatic
             class Data {
@@ -102,16 +112,16 @@ class Groovy9215Bug extends GroovyTestCase {
                     c("hello")
                 }
             }
-            
+
             @TypeChecked
             @TypeChecked
             class Op {
                 public Data d = new Data()
-            
+
                 void aFunc(Closure c){
                     c()
                 }
-            
+
                 void broken() {
                     aFunc({
                         d.getThing({ String res ->
@@ -120,21 +130,22 @@ class Groovy9215Bug extends GroovyTestCase {
                     })
                 }
             }
-            
+
             assert Op.class
         '''
     }
 
+    @Test
     void testDuplicatedAnnotations4() {
         assertScript '''
             import groovy.transform.CompileDynamic
             import groovy.transform.CompileStatic
             import groovy.transform.TypeChecked
-            
+
             class Person {
                 String name
             }
-            
+
             @CompileStatic  // ignored
             @CompileDynamic // taken effect
             @TypeChecked    // ignored
@@ -143,7 +154,7 @@ class Groovy9215Bug extends GroovyTestCase {
                 def person = new Person(name:"Daniel.Sun")
                 assert "I'm Daniel.Sun" == person.introduce()
             }
-            
+
             x()
         '''
     }
diff --git a/src/test/groovy/bugs/Groovy9217Bug.groovy b/src/test/groovy/bugs/Groovy9217.groovy
similarity index 66%
rename from src/test/groovy/bugs/Groovy9217Bug.groovy
rename to src/test/groovy/bugs/Groovy9217.groovy
index 3d11c93..d8ac56b 100644
--- a/src/test/groovy/bugs/Groovy9217Bug.groovy
+++ b/src/test/groovy/bugs/Groovy9217.groovy
@@ -18,12 +18,21 @@
  */
 package groovy.bugs
 
-// TODO add JVM option `--illegal-access=deny` when all warnings fixed
-class Groovy9217Bug extends GroovyTestCase {
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+// TODO: add JVM option `--illegal-access=deny` when all warnings fixed
+@CompileStatic
+final class Groovy9217 {
+
+    @Test
     void testSetProperty() {
-        HttpURLConnection conn = new URL('http://www.bing.com').openConnection() as HttpURLConnection
-        conn.requestMethod = 'HEAD'
-        assert 'HEAD' == conn.requestMethod
-        conn.disconnect()
+        def conn = new URL('http://www.bing.com').openConnection() as HttpURLConnection
+        try {
+            conn.requestMethod = 'HEAD'
+            assert 'HEAD' == conn.requestMethod
+        } finally {
+            conn.disconnect()
+        }
     }
 }
diff --git a/src/test/groovy/bugs/Groovy9226Bug.groovy b/src/test/groovy/bugs/Groovy9226.groovy
similarity index 89%
rename from src/test/groovy/bugs/Groovy9226Bug.groovy
rename to src/test/groovy/bugs/Groovy9226.groovy
index 30fd05d..a2bb199 100644
--- a/src/test/groovy/bugs/Groovy9226Bug.groovy
+++ b/src/test/groovy/bugs/Groovy9226.groovy
@@ -19,25 +19,32 @@
 
 package groovy.bugs
 
-class Groovy9226Bug extends GroovyTestCase {
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class Groovy9226 {
+
+    @Test
     void testDuplicatedAnnotations5() {
         assertScript '''
             import groovy.transform.CompileStatic
             import groovy.transform.TypeChecked
-            
+
             @CompileStatic
             class Super {
               String toString() { 'Super' }
             }
-            
+
             @TypeChecked
             @CompileStatic
             class Child extends Super {
               String toString() { 'Child extends ' + super.toString() }
             }
-            
+
             assert new Child().toString()
         '''
     }
-
 }


Mime
View raw message