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 2020/10/11 01:49:00 UTC

[groovy] 01/02: minor refactor to junit4

This is an automated email from the ASF dual-hosted git repository.

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

commit 4e610808d9f6dde3d021370385ee7c1f7d0b9ed6
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Oct 11 09:18:44 2020 +1000

    minor refactor to junit4
---
 .../groovy/grape/GrabErrorIsolationTest.groovy     |  8 ++---
 src/test/groovy/grape/GrabExcludeTest.groovy       | 41 ++++++++++++++--------
 2 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/src/test/groovy/grape/GrabErrorIsolationTest.groovy b/src/test/groovy/grape/GrabErrorIsolationTest.groovy
index 4bd6646..c73b8d5 100644
--- a/src/test/groovy/grape/GrabErrorIsolationTest.groovy
+++ b/src/test/groovy/grape/GrabErrorIsolationTest.groovy
@@ -18,14 +18,14 @@
  */
 package groovy.grape
 
-import groovy.test.GroovyTestCase
+import org.junit.Test
 
 /**
- * Test for GROOVY-3853. Kept with other grab tests and not normally
- * run unless -Djunit.network=true is set on command line.
+ * Test for GROOVY-3853.
  */
-class GrabErrorIsolationTest extends GroovyTestCase {
+class GrabErrorIsolationTest {
 
+    @Test
     void testConsecutiveGrabCallsWithASharedLoaderWhereFirstGrabFails() {
         def classLoader = new GroovyClassLoader()
 
diff --git a/src/test/groovy/grape/GrabExcludeTest.groovy b/src/test/groovy/grape/GrabExcludeTest.groovy
index 1872103..2f89c5d 100644
--- a/src/test/groovy/grape/GrabExcludeTest.groovy
+++ b/src/test/groovy/grape/GrabExcludeTest.groovy
@@ -18,61 +18,72 @@
  */
 package groovy.grape
 
-import groovy.test.GroovyTestCase
 import org.codehaus.groovy.control.MultipleCompilationErrorsException
+import org.junit.BeforeClass
+import org.junit.Test
 
-class GrabExcludeTest extends GroovyTestCase {
+import static groovy.test.GroovyAssert.shouldFail
 
-    public GrabClassLoaderTest() {
-        // insure files are installed locally
+class GrabExcludeTest {
+
+    @BeforeClass
+    static void populateCache() {
+        // ensure files are installed locally
         Grape.resolve([autoDownload:true, classLoader:new GroovyClassLoader()],
         [groupId:'org.mortbay.jetty', artifactId:'jetty', version:'6.0.0'])
     }
 
+    @Test
     void testExcludeByGroupAndModule() {
-        assertCompilationFailsWithMessageContainingString("""
+        shouldFailCompilationWithMessage('''
                 @Grab('org.mortbay.jetty:jetty:6.0.0')
                 @GrabExclude(group='org.mortbay.jetty', module='jetty-util')
                 static testMethod() {
                     // access class from excluded module to provoke an error
                     org.mortbay.util.IO.name
-                }""",
+                }
+                ''',
                 "Apparent variable 'org' was found")
     }
 
+    @Test
     void testExcludeByValue() {
-       assertCompilationFailsWithMessageContainingString("""
+       shouldFailCompilationWithMessage('''
                 @Grab('org.mortbay.jetty:jetty:6.0.0')
                 @GrabExclude('org.mortbay.jetty:jetty-util')
                 static testMethod() {
                     // access class from excluded module to provoke an error
                     org.mortbay.util.IO.name
-                }""",
+                }
+                ''',
                 "Apparent variable 'org' was found")
     }
 
+    @Test
     void testExcludeByGroupAndModule_requiresGroup() {
-       assertCompilationFailsWithMessageContainingString("""
+       shouldFailCompilationWithMessage('''
                 @Grab('org.mortbay.jetty:jetty:6.0.0')
                 @GrabExclude(module='jetty-util')
-                class AnnotatedClass { }""",
+                class AnnotatedClass { }
+                ''',
                 'The missing attribute "group" is required in @GrabExclude annotations')
     }
 
+    @Test
     void testExcludeByGroupAndModule_requiresModule() {
-        assertCompilationFailsWithMessageContainingString("""
+        shouldFailCompilationWithMessage('''
                 @Grab('org.mortbay.jetty:jetty:6.0.0')
                 @GrabExclude(group='org.mortbay.jetty')
-                class AnnotatedClass { }""",
+                class AnnotatedClass { }
+                ''',
                 'The missing attribute "module" is required in @GrabExclude annotations')
     }
 
-    private assertCompilationFailsWithMessageContainingString(String code, String expectedString) {
+    private static shouldFailCompilationWithMessage(String code, String expectedString) {
         GroovyClassLoader loader = new GroovyClassLoader()
         String exceptionMessage = shouldFail(MultipleCompilationErrorsException) {
-            Class testClass = loader.parseClass(code)
+            loader.parseClass(code)
         }
-        
         assert exceptionMessage.contains(expectedString)
     }
 }