1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.test;
18
19import junit.framework.*;
20import junit.framework.TestCase;
21import junit.runner.BaseTestRunner;
22import android.os.Bundle;
23
24/**
25 * A {@link TestListener} that adds test case results to a bundle.
26 *
27 * {@hide} - This class is deprecated, and will be going away.  Please don't use it.
28 */
29public class BundleTestListener implements TestListener {
30
31    private Bundle mBundle;
32    private boolean mFailed;
33
34    public BundleTestListener(Bundle bundle) {
35        mBundle = bundle;
36    }
37
38
39    public void addError(Test test, Throwable t) {
40        mBundle.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
41        mFailed = true;
42    }
43
44    public void addFailure(Test test, junit.framework.AssertionFailedError t) {
45        mBundle.putString(getComboName(test), BaseTestRunner.getFilteredTrace(t));
46        mFailed = true;
47    }
48
49    public void endTest(Test test) {
50        if (!mFailed) {
51            mBundle.putString(getComboName(test), "passed");
52        }
53    }
54
55    public void startTest(Test test) {
56        mFailed = false;
57    }
58
59    private String getComboName(Test test) {
60        return test.getClass().getName() + ":" + ((TestCase) test).getName();
61    }
62
63}
64