Skip to content

Commit

Permalink
address jakartaee#1515 by improving error message for missing @SetupM…
Browse files Browse the repository at this point in the history
…ethod method

Signed-off-by: Scott Marlow <[email protected]>
  • Loading branch information
scottmarlow committed Sep 9, 2024
1 parent 96e727f commit 218405c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions common/src/main/java/com/sun/ts/lib/harness/EETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,20 @@ private Method getSetupMethod(Class testClass, Method runMethod) {

// first check for @SetupMethod annotation on run method
Annotation annotation = runMethod.getAnnotation(SetupMethod.class);

String testSetupMethodName = null;
if (annotation != null) {
try {
TestUtil
.logTrace("getSetupMethod - getting setup method from annotation");
SetupMethod setupAnnotation = (SetupMethod) annotation;
testSetupMethodName = setupAnnotation.name();
setupMethod = testClass.getMethod(setupAnnotation.name(),
setupParameterTypes);
TestUtil.logTrace(
"getSetupMethod - setup method name: " + setupAnnotation.name());
} catch (NoSuchMethodException e) {
setTestStatus(Status.failed(
"Could not find annotation defined setup method for testcase: "
"Could not find annotation defined test setup method (" + testSetupMethodName + ") for testcase: "
+ sTestCase),
e);
}
Expand Down Expand Up @@ -545,27 +546,25 @@ public Status run(String[] argv, Properties p) {
TestUtil.logTrace("TESTCLASS=" + testClass.getName());
runMethod = getRunMethod(testClass);
if (runMethod == null)
TestUtil.logTrace("* RUN METHOD is null and is not found");
return Status.failed("Invalid test case name as test run Method ( " + sTestCase + ") could not be found in " + testClass.getName());
else {
TestUtil.logTrace("** GOT RUN METHOD!");
TestUtil.logTrace("**runmethod=" + runMethod.getName());
}
TestUtil.logTrace("ABOUT TO GET SETUP METHOD!");
setupMethod = getSetupMethod(testClass, runMethod);
if (setupMethod == null)
TestUtil.logTrace("SETUP METHOD not found");
return Status.failed("Invalid test case name as test setupMethod could not be found ( Test setup method: " +
getSetupMethodName(runMethod) + ", testName:" + sTestCase + ") " +
"in test class " + testClass.getName() + "(test class was loaded from: " + testClass.getClassLoader().getName() + ")");
else
TestUtil.logTrace("GOT SETUP METHOD!");

cleanupMethod = getCleanupMethod(testClass, runMethod);
if (cleanupMethod == null)
TestUtil.logTrace("CLEANUP METHOD not found");
return Status.failed("Invalid test case name as test cleanupMethod Method ( for " + sTestCase + ") could not be found in " + testClass.getName());
else
TestUtil.logTrace("GOT CLEANUP METHOD!");
// if anything went wrong while getting our methods, return
if (setupMethod == null || runMethod == null || cleanupMethod == null)
return Status.failed("One of the test methods could not be"
+ "found for testcase: " + sTestCase);
try {
TestUtil.logTrace("ABOUT TO INVOKE SETUP METHOD!");
// if new classname is true, use that class name instead of
Expand Down Expand Up @@ -650,6 +649,15 @@ public Status run(String[] argv, Properties p) {
return sTestStatus;
}

private String getSetupMethodName(Method runMethod) {
Annotation annotation = runMethod.getAnnotation(SetupMethod.class);
if (annotation != null) {
SetupMethod setupAnnotation = (SetupMethod) annotation;
return setupAnnotation.name();
}
return "";
}

private String[] getAllTestCases(Properties p) throws SetupException {
Vector tests = new Vector();
String[] testMethods;
Expand Down

0 comments on commit 218405c

Please sign in to comment.