Test (JUnit3IdeaTestRunner runner, Class<?> testClass, String methodName) { runner.clearStatus(); try { Constructor<?> constructor = testClass.getConstructor(String.class); return (Test)constructor.newInstance(methodName); } catch (NoSuchMethodException e) { try { Constructor<?> constructor = testClass.getConstructor(); TestCase test = (TestCase)constructor.newInstance(); test.setName(methodName); return test; } catch(ClassCastException e1) { boolean methodExists; try { testClass.getMethod(methodName); methodExists = true; } catch (NoSuchMethodException e2) { methodExists = false; } if (!methodExists) { String error = MessageFormat.format(ourBundle.getString("junit.method.not.found"), methodName); String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), error); return new FailedTestCase(testClass, methodName, message, null); } runner.runFailed(MessageFormat.format(ourBundle.getString("junit.class.not.derived"), testClass.getName())); return null; } catch (Exception e1) { String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), e1.toString()); return new FailedTestCase(testClass, methodName, message, e1); } } catch (Throwable e) { String message = MessageFormat.format(ourBundle.getString("junit.cannot.instantiate.tests"), e.toString()); return new FailedTestCase(testClass, methodName, message, e); } }