Object testInstance = testMethodExecutor.getInstance();
final String testClass = testInstance.getClass().getName();
final String testMethod = testMethodExecutor.getMethod().getName();
TestResult result = null;
NotificationListener listener = null;
try
{
final JMXTestRunnerMBean testRunner = getMBeanProxy(JMXTestRunnerMBean.OBJECT_NAME, JMXTestRunnerMBean.class);
listener = registerNotificationListener(JMXTestRunnerMBean.OBJECT_NAME, testRunner, testInstance);
if (executionType == ExecutionType.EMBEDDED)
{
InputStream resultStream = executor.submit(new Callable<InputStream>()
{
@Override
public InputStream call() throws Exception
{
return testRunner.runTestMethodEmbedded(testClass, testMethod, props);
}
}).get();
try
{
result = Utils.deserialize(resultStream, TestResult.class);
}
finally
{
try
{
resultStream.close();
}
catch (IOException ignore)
{
}
}
}
else if (executionType == ExecutionType.REMOTE)
{
result = testRunner.runTestMethod(testClass, testMethod, props);
}
}
catch (final Throwable e)
{
result = new TestResult(Status.FAILED);
result.setThrowable(e);
}
finally
{
result.setEnd(System.currentTimeMillis());
unregisterNotificationListener(JMXTestRunnerMBean.OBJECT_NAME, listener);
}
return result;
}