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 2022/04/19 07:56:49 UTC

[groovy] 04/11: minor refactor: fix style warnings

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

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

commit 14500eaa140ba878b875b5017c08571758f496b6
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Apr 17 16:51:18 2022 +1000

    minor refactor: fix style warnings
---
 src/main/java/groovy/lang/MetaClassImpl.java              |  6 +++---
 .../src/main/java/groovy/test/GroovyAssert.java           |  2 +-
 .../src/main/java/groovy/test/GroovyTestSuite.java        | 15 ++++++++++-----
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java
index 7600e7a910..5886578211 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -264,7 +264,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
      * @see MetaObjectProtocol#respondsTo(Object, String, Object[])
      */
     @Override
-    public List respondsTo(final Object obj, final String name, final Object[] argTypes) {
+    public List<MetaMethod> respondsTo(final Object obj, final String name, final Object[] argTypes) {
         Class[] classes = castArgumentsToClassArray(argTypes);
         MetaMethod m = getMetaMethod(name, classes);
         if (m != null) {
@@ -277,12 +277,12 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
      * @see MetaObjectProtocol#respondsTo(Object, String)
      */
     @Override
-    public List respondsTo(final Object obj, final String name) {
+    public List<MetaMethod> respondsTo(final Object obj, final String name) {
         final Object o = getMethods(getTheClass(), name, false);
         if (o instanceof FastArray) {
             return ((FastArray) o).toList();
         }
-        return Collections.singletonList(o);
+        return Collections.<MetaMethod>singletonList((MetaMethod) o);
     }
 
     /**
diff --git a/subprojects/groovy-test/src/main/java/groovy/test/GroovyAssert.java b/subprojects/groovy-test/src/main/java/groovy/test/GroovyAssert.java
index bf701d0436..fc0e75ad51 100644
--- a/subprojects/groovy-test/src/main/java/groovy/test/GroovyAssert.java
+++ b/subprojects/groovy-test/src/main/java/groovy/test/GroovyAssert.java
@@ -295,7 +295,7 @@ public class GroovyAssert {
      * @return the test case method
      * @throws RuntimeException if no method could be found.
      */
-    private static Method findRunningJUnitTestMethod(Class caller) {
+    private static Method findRunningJUnitTestMethod(Class<?> caller) {
         final Class<?>[] args = new Class<?>[]{};
 
         // search the initial junit test
diff --git a/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestSuite.java b/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestSuite.java
index 914b9f2f2f..71dd2eb2e7 100644
--- a/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestSuite.java
+++ b/subprojects/groovy-test/src/main/java/groovy/test/GroovyTestSuite.java
@@ -78,17 +78,22 @@ public class GroovyTestSuite extends TestSuite {
             throw new RuntimeException("No filename given in the 'test' system property so cannot run a Groovy unit test");
         }
         System.out.println("Compiling: " + fileName);
-        Class<? extends TestCase> type = compile(fileName);
+        Class<?> type = compile(fileName);
         String[] args = {};
-        if (!Test.class.isAssignableFrom(type) && Script.class.isAssignableFrom(type)) {
+        if (TestCase.class.isAssignableFrom(type)) {
+            addToTestSuite(type);
+        } else if (Script.class.isAssignableFrom(type)) {
             // let's treat the script as a Test
             addTest(new ScriptTestAdapter(type, args));
-        } else {
-            addTestSuite(type);
         }
     }
 
-    public Class<? extends TestCase> compile(String fileName) throws Exception {
+    @SuppressWarnings("unchecked")
+    private void addToTestSuite(Class<?> type) {
+        addTestSuite((Class<? extends TestCase>) type);
+    }
+
+    public Class<?> compile(String fileName) throws Exception {
         return loader.parseClass(new File(fileName));
     }
 }