⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testevent.java

📁 MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自JUnit框架
💻 JAVA
字号:
package org.momeunit.ant.event;/** * Class that encapsulates information of test event. Test events of different * types can be constructed using static factory methods * {@link #createStartTestEvent(long, String, String)}, * {@link #createErrorTestEvent(long, String, String, String, String, String)}, * {@link #createFailTestEvent(long, String, String, String, String, String)}, * {@link #createEndTestEvent(long, String, String)}. This class contains * methods for accessing and modifying of type of the event; time at which this * event occurred; name and classname of test on which this event occurred; * classname, message and stack trace of error or failure occurred. *  * @author Sergio Morozov * @version 1.1.2 */public class TestEvent{  /**   * Start test event type.   *    * @since 1.1   */  public static final int START_TEST = 1;  /**   * Fail test event type.   *    * @since 1.1   */  public static final int FAIL_TEST = 2;  /**   * Error test event type.   *    * @since 1.1   */  public static final int ERROR_TEST = 3;  /**   * End test event type.   *    * @since 1.1   */  public static final int END_TEST = 4;  /**   * Test events type names.   */  private static String[] typeNames = { "Unknown", "TestStart", "TestFail",      "TestError", "TestEnd" };  /**   * Type of test event.   */  private int type = 0;  /**   * Name of test during which run this event occurs.   */  private String testName = null;  /**   * Classname of test during which run this event occurs.   */  private String testClassName = null;  /**   * Time at which test event occurred.   */  private long timestamp = 0;  /**   * Is this failure test event.   */  private boolean isFailure = false;  /**   * Error or failure message.   */  private String msg = null;  /**   * Classname of error or failure.   */  private String errorClassName = null;  /**   * Stack trace of error or failure.   */  private String stackTrace = null;  /**   * Instantiates TestEvent.   *    * @since 1.1   */  public TestEvent()  {    super();  }  /**   * Instantiates TestEvent with given type, test name, test class name, class   * name of error or failure, error or failure message, stack trace of error or   * failure.   *    * @param type   *          type of TestEvent.   * @param timestamp   *          time at which this event occurred.   * @param testName   *          name of test on which this event occurs.   * @param testClassName   *          classname of test on which this event occurs.   * @param errorClassName   *          classname of error or failure.   * @param msg   *          error or failure message.   * @param stackTrace   *          stack trace of error or failure.   * @since 1.1   */  public TestEvent(int type, long timestamp, String testName,      String testClassName, String errorClassName, String msg, String stackTrace)  {    super();    setType(type);    setTimestamp(timestamp);    setTestName(testName);    setTestClassName(testClassName);    setMsg(msg);    setErrorClassName(errorClassName);    setStackTrace(stackTrace);  }  /**   * Creates start test event with given test name and test classname.   *    * @param timestamp   *          time at which this event occurred.   * @param testName   *          name of test started.   * @param testClassName   *          classname of test started.   *    * @return the created test event.   * @since 1.1   */  public static TestEvent createStartTestEvent(long timestamp, String testName,      String testClassName)  {    return new TestEvent(START_TEST, timestamp, testName, testClassName, null,        null, null);  }  /**   * Creates end test event with given test name and test classname.   *    * @param timestamp   *          time at which this event occurred.   * @param testName   *          name of test finished.   * @param testClassName   *          classname of test finished.   *    * @return the created test event.   * @since 1.1   */  public static TestEvent createEndTestEvent(long timestamp, String testName,      String testClassName)  {    return new TestEvent(END_TEST, timestamp, testName, testClassName, null,        null, null);  }  /**   * Creates error test event with given test name, test classname, classname,   * message and stack trace of error occurred.   *    * @param timestamp   *          time at which this event occurred.   * @param testName   *          name of test during execution error occurred.   * @param testClassName   *          classname of test during execution error occurred.   * @param errorClassName   *          classname of error occurred.   * @param msg   *          message of error occurred.   * @param stackTrace   *          stack trace of error occurred.   *    * @return the created test event.   * @since 1.1   */  public static TestEvent createErrorTestEvent(long timestamp, String testName,      String testClassName, String errorClassName, String msg, String stackTrace)  {    return new TestEvent(ERROR_TEST, timestamp, testName, testClassName,        errorClassName, msg, stackTrace);  }  /**   * Creates failure test event with given test name, test classname, classname,   * message and stack trace of error occurred.   *    * @param timestamp   *          time at which this event occurred.   * @param testName   *          name of test during execution failure occurred.   * @param testClassName   *          classname of test during execution failure occurred.   * @param errorClassName   *          classname of failure occurred.   * @param msg   *          message of failure occurred.   * @param stackTrace   *          stack trace of failure occurred.   *    * @return the created test event.   * @since 1.1   */  public static TestEvent createFailTestEvent(long timestamp, String testName,      String testClassName, String errorClassName, String msg, String stackTrace)  {    return new TestEvent(FAIL_TEST, timestamp, testName, testClassName,        errorClassName, msg, stackTrace);  }  /**   * Returns classname of error or failure occurred.   *    * @return the classname of error or failure occurred.   * @since 1.1   */  public String getErrorClassName()  {    return this.errorClassName;  }  /**   * Sets classname of error or failure occurred.   *    * @param errorClassName   *          classname of error or failure occurred.   * @since 1.1   */  public void setErrorClassName(String errorClassName)  {    this.errorClassName = errorClassName;  }  /**   * Returns message of error or failure occurred.   *    * @return the message of error or failure occurred.   * @since 1.1   */  public String getMsg()  {    return this.msg;  }  /**   * Sets message of error or failure occurred.   *    * @param msg   *          the message of error or failure occurred.   * @since 1.1   */  public void setMsg(String msg)  {    this.msg = msg;  }  /**   * Returns stack trace of error or failure occurred.   *    * @return the stack trace of error or failure occurred.   * @since 1.1   */  public String getStackTrace()  {    return this.stackTrace;  }  /**   * Sets stack trace of error or failure occurred.   *    * @param stackTrace   *          stack trace of error or failure occurred.   * @since 1.1   */  public void setStackTrace(String stackTrace)  {    this.stackTrace = stackTrace;  }  /**   * Returns classname of test during which execution a test event occurred.   *    * @return classname of test during which execution a test event occurred.   * @since 1.1   */  public String getTestClassName()  {    return this.testClassName;  }  /**   * Sets classname of test during which execution a test event occurred.   *    * @param testClassName   *          the classname of test during which execution a test event   *          occurred.   * @since 1.1   */  public void setTestClassName(String testClassName)  {    this.testClassName = testClassName;  }  /**   * Returns name of test during which execution a test event occurred.   *    * @return the name of test during which execution a test event occurred.   * @since 1.1   */  public String getTestName()  {    return this.testName;  }  /**   * Sets name of test during which execution a test event occurred.   *    * @param testName   *          name of test during which execution a test event occurred.   * @since 1.1   */  public void setTestName(String testName)  {    this.testName = testName;  }  /**   * Returns time at which test event occurred.   *    * @return the time at which test event occurred.   * @since 1.1   */  public long getTimestamp()  {    return this.timestamp;  }  /**   * Sets time at which test event occurred.   *    * @param timestamp   *          the time at which test event occurred.   *    * @since 1.1   */  public void setTimestamp(long timestamp)  {    this.timestamp = timestamp;  }  /**   * Returns whether this test event is a failure test event.   *    * @return <code>true</code> if this test event is a failure test event,   *         <code>false</code> otherwise.   * @since 1.1   */  public boolean isFailure()  {    return this.isFailure;  }  /**   * Returns type of test event.   *    * @return the type of test event.   * @since 1.1   */  public int getType()  {    return this.type;  }  /**   * Sets type of test event.   *    * @param type   *          type of test event.   * @since 1.1   */  public void setType(int type)  {    this.type = type;  }  /*   * (non-Javadoc)   *    * @see java.lang.Object#toString()   */  public String toString()  {    StringBuffer sb = new StringBuffer();    sb.append(typeNames[this.type]).append('=').append(this.getTestName())        .append('(').append(this.getTestClassName()).append(")[").append(            this.timestamp).append("]\n");    if (type == ERROR_TEST || type == FAIL_TEST)    {      sb.append('(').append(this.getErrorClassName()).append(')').append(          this.getMsg()).append("\n{\n").append(this.getStackTrace()).append(          "\n}");    }    return sb.toString();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -