3 import java
.io
.PrintWriter
;
4 import java
.lang
.reflect
.Method
;
7 * Invoke a method of a class in an own thread. Provide a method to end
10 public class MethodThread
extends Thread
13 /** The method that should be executed **/
14 private Method mTestMethod
= null;
15 /** The object that implements the method **/
16 private Object mInvokeClass
= null;
17 /** A PrintWriter for debug Output **/
18 private PrintWriter mLog
= null;
19 /** An Error String **/
20 private String mErrMessage
= null;
21 /** Did an Exception happen? **/
22 private boolean mExceptionHappened
= false;
23 private Object
[] mParameter
= null;
27 * @param testMethod The method that will be invoked.
28 * @param invokeClass The class where the method is invoked.
29 * @param log The logging mechanism.
31 public MethodThread(Method testMethod
, Object invokeClass
, PrintWriter log
)
33 mTestMethod
= testMethod
;
34 mInvokeClass
= invokeClass
;
38 public MethodThread(Method testMethod
, Object invokeClass
, Object
[] parameter
, PrintWriter log
)
40 mTestMethod
= testMethod
;
41 mInvokeClass
= invokeClass
;
42 mParameter
= parameter
;
53 mTestMethod
.invoke(mInvokeClass
, mParameter
);
55 catch (IllegalAccessException e
)
57 e
.printStackTrace(mLog
);
58 mErrMessage
= e
.getMessage();
59 mExceptionHappened
= true;
61 catch (java
.lang
.reflect
.InvocationTargetException e
)
63 Throwable t
= e
.getTargetException();
64 if (!(t
instanceof ComplexTestCase
.AssureException
))
66 t
.printStackTrace(mLog
);
67 mErrMessage
= t
.getMessage();
68 if (mErrMessage
== null)
70 mErrMessage
= t
.toString();
72 mExceptionHappened
= true;
79 * Get the error message
80 * @return The error message.
82 public String
getErrorMessage()
88 * Is there an error message?
89 * @return True, if an error did happen.
91 public boolean hasErrorMessage()
93 return mExceptionHappened
;
97 * Stop the running method.
105 catch (SecurityException e
)
107 e
.printStackTrace(mLog
);
108 mErrMessage
= e
.getMessage();
109 mExceptionHappened
= true;