From ae45f4ed6b1bb8ebb71b72f30bd2ce4f69d3c93d Mon Sep 17 00:00:00 2001
From: Matthew Hague <matthew.hague@rhul.ac.uk>
Date: Mon, 15 Nov 2021 21:13:21 +0000
Subject: [PATCH] Allow checkMethodSignature to ignore return type

---
 src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java b/src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java
index 251af0d..0b239c2 100644
--- a/src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java
+++ b/src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java
@@ -450,7 +450,7 @@ public class CodeTester {
      *
      * @param klass the class the method belongs to
      * @param isStatic true if the method should be static
-     * @param returnType class of return type
+     * @param returnType class of return type or null if we don't care
      * @param methodName name of method
      * @param params the class of the method arguments
      * @throws failed test or no such method exception if not found
@@ -465,8 +465,10 @@ public class CodeTester {
 
         String staticString = isStatic ? "static " : "";
         String className = getClassString(klass);
+        String returnTypeString
+            = returnType == null ? "<return type>" : getClassString(returnType);
         String methodSig =
-            getClassString(returnType) + " " +
+            returnTypeString + " " +
             methodName + "(" + getClassParamsString(params) + ") ";
 
         String baseErr =
@@ -477,7 +479,7 @@ public class CodeTester {
         try {
             Method m = invasiveGetMethod(klass, methodName, params);
 
-            if (!m.getReturnType().equals(returnType)) {
+            if (returnType != null && !m.getReturnType().equals(returnType)) {
                 throw new BaseTester.FailedTestException(
                     baseErr + "\n\n" +
                     "A similar method was found, but the return types do not match."
-- 
GitLab