📄 unitresultformatter.java
字号:
package org.momeunit.ant.formatter;import java.io.OutputStream;import org.momeunit.ant.event.TestEventListener;/** * The abstract base class of every formatter. Extends {@link TestEventListener}. * Contains callback methods {@link #startTestSuite(String)}, * {@link #startTest(org.momeunit.ant.event.TestEvent)}, * {@link #addError(org.momeunit.ant.event.TestEvent)}, * {@link #addFailure(org.momeunit.ant.event.TestEvent)}, * {@link #endTest(org.momeunit.ant.event.TestEvent)} and * {@link #endTestSuite()} that formatter should implement for processing test * events and creating report. Contains base and utility methods that formatter * can use in generating report. * * @author Sergio Morozov * @version 1.1.2 */public abstract class UnitResultFormatter extends TestEventListener{ /** * Default encoding of report. * * @since 1.1 */ public static final String DEFAULT_ENCODING = "utf-8"; /** * Default test suite name. */ private static final String DEFAULT_TESTSUITE_NAME = "unknown"; /** * Output where to send report. */ private OutputStream out = null; /** * Characters printed on <code>System.out</code> while tests run. */ private String systemOutput = null; /** * Characters printed on <code>System.err</code> while tests run. */ private String systemError = null; /** * Filter trace flag. */ private boolean filterTrace = true; /** * Test suite name. */ private String testSuiteName = DEFAULT_TESTSUITE_NAME; /** * Encoding used in creating report. */ private String encoding = DEFAULT_ENCODING; /** * Returns encoding of generated report. * * @return the encoding of generated report. * @since 1.1 */ public String getEncoding() { return this.encoding; } /** * Sets encoding of report. * * @param encoding * the encoding to use in generating report. * @since 1.1 */ public void setEncoding(String encoding) { this.encoding = encoding; } /** * Sets {@link OutputStream} where formatter sends report. * * @param out * the out used to create report. * @since 1.1 */ public void setOutput(OutputStream out) { this.out = out; } /** * Sets output generated by tests run and emulator. * * @param out * output generated by tests run and emulator. * @since 1.1 */ public void setSystemOutput(String out) { systemOutput = out; } /** * Sets error output generated by tests run and emulator. * * @param err * error output generated by tests run and emulator. * @since 1.1 */ public void setSystemError(String err) { systemError = err; } /** * Sets whether to filter <code>momeunit</code> and <code>mome</code> * stack frames from stack trace. * * @param filterTrace * <code>filtertrace</code> flag to set. * @since 1.1 */ public void setFilterTrace(boolean filterTrace) { this.filterTrace = filterTrace; } /** * Returns whether to filter <code>momeunit</code> and <code>mome</code> * stack frames from stack trace. * * @return the <code>filtertrace</code> flag. * @since 1.1 */ public boolean isFilterTrace() { return this.filterTrace; } /** * Returns {@link OutputStream} where formatter sends report. * * @return {@link OutputStream} where formatter sends report. * @since 1.1 */ public OutputStream getOutput() { return this.out; } /** * Returns error output generated by tests run and emulator. * * @return error output generated by tests run and emulator. * @since 1.1 */ public String getSystemError() { return this.systemError; } /** * Returns output generated by tests run and emulator. * * @return output generated by tests run and emulator. * @since 1.1 */ public String getSystemOutput() { return this.systemOutput; } /** * Callback method that indicates the start of tests run. * * @param name * name of test suite that runs. * @since 1.1 */ public void startTestSuite(String name) { this.testSuiteName = name != null ? name : DEFAULT_TESTSUITE_NAME; } /** * Returns test suite name. * * @return test suite name. * @since 1.1 */ public String getTestSuiteName() { return this.testSuiteName; } /** * Callback method that indicates the end of tests run. * * @since 1.1 */ public void endTestSuite() {} /** * Utility method that excludes <code>momeunit</code> and <code>mome</code> * stack frames from given stack trace. * * @param stackTrace * stack trace to excludes <code>momeunit</code> and * <code>mome</code> stack frames from. * @return stack trace with <code>momeunit</code> and <code>mome</code> * stack frames excluded. * @since 1.1 */ public static String filterStackTrace(String stackTrace) { return stackTrace.replaceAll("\\s*at\\s*momeunit\\..*", "").replaceAll( "\\s*at\\s*mome\\..*", ""); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -