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 9ad4468d78 junit jupiter
9ad4468d78 is described below
commit 9ad4468d7891cc123390b0312b27585d5aafd9d4
Author: Eric Milles <[email protected]>
AuthorDate: Tue Mar 3 10:27:25 2026 -0600
junit jupiter
---
src/test/groovy/bugs/ClassInScriptBug.java | 6 ++-
src/test/groovy/bugs/ClosuresInScriptBug.java | 6 ++-
src/test/groovy/bugs/ScriptBug.java | 6 ++-
.../groovy/lang/ScriptIntegerDivideTest.java | 6 ++-
src/test/groovy/groovy/lang/ScriptPrintTest.java | 7 +--
src/test/groovy/groovy/lang/ScriptTest.java | 44 +++++++---------
src/test/groovy/groovy/tree/NodePrinterTest.java | 24 ++++++---
.../codehaus/groovy/classgen/ConstructorTest.java | 6 ++-
.../org/codehaus/groovy/classgen/ForTest.java | 40 ++++++++------
.../org/codehaus/groovy/classgen/GStringTest.java | 26 ++++++---
.../codehaus/groovy/classgen/GetPropertyTest.java | 12 +++--
.../groovy/classgen/GroovyClassLoaderTest.java | 20 +++----
.../org/codehaus/groovy/classgen/IfElseTest.java | 26 +++++----
.../org/codehaus/groovy/classgen/MainTest.java | 6 ++-
.../org/codehaus/groovy/classgen/MethodTest.java | 27 ++++++----
.../org/codehaus/groovy/classgen/PropertyTest.java | 30 ++++++-----
.../org/codehaus/groovy/classgen/RunBugsTest.java | 61 ++++++++++++++--------
.../codehaus/groovy/classgen/RunClosureTest.java | 34 +++++++-----
.../codehaus/groovy/classgen/RunGroovyTest.java | 21 +++++---
.../codehaus/groovy/classgen/TupleListTest.java | 35 +++++++++----
.../org/codehaus/groovy/classgen/TestSupport.java | 41 +++++++++------
.../src/test/groovy/groovy/xml/DOMTest.groovy | 24 +++++----
.../groovy/groovy/xml/MarkupWithWriterTest.groovy | 10 +++-
.../groovy/xml/NamespaceNodeGPathTest.groovy | 5 +-
.../groovy/groovy/xml/NamespaceNodeTest.groovy | 7 ++-
.../src/test/groovy/groovy/xml/SAXTest.groovy | 12 +++--
.../src/test/groovy/groovy/xml/TestXmlSupport.java | 12 +++--
.../test/groovy/groovy/xml/VerboseDOMTest.groovy | 20 +++----
.../groovy/groovy/xml/bugs/MarkupInScriptBug.java | 7 ++-
.../src/test/groovy/groovy/xml/bugs/SeansBug.java | 10 ++--
.../groovy/groovy/xml/dom/NamespaceDOMTest.groovy | 6 ++-
31 files changed, 375 insertions(+), 222 deletions(-)
diff --git a/src/test/groovy/bugs/ClassInScriptBug.java
b/src/test/groovy/bugs/ClassInScriptBug.java
index bc8433c727..351a7feae9 100644
--- a/src/test/groovy/bugs/ClassInScriptBug.java
+++ b/src/test/groovy/bugs/ClassInScriptBug.java
@@ -19,10 +19,12 @@
package bugs;
import org.codehaus.groovy.classgen.TestSupport;
+import org.junit.jupiter.api.Test;
-public class ClassInScriptBug extends TestSupport {
+final class ClassInScriptBug extends TestSupport {
- public void testBug() throws Exception {
+ @Test
+ void testBug() throws Exception {
assertScript("class X {}\nx = new X()\nprintln(x)");
}
}
diff --git a/src/test/groovy/bugs/ClosuresInScriptBug.java
b/src/test/groovy/bugs/ClosuresInScriptBug.java
index 854f17cc81..bd1809fff3 100644
--- a/src/test/groovy/bugs/ClosuresInScriptBug.java
+++ b/src/test/groovy/bugs/ClosuresInScriptBug.java
@@ -19,10 +19,12 @@
package bugs;
import org.codehaus.groovy.classgen.TestSupport;
+import org.junit.jupiter.api.Test;
-public class ClosuresInScriptBug extends TestSupport {
+final class ClosuresInScriptBug extends TestSupport {
- public void testBug() throws Exception {
+ @Test
+ void testBug() throws Exception {
assertScript("a = 1\n [2].each { a = it }\n assert a == 2");
}
}
diff --git a/src/test/groovy/bugs/ScriptBug.java
b/src/test/groovy/bugs/ScriptBug.java
index b2cfe0252a..063a45e5a2 100644
--- a/src/test/groovy/bugs/ScriptBug.java
+++ b/src/test/groovy/bugs/ScriptBug.java
@@ -19,10 +19,12 @@
package bugs;
import org.codehaus.groovy.classgen.TestSupport;
+import org.junit.jupiter.api.Test;
-public class ScriptBug extends TestSupport {
+final class ScriptBug extends TestSupport {
- public void testBug() throws Exception {
+ @Test
+ void testBug() throws Exception {
assertScript("println 'hello world'");
}
}
diff --git a/src/test/groovy/groovy/lang/ScriptIntegerDivideTest.java
b/src/test/groovy/groovy/lang/ScriptIntegerDivideTest.java
index 3ca8f671e6..68b8497abb 100644
--- a/src/test/groovy/groovy/lang/ScriptIntegerDivideTest.java
+++ b/src/test/groovy/groovy/lang/ScriptIntegerDivideTest.java
@@ -19,13 +19,15 @@
package groovy.lang;
import org.codehaus.groovy.classgen.TestSupport;
+import org.junit.jupiter.api.Test;
-public class ScriptIntegerDivideTest extends TestSupport {
+final class ScriptIntegerDivideTest extends TestSupport {
/**
* Check integer division which is now a method call rather than the
symbol "\".
*/
- public void testIntegerDivide() throws Exception {
+ @Test
+ void testIntegerDivide() throws Exception {
assertScript("assert 4.intdiv(3) == 1");
}
}
diff --git a/src/test/groovy/groovy/lang/ScriptPrintTest.java
b/src/test/groovy/groovy/lang/ScriptPrintTest.java
index dde96c5751..5135a2441e 100644
--- a/src/test/groovy/groovy/lang/ScriptPrintTest.java
+++ b/src/test/groovy/groovy/lang/ScriptPrintTest.java
@@ -19,14 +19,15 @@
package groovy.lang;
import org.codehaus.groovy.classgen.TestSupport;
+import org.junit.jupiter.api.Test;
-public class ScriptPrintTest extends TestSupport {
+final class ScriptPrintTest extends TestSupport {
- public void testScriptWithCustomPrintln() throws Exception {
+ @Test
+ void testScriptWithCustomPrintln() throws Exception {
assertScript(
"out = new MockWriter(); println(); assert out.output ==
'println()', 'value of output is: ' + out.output\n"
+ "print('hey'); assert out.output == 'print(hey)' ,
'value is: ' + out.output\n"
+ "println('hey'); assert out.output ==
'println(hey)', 'value is: ' + out.output\n");
}
-
}
diff --git a/src/test/groovy/groovy/lang/ScriptTest.java
b/src/test/groovy/groovy/lang/ScriptTest.java
index 8dad22af00..7d57fec4cd 100644
--- a/src/test/groovy/groovy/lang/ScriptTest.java
+++ b/src/test/groovy/groovy/lang/ScriptTest.java
@@ -18,38 +18,32 @@
*/
package groovy.lang;
-import org.codehaus.groovy.classgen.TestSupport;
-import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.runtime.MethodClosure;
+import org.junit.jupiter.api.Test;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests some particular script features.
*/
-public class ScriptTest extends TestSupport {
+final class ScriptTest {
+
/**
* When a method is not found in the current script, checks that it's
possible to call a method closure from the binding.
- *
- * @throws IOException
- * @throws CompilationFailedException
- * @throws IllegalAccessException
- * @throws InstantiationException
*/
- public void testInvokeMethodFallsThroughToMethodClosureInBinding() throws
IOException, CompilationFailedException, IllegalAccessException,
InstantiationException, NoSuchMethodException, InvocationTargetException {
+ @Test
+ void testInvokeMethodFallsThroughToMethodClosureInBinding() throws
Exception {
String text = "if (method() == 3) { println 'succeeded' }";
+ try (GroovyClassLoader loader = new
GroovyClassLoader(Thread.currentThread().getContextClassLoader())) {
+ Class<?> clazz = loader.parseClass(new GroovyCodeSource(text,
"groovy.script", "groovy.script"));
+ Script script = ((Script)
clazz.getDeclaredConstructor().newInstance());
- GroovyCodeSource codeSource = new GroovyCodeSource(text,
"groovy.script", "groovy.script");
- GroovyClassLoader loader = new
GroovyClassLoader(Thread.currentThread().getContextClassLoader());
- Class clazz = loader.parseClass(codeSource);
- Script script = ((Script)
clazz.getDeclaredConstructor().newInstance());
-
- Binding binding = new Binding();
- binding.setVariable("method", new MethodClosure(new Dummy(),
"method"));
- script.setBinding(binding);
+ Binding binding = new Binding();
+ binding.setVariable("method", new MethodClosure(new Dummy(),
"method"));
+ script.setBinding(binding);
- script.run();
+ script.run();
+ }
}
public static class Dummy {
@@ -60,11 +54,11 @@ public class ScriptTest extends TestSupport {
/**
* GROOVY-6582 : Script.invokeMethod bypasses getProperty when looking for
closure-valued properties.
- *
+ * <p>
* Make sure that getProperty and invokeMethod are consistent.
- *
*/
- public void testGROOVY_6582() {
+ @Test
+ void testBaseScript() {
String script = "" +
"abstract class DeclaredBaseScript extends Script {\n" +
" def v = { it * 2 }\n" +
@@ -80,11 +74,11 @@ public class ScriptTest extends TestSupport {
}
// GROOVY-6344
- public void testScriptNameMangling() {
+ @Test
+ void testScriptNameMangling() {
String script = "this.getClass().getName()";
GroovyShell shell = new GroovyShell();
String name = (String) shell.evaluate(script,"a!b");
assertEquals("a_b", name);
}
-
}
diff --git a/src/test/groovy/groovy/tree/NodePrinterTest.java
b/src/test/groovy/groovy/tree/NodePrinterTest.java
index 7c63bd00f0..1d61606597 100644
--- a/src/test/groovy/groovy/tree/NodePrinterTest.java
+++ b/src/test/groovy/groovy/tree/NodePrinterTest.java
@@ -20,42 +20,50 @@ package groovy.tree;
import groovy.lang.GroovyObject;
import org.codehaus.groovy.classgen.TestSupport;
+import org.junit.jupiter.api.Test;
import java.util.logging.Logger;
-public class NodePrinterTest extends TestSupport {
+final class NodePrinterTest extends TestSupport {
- public void testTree() throws Exception {
+ @Test
+ void testTree() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/tree/TreeTest.groovy");
object.invokeMethod("testTree", null);
}
- public void testVerboseTree() throws Exception {
+ @Test
+ void testVerboseTree() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/tree/VerboseTreeTest.groovy");
object.invokeMethod("testTree", null);
}
- public void testSmallTree() throws Exception {
+ @Test
+ void testSmallTree() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/tree/SmallTreeTest.groovy");
object.invokeMethod("testTree", null);
}
- public void testLittleClosure() throws Exception {
+ @Test
+ void testLittleClosure() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/LittleClosureTest.groovy");
object.invokeMethod("testClosure", null);
}
- public void testNestedClosureBug() throws Exception {
+ @Test
+ void testNestedClosureBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/tree/NestedClosureBugTest.groovy");
object.invokeMethod("testNestedClosureBug", null);
}
- public void testClosureClassLoaderBug() throws Exception {
+ @Test
+ void testClosureClassLoaderBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/tree/ClosureClassLoaderBug.groovy");
object.invokeMethod("testTree", null);
}
- public void testLogging() {
+ @Test
+ void testLogging() {
Logger log = Logger.getLogger(getClass().getName());
log.info("Logging using JDK 1.4 logging");
}
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/ConstructorTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/ConstructorTest.java
index 762ed042a3..5fcbae8eca 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/ConstructorTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/ConstructorTest.java
@@ -19,10 +19,12 @@
package org.codehaus.groovy.classgen;
import groovy.lang.GroovyObject;
+import org.junit.jupiter.api.Test;
-public class ConstructorTest extends TestSupport {
+final class ConstructorTest extends TestSupport {
- public void testConstructor() throws Exception {
+ @Test
+ void testConstructor() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/NewExpressionTest.groovy");
object.invokeMethod("testNewInstance", null);
}
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/ForTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/ForTest.java
index c37dbdf412..4a11afa654 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/ForTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/ForTest.java
@@ -18,17 +18,26 @@
*/
package org.codehaus.groovy.classgen;
-import org.codehaus.groovy.ast.*;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.ConstructorNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.ForStatement;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.InvokerInvocationException;
+import org.junit.jupiter.api.Test;
-public class ForTest extends TestSupport {
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
- public void testNonLoop() throws Exception {
+final class ForTest extends TestSupport {
+
+ @Test
+ void testNonLoop() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC,
ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
@@ -37,11 +46,11 @@ public class ForTest extends TestSupport {
Statement statement = createPrintlnStatement(new
VariableExpression("coll"));
classNode.addMethod(new MethodNode("oneParamDemo", ACC_PUBLIC,
ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Managed to create bean", bean != null);
+ assertTrue(bean != null, "Managed to create bean");
System.out.println("################ Now about to invoke a method
without looping");
Object value = Integer.valueOf(10000);
@@ -56,8 +65,8 @@ public class ForTest extends TestSupport {
System.out.println("################ Done");
}
-
- public void testLoop() throws Exception {
+ @Test
+ void testLoop() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC,
ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
@@ -68,11 +77,11 @@ public class ForTest extends TestSupport {
ForStatement statement = new ForStatement(new
Parameter(ClassHelper.OBJECT_TYPE, "i"), new VariableExpression("coll"),
loopStatement);
classNode.addMethod(new MethodNode("iterateDemo", ACC_PUBLIC,
ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Managed to create bean", bean != null);
+ assertTrue(bean != null, "Managed to create bean");
System.out.println("################ Now about to invoke a method with
looping");
Object[] array = {Integer.valueOf(1234), "abc", "def"};
@@ -87,7 +96,8 @@ public class ForTest extends TestSupport {
System.out.println("################ Done");
}
- public void testManyParam() throws Exception {
+ @Test
+ void testManyParam() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC,
ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
@@ -100,11 +110,11 @@ public class ForTest extends TestSupport {
classNode.addMethod(new MethodNode("manyParamDemo", ACC_PUBLIC,
ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Managed to create bean", bean != null);
+ assertTrue(bean != null, "Managed to create bean");
System.out.println("################ Now about to invoke a method with
many parameters");
Object[] array = {Integer.valueOf(1000 * 1000), "foo-", "bar~"};
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/GStringTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/GStringTest.java
index 1513f32d63..348dd744b3 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/GStringTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/GStringTest.java
@@ -22,17 +22,28 @@ import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
-import org.codehaus.groovy.ast.expr.*;
+import org.codehaus.groovy.ast.expr.BinaryExpression;
+import org.codehaus.groovy.ast.expr.BooleanExpression;
+import org.codehaus.groovy.ast.expr.ConstantExpression;
+import org.codehaus.groovy.ast.expr.DeclarationExpression;
+import org.codehaus.groovy.ast.expr.GStringExpression;
+import org.codehaus.groovy.ast.expr.MethodCallExpression;
+import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.AssertStatement;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.InvokerInvocationException;
import org.codehaus.groovy.syntax.Token;
+import org.junit.jupiter.api.Test;
-public class GStringTest extends TestSupport {
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
- public void testConstructor() throws Exception {
+final class GStringTest extends TestSupport {
+
+ @Test
+ void testConstructor() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC,
ClassHelper.OBJECT_TYPE);
//Statement printStatement = createPrintlnStatement(new
VariableExpression("str"));
@@ -75,18 +86,17 @@ public class GStringTest extends TestSupport {
);
classNode.addMethod(new MethodNode("stringDemo", ACC_PUBLIC,
ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, block));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Managed to create bean", bean != null);
+ assertTrue(bean != null, "Managed to create bean");
//Object[] array = { new Integer(1234), "abc", "def" };
try {
InvokerHelper.invokeMethod(bean, "stringDemo", null);
- }
- catch (InvokerInvocationException e) {
+ } catch (InvokerInvocationException e) {
System.out.println("Caught: " + e.getCause());
e.getCause().printStackTrace();
fail("Should not have thrown an exception");
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/GetPropertyTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/GetPropertyTest.java
index 2d542a42c3..ccf370cd1a 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/GetPropertyTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/GetPropertyTest.java
@@ -19,20 +19,24 @@
package org.codehaus.groovy.classgen;
import groovy.lang.GroovyObject;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests using the GroovyObject API from Java on a groovy object
*/
-public class GetPropertyTest extends TestSupport {
+final class GetPropertyTest extends TestSupport {
- public void testProperty() throws Exception {
+ @Test
+ void testProperty() throws Exception {
GroovyObject object =
compile("src/test/groovy/org/codehaus/groovy/classgen/MyBean.groovy");
System.out.println("Got object: " + object);
Object value = object.getProperty("name");
- assertEquals("name property", "James", value);
+ assertEquals("James", value, "name property");
object.setProperty("name", "Bob");
- assertEquals("name property", "Bob", object.getProperty("name"));
+ assertEquals("Bob", object.getProperty("name"), "name property");
}
}
diff --git
a/src/test/groovy/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java
index 9e6ddd0bea..12bc7e1e75 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java
@@ -20,27 +20,21 @@ package org.codehaus.groovy.classgen;
import groovy.lang.GroovyObject;
import groovy.lang.MetaClass;
-
-import java.io.File;
+import org.junit.jupiter.api.Test;
/**
- * Tests dynamically compiling a new class
+ * Tests dynamically compiling a new class.
*/
-public class GroovyClassLoaderTest extends TestSupport {
-
- public void testCompile() throws Exception {
- Class groovyClass = loader.parseClass(new
File("src/test/groovy/org/codehaus/groovy/classgen/Main.groovy"));
-
- System.out.println("Invoking main...");
-
- GroovyObject object = (GroovyObject)
groovyClass.getDeclaredConstructor().newInstance();
+final class GroovyClassLoaderTest extends TestSupport {
- assertTrue(object != null);
+ @Test
+ void testCompile() throws Exception {
+ GroovyObject object =
compile("src/test/groovy/org/codehaus/groovy/classgen/Main.groovy");
MetaClass metaClass = object.getMetaClass();
System.out.println("Metaclass: " + metaClass);
- Class type = object.getClass();
+ Class<?> type = object.getClass();
System.out.println("Type: " + type);
// invoke via metaclass
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/IfElseTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/IfElseTest.java
index 7d725816ae..f0be5dfa02 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/IfElseTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/IfElseTest.java
@@ -18,7 +18,13 @@
*/
package org.codehaus.groovy.classgen;
-import org.codehaus.groovy.ast.*;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.ConstructorNode;
+import org.codehaus.groovy.ast.FieldNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.PropertyNode;
import org.codehaus.groovy.ast.expr.BinaryExpression;
import org.codehaus.groovy.ast.expr.BooleanExpression;
import org.codehaus.groovy.ast.expr.ConstantExpression;
@@ -28,10 +34,14 @@ import org.codehaus.groovy.ast.stmt.IfStatement;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.syntax.Token;
+import org.junit.jupiter.api.Test;
-public class IfElseTest extends TestSupport {
+import static org.junit.jupiter.api.Assertions.assertTrue;
- public void testLoop() throws Exception {
+final class IfElseTest extends TestSupport {
+
+ @Test
+ void testLoop() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC,
ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
classNode.addProperty(new PropertyNode("bar", ACC_PUBLIC,
ClassHelper.STRING_TYPE, classNode, null, null, null));
@@ -59,19 +69,17 @@ public class IfElseTest extends TestSupport {
IfStatement statement = new IfStatement(expression, trueStatement,
falseStatement);
classNode.addMethod(new MethodNode("ifDemo", ACC_PUBLIC,
ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY,
statement));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Managed to create bean", bean != null);
+ assertTrue(bean != null, "Managed to create bean");
assertSetProperty(bean, "bar", "abc");
System.out.println("################ Now about to invoke method");
- Object[] array = {
- };
-
+ Object[] array = {};
InvokerHelper.invokeMethod(bean, "ifDemo", array);
System.out.println("################ Done");
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/MainTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/MainTest.java
index e4cab41135..11c3c3cc50 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/MainTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/MainTest.java
@@ -19,12 +19,14 @@
package org.codehaus.groovy.classgen;
import groovy.lang.GroovyShell;
+import org.junit.jupiter.api.Test;
import java.io.File;
-public class MainTest extends TestSupport {
+final class MainTest {
- public void testMainMethod() throws Exception {
+ @Test
+ void testMainMethod() throws Exception {
GroovyShell shell = new GroovyShell();
shell.run(new File("src/test/groovy/groovy/SampleMain.groovy"), new
String[]{"A", "B", "C"});
}
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/MethodTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/MethodTest.java
index 6769adc605..e38d0df0a7 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/MethodTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/MethodTest.java
@@ -18,16 +18,25 @@
*/
package org.codehaus.groovy.classgen;
-import org.codehaus.groovy.ast.*;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.ConstructorNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.expr.ConstantExpression;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.ReturnStatement;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.runtime.InvokerHelper;
+import org.junit.jupiter.api.Test;
-public class MethodTest extends TestSupport {
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
- public void testMethods() throws Exception {
+final class MethodTest extends TestSupport {
+
+ @Test
+ void testMethods() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC,
ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
@@ -43,11 +52,11 @@ public class MethodTest extends TestSupport {
classNode.addMethod(new MethodNode("c", ACC_PUBLIC,
ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY,
emptyStatement));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Created instance of class: " + bean, bean != null);
+ assertTrue(bean != null, "Created instance of class: " + bean);
assertCallMethod(bean, "a", "calledA");
assertCallMethod(bean, "b", "calledB");
@@ -56,11 +65,11 @@ public class MethodTest extends TestSupport {
assertCallMethod(bean, "c", null);
}
- protected void assertCallMethod(Object object, String method, Object
expected) {
+ private void assertCallMethod(Object object, String method, Object
expected) {
Object value = InvokerHelper.invokeMethod(object, method, new
Object[0]);
- assertEquals("Result of calling method: " + method + " on: " + object
+ " with empty list", expected, value);
+ assertEquals(expected, value, "Result of calling method: " + method +
" on: " + object + " with empty list");
value = InvokerHelper.invokeMethod(object, method, null);
- assertEquals("Result of calling method: " + method + " on: " + object
+ " with null", expected, value);
+ assertEquals(expected, value, "Result of calling method: " + method +
" on: " + object + " with null");
}
}
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/PropertyTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/PropertyTest.java
index 31834cac90..5ed8c614eb 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/PropertyTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/PropertyTest.java
@@ -22,34 +22,39 @@ import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.PropertyNode;
import org.codehaus.groovy.runtime.DummyBean;
+import org.junit.jupiter.api.Test;
import java.lang.reflect.Modifier;
-public class PropertyTest extends TestSupport {
+import static org.junit.jupiter.api.Assertions.assertTrue;
- public void testFields() throws Exception {
+final class PropertyTest extends TestSupport {
+
+ @Test
+ void testFields() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC,
ClassHelper.OBJECT_TYPE);
classNode.addField("x", ACC_PUBLIC, ClassHelper.OBJECT_TYPE, null);
classNode.addField("y", ACC_PUBLIC, ClassHelper.Integer_TYPE, null);
classNode.addField("z", ACC_PRIVATE, ClassHelper.STRING_TYPE, null);
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
assertField(fooClass, "x", Modifier.PUBLIC, ClassHelper.OBJECT_TYPE);
assertField(fooClass, "y", Modifier.PUBLIC, ClassHelper.Integer_TYPE);
assertField(fooClass, "z", Modifier.PRIVATE, ClassHelper.STRING_TYPE);
}
- public void testProperties() throws Exception {
+ @Test
+ void testProperties() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC + ACC_SUPER,
ClassHelper.OBJECT_TYPE);
classNode.addProperty(new PropertyNode("bar", ACC_PUBLIC,
ClassHelper.STRING_TYPE, classNode, null, null, null));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Managed to create bean", bean != null);
+ assertTrue(bean != null, "Managed to create bean");
assertField(fooClass, "bar", 0, ClassHelper.STRING_TYPE);
@@ -57,15 +62,16 @@ public class PropertyTest extends TestSupport {
assertSetProperty(bean, "bar", "newValue");
}
- public void testInheritedProperties() throws Exception {
+ @Test
+ void testInheritedProperties() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC + ACC_SUPER,
ClassHelper.make(DummyBean.class));
classNode.addProperty(new PropertyNode("bar", ACC_PUBLIC,
ClassHelper.STRING_TYPE, classNode, null, null, null));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Managed to create bean", bean != null);
+ assertTrue(bean != null, "Managed to create bean");
assertField(fooClass, "bar", 0, ClassHelper.STRING_TYPE);
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/RunBugsTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/RunBugsTest.java
index 413e61523e..3653ea9e9f 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/RunBugsTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/RunBugsTest.java
@@ -19,107 +19,126 @@
package org.codehaus.groovy.classgen;
import groovy.lang.GroovyObject;
+import org.junit.jupiter.api.Test;
/**
* A helper class for testing bugs in code generation errors. By turning on the
* logging in TestSupport we can dump the ASM code generation code for inner
* classes etc.
*/
-public class RunBugsTest extends TestSupport {
+final class RunBugsTest extends TestSupport {
- public void testStaticMethodCall() throws Exception {
+ @Test
+ void testStaticMethodCall() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/StaticMethodCallBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testTryCatchBug() throws Exception {
+ @Test
+ void testTryCatchBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/TryCatchBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testRodsBug() throws Exception {
+ @Test
+ void testRodsBug() throws Exception {
GroovyObject object = compile("src/test/groovy/bugs/RodsBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testCastBug() throws Exception {
+ @Test
+ void testCastBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/ClosureMethodCallTest.groovy");
object.invokeMethod("testCallingClosureWithMultipleArguments", null);
}
- public void testGuillaumesMapBug() throws Exception {
+ @Test
+ void testGuillaumesMapBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/GuillaumesMapBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testUseClosureInScript() throws Exception {
+ @Test
+ void testUseClosureInScript() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/script/scriptWithClosure.groovy");
object.invokeMethod("run", null);
}
- public void testUseStaticInClosure() throws Exception {
+ @Test
+ void testUseStaticInClosure() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/UseStaticInClosureBug.groovy");
object.invokeMethod("testBug2", null);
}
- public void testPrimitiveTypeFieldTest() throws Exception {
+ @Test
+ void testPrimitiveTypeFieldTest() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/PrimitiveTypeFieldTest.groovy");
object.invokeMethod("testPrimitiveField", null);
}
- public void testMethodDispatchBug() throws Exception {
+ @Test
+ void testMethodDispatchBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/MethodDispatchBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testClosureInClosureTest() throws Exception {
+ @Test
+ void testClosureInClosureTest() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/ClosureInClosureTest.groovy");
object.invokeMethod("testInvisibleVariable", null);
}
- public void testOverloadInvokeMethodBug() throws Exception {
+ @Test
+ void testOverloadInvokeMethodBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/OverloadInvokeMethodBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testClosureVariableBug() throws Exception {
+ @Test
+ void testClosureVariableBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/ClosureVariableBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testMarkupAndMethodBug() throws Exception {
+ @Test
+ void testMarkupAndMethodBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/MarkupAndMethodBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testClosureParameterPassingBug() throws Exception {
+ @Test
+ void testClosureParameterPassingBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/ClosureParameterPassingBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testNestedClosureBug() throws Exception {
+ @Test
+ void testNestedClosureBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/NestedClosure2Bug.groovy");
object.invokeMethod("testFieldBug", null);
}
- public void testSuperMethod2Bug() throws Exception {
+ @Test
+ void testSuperMethod2Bug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/SuperMethod2Bug.groovy");
object.invokeMethod("testBug", null);
}
- public void testToStringBug() throws Exception {
+ @Test
+ void testToStringBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/ToStringBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testByteIndexBug() throws Exception {
+ @Test
+ void testByteIndexBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/ByteIndexBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testGroovy252_Bug() throws Exception {
+ @Test
+ void testGroovy252_Bug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/Groovy252_Bug.groovy");
object.invokeMethod("testBug", null);
}
-
}
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/RunClosureTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/RunClosureTest.java
index bc5a7e5c20..4a04c6eeb3 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/RunClosureTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/RunClosureTest.java
@@ -19,59 +19,69 @@
package org.codehaus.groovy.classgen;
import groovy.lang.GroovyObject;
+import org.junit.jupiter.api.Test;
-public class RunClosureTest extends TestSupport {
+final class RunClosureTest extends TestSupport {
- public void testClosure() throws Exception {
+ @Test
+ void testClosure() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/ClosureUsingOuterVariablesTest.groovy");
object.invokeMethod("testExampleUseOfClosureScopesUsingEach", null);
}
- public void testStaticClosureBug() throws Exception {
+ @Test
+ void testStaticClosureBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/StaticClosurePropertyBug.groovy");
object.invokeMethod("testCallStaticClosure", null);
}
- public void testZoharsBug() throws Exception {
+ @Test
+ void testZoharsBug() throws Exception {
GroovyObject object = compile("src/test/groovy/bugs/ZoharsBug.groovy");
object.invokeMethod("testBug", null);
}
- public void testBytecodeBug() throws Exception {
+ @Test
+ void testBytecodeBug() throws Exception {
GroovyObject object =
compile("src/test//groovy/bugs/BytecodeBug.groovy");
object.invokeMethod("testTedsBytecodeBug", null);
}
- public void testBytecode2Bug() throws Exception {
+ @Test
+ void testBytecode2Bug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/Bytecode2Bug.groovy");
object.invokeMethod("testTedsBytecodeBug", null);
}
- public void testBytecode3Bug() throws Exception {
+ @Test
+ void testBytecode3Bug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/Bytecode3Bug.groovy");
//object.invokeMethod("testInject", null);
object.invokeMethod("testIncrementPropertyInclosure", null);
}
- public void testBytecode4Bug() throws Exception {
+ @Test
+ void testBytecode4Bug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/Bytecode4Bug.groovy");
object.invokeMethod("testInject", null);
object.invokeMethod("testUsingProperty", null);
}
- public void testBytecode5Bug() throws Exception {
+ @Test
+ void testBytecode5Bug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/Bytecode5Bug.groovy");
object.invokeMethod("testUsingLocalVar", null);
}
- public void testBytecode6Bug() throws Exception {
+ @Test
+ void testBytecode6Bug() throws Exception {
GroovyObject object =
compile("src/test/groovy/bugs/Bytecode6Bug.groovy");
object.invokeMethod("testPreFixReturn", null);
}
- public void testPropertyTest() throws Exception {
+ @Test
+ void testPropertyTest() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/PropertyTest.groovy");
object.invokeMethod("testNormalPropertyGettersAndSetters", null);
}
-
}
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/RunGroovyTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/RunGroovyTest.java
index 25d05ad944..8b62a37e5e 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/RunGroovyTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/RunGroovyTest.java
@@ -19,38 +19,45 @@
package org.codehaus.groovy.classgen;
import groovy.lang.GroovyObject;
+import org.junit.jupiter.api.Test;
/**
* Tests dynamically compiling and running a new class
*/
-public class RunGroovyTest extends TestSupport {
+final class RunGroovyTest extends TestSupport {
- public void testArrayBug() throws Exception {
+ @Test
+ void testArrayBug() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/ToArrayBugTest.groovy");
object.invokeMethod("testToArrayBug", null);
}
- public void testPostfix() throws Exception {
+ @Test
+ void testPostfix() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/PostfixTest.groovy");
object.invokeMethod("testIntegerPostfix", null);
}
- public void testMap() throws Exception {
+ @Test
+ void testMap() throws Exception {
GroovyObject object = compile("src/test/groovy/groovy/MapTest.groovy");
object.invokeMethod("testMap", null);
}
- public void testClosure() throws Exception {
+ @Test
+ void testClosure() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/ClosureMethodTest.groovy");
object.invokeMethod("testListCollect", null);
}
- public void testClosureWithDefaultParam() throws Exception {
+ @Test
+ void testClosureWithDefaultParam() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/ClosureWithDefaultParamTest.groovy");
object.invokeMethod("methodWithDefaultParam", null);
}
- public void testOptionalReturn() throws Exception {
+ @Test
+ void testOptionalReturn() throws Exception {
GroovyObject object =
compile("src/test/groovy/groovy/OptionalReturnTest.groovy");
object.invokeMethod("testSingleExpression", null);
object.invokeMethod("testLastExpressionIsSimple", null);
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/TupleListTest.java
b/src/test/groovy/org/codehaus/groovy/classgen/TupleListTest.java
index f2ebe4e4b5..0419d46f2f 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/TupleListTest.java
+++ b/src/test/groovy/org/codehaus/groovy/classgen/TupleListTest.java
@@ -18,8 +18,18 @@
*/
package org.codehaus.groovy.classgen;
-import org.codehaus.groovy.ast.*;
-import org.codehaus.groovy.ast.expr.*;
+import org.codehaus.groovy.ast.ClassHelper;
+import org.codehaus.groovy.ast.ClassNode;
+import org.codehaus.groovy.ast.ConstructorNode;
+import org.codehaus.groovy.ast.MethodNode;
+import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.PropertyNode;
+import org.codehaus.groovy.ast.expr.ConstantExpression;
+import org.codehaus.groovy.ast.expr.DeclarationExpression;
+import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.ListExpression;
+import org.codehaus.groovy.ast.expr.MapExpression;
+import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.BlockStatement;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.ast.stmt.ForStatement;
@@ -27,10 +37,15 @@ import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.InvokerInvocationException;
import org.codehaus.groovy.syntax.Token;
+import org.junit.jupiter.api.Test;
-public class TupleListTest extends TestSupport {
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
- public void testIterateOverList() throws Exception {
+final class TupleListTest extends TestSupport {
+
+ @Test
+ void testIterateOverList() throws Exception {
ListExpression listExpression = new ListExpression();
listExpression.addExpression(new ConstantExpression("a"));
listExpression.addExpression(new ConstantExpression("b"));
@@ -41,7 +56,8 @@ public class TupleListTest extends TestSupport {
assertIterate("iterateOverList", listExpression);
}
- public void testIterateOverMap() throws Exception {
+ @Test
+ void testIterateOverMap() throws Exception {
MapExpression mapExpression = new MapExpression();
mapExpression.addMapEntryExpression(new ConstantExpression("a"), new
ConstantExpression("x"));
mapExpression.addMapEntryExpression(new ConstantExpression("b"), new
ConstantExpression("y"));
@@ -49,7 +65,7 @@ public class TupleListTest extends TestSupport {
assertIterate("iterateOverMap", mapExpression);
}
- protected void assertIterate(String methodName, Expression listExpression)
throws Exception {
+ private void assertIterate(String methodName, Expression listExpression)
throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC,
ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
classNode.addProperty(new PropertyNode("bar", ACC_PUBLIC,
ClassHelper.STRING_TYPE, classNode, null, null, null));
@@ -61,11 +77,11 @@ public class TupleListTest extends TestSupport {
block.addStatement(new ForStatement(new
Parameter(ClassHelper.dynamicType(), "i"), new VariableExpression("list"),
loopStatement));
classNode.addMethod(new MethodNode(methodName, ACC_PUBLIC,
ClassHelper.VOID_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, block));
- Class fooClass = loadClass(classNode);
- assertTrue("Loaded a new class", fooClass != null);
+ Class<?> fooClass = loadClass(classNode);
+ assertTrue(fooClass != null, "Loaded a new class");
Object bean = fooClass.getDeclaredConstructor().newInstance();
- assertTrue("Managed to create bean", bean != null);
+ assertTrue(bean != null, "Managed to create bean");
System.out.println("################ Now about to invoke method");
@@ -79,5 +95,4 @@ public class TupleListTest extends TestSupport {
}
System.out.println("################ Done");
}
-
}
diff --git
a/src/testFixtures/groovy/org/codehaus/groovy/classgen/TestSupport.java
b/src/testFixtures/groovy/org/codehaus/groovy/classgen/TestSupport.java
index 6dab325917..a176e9efa3 100644
--- a/src/testFixtures/groovy/org/codehaus/groovy/classgen/TestSupport.java
+++ b/src/testFixtures/groovy/org/codehaus/groovy/classgen/TestSupport.java
@@ -23,7 +23,6 @@ import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyCodeSource;
import groovy.lang.GroovyObject;
import groovy.lang.Script;
-import groovy.test.GroovyTestCase;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.CompileUnit;
import org.codehaus.groovy.ast.FieldNode;
@@ -34,6 +33,9 @@ import org.codehaus.groovy.ast.expr.MethodCallExpression;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.runtime.InvokerHelper;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestInfo;
import org.objectweb.asm.Opcodes;
import java.beans.BeanInfo;
@@ -44,17 +46,22 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
+
/**
* Base class for test cases.
*/
-public abstract class TestSupport extends GroovyTestCase implements Opcodes {
+public abstract class TestSupport implements Opcodes {
/**
* Asserts the script runs without any exceptions.
*/
protected final void assertScript(String scriptText) throws Exception {
+ String scriptName = "TestScript" + testMethodName +
(++testScriptCounter) + ".groovy";
Class<?> scriptClass = loader.parseClass(doPrivileged(() ->
- new GroovyCodeSource(scriptText, getTestClassName(),
"/groovy/testSupport")
+ new GroovyCodeSource(scriptText, scriptName, "/groovy/testSupport")
));
Script script = InvokerHelper.createScript(scriptClass, new Binding());
script.run();
@@ -80,30 +87,29 @@ public abstract class TestSupport extends GroovyTestCase
implements Opcodes {
protected final void assertGetProperty(Object bean, String property,
Object expected) throws Exception {
PropertyDescriptor descriptor = getDescriptor(bean, property);
Method method = descriptor.getReadMethod();
- assertNotNull("has getter method", method);
+ assertNotNull(method, "has getter method");
Object[] args = {};
Object value = invokeMethod(bean, method, args);
-
- assertEquals("property value", expected, value);
+ assertEquals(expected, value, "property value");
}
protected final void assertSetProperty(Object bean, String property,
Object newValue) throws Exception {
PropertyDescriptor descriptor = getDescriptor(bean, property);
Method method = descriptor.getWriteMethod();
- assertNotNull("has setter method", method);
+ assertNotNull(method, "has setter method");
Object[] args = {newValue};
Object value = invokeMethod(bean, method, args);
- assertEquals("should return null", null, value);
+ assertEquals(null, value, "should return null");
assertGetProperty(bean, property, newValue);
}
protected final void assertField(Class<?> clazz, String name, int
modifiers, ClassNode type) throws Exception {
Field field = clazz.getDeclaredField(name);
- assertNotNull("Found field called: " + name, field);
- assertEquals("Name", name, field.getName());
- assertEquals("Type", type.getName(), field.getType().getName());
- assertEquals("Modifiers", modifiers, field.getModifiers());
+ assertNotNull(field, "Found field called: " + name);
+ assertEquals(name, field.getName());
+ assertEquals(type.getName(), field.getType().getName());
+ assertEquals(modifiers, field.getModifiers());
}
protected final ExpressionStatement createPrintlnStatement(Expression
expression) throws NoSuchFieldException {
@@ -113,14 +119,19 @@ public abstract class TestSupport extends GroovyTestCase
implements Opcodes {
//--------------------------------------------------------------------------
- protected GroovyClassLoader loader;
+ private GroovyClassLoader loader;
+ private String testMethodName;
+ private int testScriptCounter;
- protected void setUp() throws Exception {
+ @BeforeEach
+ void setUpTestCase(TestInfo testInfo) throws Exception {
ClassLoader parentLoader = getClass().getClassLoader();
loader = doPrivileged(() -> new GroovyClassLoader(parentLoader));
+ testMethodName = testInfo.getTestMethod().orElseThrow().getName();
}
- protected void tearDown() throws Exception {
+ @AfterEach
+ void tearDownTestCase() throws Exception {
loader.close();
loader = null;
}
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/DOMTest.groovy
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/DOMTest.groovy
index 69b388dba4..a56eba0dbd 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/DOMTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/DOMTest.groovy
@@ -18,12 +18,15 @@
*/
package groovy.xml
+import org.junit.jupiter.api.Test
+
/**
- * This test uses the concise syntax to test the building of
+ * This test uses the concise syntax to test the building of
* W3C DOM trees using GroovyMarkup
*/
-class DOMTest extends TestXmlSupport {
+final class DOMTest extends TestXmlSupport {
+ @Test
void testSmallTree() {
def b = DOMBuilder.newInstance()
@@ -38,6 +41,7 @@ class DOMTest extends TestXmlSupport {
dump(root)
}
+ @Test
void testTree() {
def b = DOMBuilder.newInstance()
@@ -46,19 +50,18 @@ class DOMTest extends TestXmlSupport {
elem2('hello2')
nestedElem(x:'abc', y:'def') {
child(z:'def')
- child2()
+ child2()
}
nestedElem2(z:'zzz') {
child(z:'def')
- child2("hello")
+ child2("hello")
}
}
assert root != null
dump(root)
-
/*
def elem1 = root.elem1
assert elem1.value() := 'hello1'
@@ -69,12 +72,12 @@ class DOMTest extends TestXmlSupport {
assert root.elem1.value() := 'hello1'
assert root.elem2.value() := 'hello2'
- assert root.nestedElem.attributes() := ['x':'abc', 'y':'def']
+ assert root.nestedElem.attributes() := ['x':'abc', 'y':'def']
assert root.nestedElem.child.attributes() := ['z':'def']
assert root.nestedElem.child2.value() := []
assert root.nestedElem.child2.text() := ''
- assert root.nestedElem2.attributes() := ['z':'zzz']
+ assert root.nestedElem2.attributes() := ['z':'zzz']
assert root.nestedElem2.child.attributes() := ['z':'def']
assert root.nestedElem2.child2.value() := 'hello'
assert root.nestedElem2.child2.text() := 'hello'
@@ -89,11 +92,10 @@ class DOMTest extends TestXmlSupport {
assert root.nestedElem.attributes().y := 'def'
assert root.nestedElem2.attributes().z := 'zzz'
assert root.nestedElem2.child.attributes().z := 'def'
-*/
+*/
/** @todo parser add .@ as an operation
assert root.@a := 5
assert root.@b := 7
- */
+ */
}
-
-}
\ No newline at end of file
+}
diff --git
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/MarkupWithWriterTest.groovy
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/MarkupWithWriterTest.groovy
index 7a8af9cc47..6c861b6c99 100644
---
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/MarkupWithWriterTest.groovy
+++
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/MarkupWithWriterTest.groovy
@@ -18,11 +18,16 @@
*/
package groovy.xml
+import org.junit.jupiter.api.Test
+
+import static org.junit.jupiter.api.Assertions.assertEquals
+
/**
* This test uses GroovyMarkup with writers other than System.out
*/
-class MarkupWithWriterTest extends TestXmlSupport {
+final class MarkupWithWriterTest extends TestXmlSupport {
+ @Test
void testSmallTreeWithStringWriter() {
def writer = new java.io.StringWriter()
def b = new MarkupBuilder(writer)
@@ -39,7 +44,8 @@ class MarkupWithWriterTest extends TestXmlSupport {
"</root1>", writer.toString()
}
+ @Test
void testWriterUseInScriptFile() {
assertScriptFile
'src/test/groovy/groovy/xml/UseMarkupWithWriterScript.groovy'
}
-}
\ No newline at end of file
+}
diff --git
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeGPathTest.groovy
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeGPathTest.groovy
index c2c9c9dc46..15061719d4 100644
---
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeGPathTest.groovy
+++
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeGPathTest.groovy
@@ -18,11 +18,14 @@
*/
package groovy.xml
+import org.junit.jupiter.api.Test
+
/**
* Test the use of GPath navigation with namespaces
*/
-class NamespaceNodeGPathTest extends TestXmlSupport {
+final class NamespaceNodeGPathTest extends TestXmlSupport {
+ @Test
void testTree() {
Node root = new XmlParser().parseText("""
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
diff --git
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeTest.groovy
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeTest.groovy
index 7ea14cf698..6a26eccf85 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/NamespaceNodeTest.groovy
@@ -19,12 +19,14 @@
package groovy.xml
import groovy.namespace.QName
+import org.junit.jupiter.api.Test
/**
* Test the building of namespaced XML using GroovyMarkup
*/
-class NamespaceNodeTest extends TestXmlSupport {
+final class NamespaceNodeTest extends TestXmlSupport {
+ @Test
void testNodeBuilderWithNamespace() {
def n = new Namespace('http://foo/bar')
def builder = NamespaceBuilder.newInstance(new NodeBuilder(), n.uri)
@@ -36,6 +38,7 @@ class NamespaceNodeTest extends TestXmlSupport {
assert result[n.inner][1].text() == 'bar'
}
+ @Test
void testTree() {
def builder = NodeBuilder.newInstance()
def xmlns = new NamespaceBuilder(builder)
@@ -84,6 +87,7 @@ class NamespaceNodeTest extends TestXmlSupport {
assert attrNode[0].@name == 'orderDate'
}
+ @Test
void testNodeBuilderWithImplicitNamespace() {
def n = new Namespace('http://foo/bar')
def builder = NamespaceBuilder.newInstance(new NodeBuilder(), n.uri)
@@ -107,6 +111,7 @@ class NamespaceNodeTest extends TestXmlSupport {
assert actual == expected
}
+ @Test
void testNamespaceBuilderWithoutNamespace() {
def builder = NamespaceBuilder.newInstance(new NodeBuilder())
def result = builder.outer(id: "3") {
diff --git a/subprojects/groovy-xml/src/test/groovy/groovy/xml/SAXTest.groovy
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/SAXTest.groovy
index ee22cd07dd..80aa313fbe 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/SAXTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/SAXTest.groovy
@@ -18,12 +18,15 @@
*/
package groovy.xml
+import org.junit.jupiter.api.Test
+
/**
* This test uses the concise syntax to test the generation
* of SAX events using GroovyMarkup
*/
-class SAXTest extends TestXmlSupport {
+final class SAXTest extends TestXmlSupport {
+ @Test
void testSmallTree() {
def b = createSAXBuilder()
@@ -34,6 +37,7 @@ class SAXTest extends TestXmlSupport {
}
}
+ @Test
void testTree() {
def b = createSAXBuilder()
@@ -42,13 +46,13 @@ class SAXTest extends TestXmlSupport {
elem2('hello2')
nestedElem(x:'abc', y:'def') {
child(z:'def')
- child2()
+ child2()
}
nestedElem2(z:'zzz') {
child(z:'def')
- child2("hello")
+ child2("hello")
}
}
}
-}
\ No newline at end of file
+}
diff --git
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/TestXmlSupport.java
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/TestXmlSupport.java
index 098a914138..e3783b0db9 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/TestXmlSupport.java
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/TestXmlSupport.java
@@ -25,25 +25,29 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
-import java.io.IOException;
-
public abstract class TestXmlSupport extends TestSupport {
- protected void dump(Node node) throws IOException {
+ protected final void dump(Node node) {
XmlUtil.serialize((Element) node, System.out);
}
- protected SAXBuilder createSAXBuilder() throws IOException {
+ protected final SAXBuilder createSAXBuilder() {
return new SAXBuilder(new LoggingDefaultHandler());
}
private static class LoggingDefaultHandler extends DefaultHandler {
+
+ @Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
System.out.println("Start Element: " + localName);
}
+
+ @Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
System.out.println("End Element: " + localName);
}
+
+ @Override
public void characters(char ch[], int start, int length) throws
SAXException {
System.out.println("Characters: " + new
String(ch).substring(start, start + length - 1));
}
diff --git
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/VerboseDOMTest.groovy
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/VerboseDOMTest.groovy
index ec3472356b..3c9068892c 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/VerboseDOMTest.groovy
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/VerboseDOMTest.groovy
@@ -18,12 +18,15 @@
*/
package groovy.xml
+import org.junit.jupiter.api.Test
+
/**
- * This test uses the verbose syntax to test the building of
+ * This test uses the verbose syntax to test the building of
* W3C DOM trees using GroovyMarkup
*/
-class VerboseDOMTest extends TestXmlSupport {
+final class VerboseDOMTest extends TestXmlSupport {
+ @Test
void testSmallTree() {
def b = DOMBuilder.newInstance()
@@ -38,6 +41,7 @@ class VerboseDOMTest extends TestXmlSupport {
dump(root)
}
+ @Test
void testTree() {
def b = DOMBuilder.newInstance()
@@ -51,14 +55,13 @@ class VerboseDOMTest extends TestXmlSupport {
nestedElem2(['z':'zzz'], {->
child(['z':'def'])
- child2("hello")
+ child2("hello")
})
})
assert root != null
dump(root)
-
/*
def elem1 = root.elem1
assert elem1.value() := 'hello1'
@@ -69,12 +72,12 @@ class VerboseDOMTest extends TestXmlSupport {
assert root.elem1.value() := 'hello1'
assert root.elem2.value() := 'hello2'
- assert root.nestedElem.attributes() := ['x':'abc', 'y':'def']
+ assert root.nestedElem.attributes() := ['x':'abc', 'y':'def']
assert root.nestedElem.child.attributes() := ['z':'def']
assert root.nestedElem.child2.value() := []
assert root.nestedElem.child2.text() := ''
- assert root.nestedElem2.attributes() := ['z':'zzz']
+ assert root.nestedElem2.attributes() := ['z':'zzz']
assert root.nestedElem2.child.attributes() := ['z':'def']
assert root.nestedElem2.child2.value() := 'hello'
assert root.nestedElem2.child2.text() := 'hello'
@@ -89,11 +92,10 @@ class VerboseDOMTest extends TestXmlSupport {
assert root.nestedElem.attributes().y := 'def'
assert root.nestedElem2.attributes().z := 'zzz'
assert root.nestedElem2.child.attributes().z := 'def'
-*/
+*/
/** @todo parser add .@ as an operation
assert root.@a := 5
assert root.@b := 7
- */
+ */
}
-
}
diff --git
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/MarkupInScriptBug.java
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/MarkupInScriptBug.java
index 7f049689ed..326d6876ef 100644
---
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/MarkupInScriptBug.java
+++
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/MarkupInScriptBug.java
@@ -19,9 +19,12 @@
package groovy.xml.bugs;
import org.codehaus.groovy.classgen.TestSupport;
+import org.junit.jupiter.api.Test;
-public class MarkupInScriptBug extends TestSupport {
- public void testBug() throws Exception {
+final class MarkupInScriptBug extends TestSupport {
+
+ @Test
+ void testBug() throws Exception {
assertScriptFile("src/test/groovy/groovy/xml/script/AtomTestScript.groovy");
}
}
diff --git
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/SeansBug.java
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/SeansBug.java
index 9eb3048462..48073347ad 100644
--- a/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/SeansBug.java
+++ b/subprojects/groovy-xml/src/test/groovy/groovy/xml/bugs/SeansBug.java
@@ -19,17 +19,19 @@
package groovy.xml.bugs;
import groovy.lang.GroovyShell;
-import org.codehaus.groovy.classgen.TestSupport;
+import org.junit.jupiter.api.Test;
-public class SeansBug extends TestSupport {
+final class SeansBug {
- public void testBug() throws Exception {
+ @Test
+ void testBug() throws Exception {
String code = "for (i in 1..10) \n{\n println(i)\n}";
GroovyShell shell = new GroovyShell();
shell.evaluate(code);
}
- public void testMarkupBug() throws Exception {
+ @Test
+ void testMarkupBug() throws Exception {
String[] lines =
{
"package groovy.xml",
diff --git
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/NamespaceDOMTest.groovy
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/NamespaceDOMTest.groovy
index 027817a45e..b0d44f7b85 100644
---
a/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/NamespaceDOMTest.groovy
+++
b/subprojects/groovy-xml/src/test/groovy/groovy/xml/dom/NamespaceDOMTest.groovy
@@ -23,10 +23,11 @@ import groovy.xml.DOMBuilder
import groovy.xml.NamespaceBuilder
import groovy.xml.TestXmlSupport
import groovy.xml.XmlUtil
+import org.junit.jupiter.api.Test
import static groovy.util.XmlAssert.assertXmlEquals
-class NamespaceDOMTest extends TestXmlSupport {
+final class NamespaceDOMTest extends TestXmlSupport {
def expected1 = '''
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
@@ -60,6 +61,7 @@ class NamespaceDOMTest extends TestXmlSupport {
</envelope>
'''
+ @Test
void testXsdSchemaWithBuilderHavingAutoPrefix() {
def builder = DOMBuilder.newInstance()
def xsd = NamespaceBuilder.newInstance(builder,
'http://www.w3.org/2001/XMLSchema', 'xsd')
@@ -79,6 +81,7 @@ class NamespaceDOMTest extends TestXmlSupport {
assertXmlEquals(expected1, XmlUtil.serialize(root))
}
+ @Test
void testXsdSchemaWithBuilderHavingMultipleNamespaces() {
def builder = DOMBuilder.newInstance()
def multi = NamespaceBuilder.newInstance(builder)
@@ -87,6 +90,7 @@ class NamespaceDOMTest extends TestXmlSupport {
checkXml(multi)
}
+ @Test
void testXsdSchemaWithBuilderHavingDeclareNamespace() {
def builder = DOMBuilder.newInstance()
def multi = NamespaceBuilder.newInstance(builder)