blob: 96213e735bac209313da3929d60ea9d74c2398d6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001package android.test;
2
3import java.io.PrintStream;
4
5import android.os.Bundle;
6
7import junit.framework.AssertionFailedError;
8import junit.framework.Test;
9import junit.framework.TestCase;
10import junit.runner.BaseTestRunner;
11import junit.textui.ResultPrinter;
12
13
14/**
15 * Subclass of ResultPrinter that adds test case results to a bundle.
16 *
17 * {@hide} - This class is deprecated, and will be going away. Please don't use it.
18 */
19public class BundlePrinter extends ResultPrinter {
20
21 private Bundle mResults;
22 private boolean mFailure;
23 private boolean mError;
24
25 public BundlePrinter(PrintStream writer, Bundle result) {
26 super(writer);
27 mResults = result;
28 }
29
30 @Override
31 public void addError(Test test, Throwable t) {
32 mResults.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
33 mFailure = true;
34 super.addError(test, t);
35 }
36
37 @Override
38 public void addFailure(Test test, AssertionFailedError t) {
39 mResults.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
40 mError = true;
41 super.addFailure(test, t);
42 }
43
44 @Override
45 public void endTest(Test test) {
46 if (!mFailure && !mError) {
47 mResults.putString(getComboName(test), "passed");
48 }
49 super.endTest(test);
50 }
51
52 @Override
53 public void startTest(Test test) {
54 mFailure = false;
55 mError = false;
56 super.startTest(test);
57 }
58
59 private String getComboName(Test test) {
60 return test.getClass().getName() + ":" + ((TestCase) test).getName();
61 }
62
63}