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

📄 testscreen.java

📁 MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自JUnit框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package momeunit.runner;import java.util.Vector;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.game.GameCanvas;import mome.ext.ListShow;import mome.ext.StringWrapper;import momeunit.framework.AssertionFailedError;import momeunit.framework.Test;import momeunit.framework.TestCase;import momeunit.framework.TestListener;import momeunit.framework.TestResult;/** * Canvas used by MIDletTestRunner. Displays progress bar and statistics of * tests run at the top part of screen. Displays list of tests that fails or * completed with errors at middle part of screen and detailed message of * failure of selected test at bottom part of screen. See * {@link momeunit.runner package description} for more details about UI usage. *  * @author Sergio Morozov * @version 1.1.2 */public class TestScreen extends GameCanvas implements TestListener{  /**   * Errors statistics label.   */  private static final String ERRORS_COUNT_PREFIX = "Errors: ";  /**   * Failures statistics label.   */  private static final String FAILURES_COUNT_PREFIX = "Failures: ";  /**   * Tests count statistics label.   */  private static final String TESTS_COUNT_PREFIX = "Tests: ";  /**   * Progress bar height.   */  private static final int PROGRESSBAR_HEIGHT = 10;  /**   * Margin.   */  private static final int MARGIN = 0;  /**   * Default foreground color.   */  private static final int DEFAULT_FG_COLOR = 0xFFFFFF;  /**   * Default background color.   */  private static final int DEFAULT_BG_COLOR = 0x00007F;  /**   * Default ok color.   */  private static final int DEFAULT_OK_COLOR = 0x00FF00;  /**   * Default failures color.   */  private static final int DEFAULT_FAILURE_COLOR = 0xFF00FF;  /**   * Default errors color.   */  private static final int DEFAULT_ERROR_COLOR = 0xFF0000;  /**   * Default selected item background color.   */  private static final int DEFAULT_SELECTED_BG_COLOR = 0xFFFFFF;  /**   * Default selected item foreground color.   */  private static final int DEFAULT_SELECTED_FG_COLOR = 0x0;  /**   * Default font.   */  private static final Font DEFAULT_FONT = Font.getDefaultFont();  /**   * Default statistics font.   */  private static final Font DEFAULT_STATISTICS_FONT = Font.getDefaultFont();  private int bgColor = DEFAULT_BG_COLOR;  private int fgColor = DEFAULT_FG_COLOR;  private int okColor = DEFAULT_OK_COLOR;  private int failureColor = DEFAULT_FAILURE_COLOR;  private int errorColor = DEFAULT_ERROR_COLOR;  private Font statisticsFont = DEFAULT_STATISTICS_FONT;  private int statisticsFontHeight = statisticsFont.getHeight();  private Font font = DEFAULT_FONT;  private int fontHeight = font.getHeight();  private static final int TOP_LEFT = Graphics.TOP | Graphics.LEFT;  private TestResult result = null;  private int testCasesNumber;  private boolean printToStdErr = false;  private boolean printStackTrace = false;  private Graphics g = null;  private boolean failureListType = true;  private boolean hasFailures = false;  private Vector failures = null;  private boolean hasErrors = false;  private Vector errors = null;  private ListShow failTests = null;  private ListShow errorTests = null;  private StringWrapper msgWrapper = null;  private int width;  private int height;  private String lastTest = null;  /**   * Instantiates TestScreen with given title and test cases number.   *    * @param name   *          title of TestScreen.   * @since 1.0   */  public TestScreen(String name)  {    this(name, false, false);  }  /**   * Instantiates TestScreen with given title and test cases number.   *    * @param name   *          title of TestScreen.   * @param testCasesNumber   *          number of test cases.   * @since 1.0   */  public TestScreen(String name, int testCasesNumber)  {    this(name);    this.clearResult(testCasesNumber);  }  /**   * Instantiates TestScreen with given title, test cases number and print   * behaviour flags. if <code>printStdErr</code> is <code>true</code>   * TestScreen will print test failures and errors to standard error output   * together with stack-trace if <code>printStackTrace</code> flag is   * <code>true</code>.   *    * @param name   *          title of TestScreen.   * @param testCasesNumber   *          number of test cases.   * @param printStdErr   *          print to standard error flag.   * @param printStackTrace   *          print stack-trace flag.   * @since 1.0   */  public TestScreen(String name, int testCasesNumber, boolean printStdErr,      boolean printStackTrace)  {    this(name, printStdErr, printStackTrace);    this.clearResult(testCasesNumber);  }  /**   * Instantiates TestScreen with given title and print behaviour flags. if   * <code>printStdErr</code> is <code>true</code> TestScreen will print   * test failures and errors to standard error output together with stack-trace   * if <code>printStackTrace</code> flag is <code>true</code>.   *    * @param name   *          title of TestScreen.   * @param printStdErr   *          print to standard error flag.   * @param printStackTrace   *          print stack-trace flag.   * @since 1.0   */  public TestScreen(String name, boolean printStdErr, boolean printStackTrace)  {    super(false);    this.setTitle(name);    this.setPrintToStdErr(printStdErr);    this.setPrintStackTrace(printStackTrace);    this.g = this.getGraphics();    this.setSize(this.getWidth(), this.getHeight());    int listY = MARGIN + PROGRESSBAR_HEIGHT + this.statisticsFontHeight;    this.errorTests = new ListShow(0, listY, this.width,        (this.height - listY) / 2);    this.errorTests.setBGColor(this.bgColor);    this.errorTests.setFGColor(this.fgColor);    this.errors = new Vector();    this.failTests = new ListShow(0, listY, this.width,        (this.height - listY) / 2);    this.failTests.setBGColor(this.bgColor);    this.failTests.setFGColor(this.fgColor);    this.failures = new Vector();    this.setSelBgColor(DEFAULT_SELECTED_BG_COLOR);    this.setSelFgColor(DEFAULT_SELECTED_FG_COLOR);    this.msgWrapper = new StringWrapper(this.width, this.font);  }  /**   * Sets the size of Canvas.   *    * @param width   *          width of canvas.   * @param height   *          height of canvas.   * @since 1.0   */  private void setSize(int width, int height)  {    this.width = width;    this.height = height;  }  /**   * Sets font of TestScreen.   *    * @param font   *          the font to set   * @throws NullPointerException   *           if font is <code>null</code>.   * @since 1.0   */  public void setFont(Font font)  {    if (font == null) throw new NullPointerException("font");    this.font = font;    this.fontHeight = this.font.getHeight();    this.msgWrapper.setFont(this.font);  }  /**   * Sets font of statistics of TestScreen.   *    * @param font   *          the font of statistics to set   * @throws NullPointerException   *           if font is <code>null</code>.   * @since 1.0   */  public void setStatisticsFont(Font font)  {    if (font == null) throw new NullPointerException("font");    this.statisticsFont = font;    this.statisticsFontHeight = this.statisticsFont.getHeight();    int listY = MARGIN + PROGRESSBAR_HEIGHT + this.statisticsFontHeight;    this.failTests.setY(listY);    this.errorTests.setY(listY);  }  /**   * Sets background color.   *    * @param color   *          color to be set.   * @since 1.0   */  public void setBgColor(int color)  {    this.bgColor = color;    this.failTests.setBGColor(this.bgColor);    this.errorTests.setBGColor(this.bgColor);  }  /**   * Sets background color of selected item.   *    * @param color   *          color to be set.   * @since 1.0   */  public void setSelBgColor(int color)  {    this.failTests.setSelectedBGColor(color);    this.errorTests.setSelectedBGColor(color);  }  /**   * Sets foreground color of selected item.   *    * @param color   *          color to be set.   * @since 1.0   */  public void setSelFgColor(int color)  {    this.failTests.setSelectedFGColor(color);    this.errorTests.setSelectedFGColor(color);  }  /**   * Sets color of progress bar when some tests completed with errors ans color   * of error statistics.   *    * @param color   *          color to be set.   * @since 1.0   */  public void setErrorColor(int color)  {    this.errorColor = color;  }  /**   * Sets color of progress bar when some tests fails and there are no errors   * ans color of failure statistics.   *    * @param color   *          color to be set.   * @since 1.0   */  public void setFailureColor(int color)  {    this.failureColor = color;  }  /**   * Sets foreground color.   *    * @param color   *          color to be set.   * @since 1.0   */  public void setFgColor(int color)  {    this.fgColor = color;    this.failTests.setFGColor(this.fgColor);    this.errorTests.setFGColor(this.fgColor);  }  /**   * Sets color of progress bar when tests completed successfully.   *    * @param color   *          color to be set.   * @since 1.0   */  public void setOkColor(int color)  {    this.okColor = color;  }  /**   * Checks if test failure and error events should be printed to standard error   * output.   *    * @return <code>true</code> if test failure and error events should be   *         printed to standard error output, <code>false</code> otherwise.   * @since 1.0   */  public boolean isPrintToStdErr()  {    return this.printToStdErr;  }

⌨️ 快捷键说明

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