1 /*
2  * Copyright (C) 2012 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 
17 package com.android.compatibility;
18 
19 import com.android.tradefed.result.ITestInvocationListener;
20 import com.android.tradefed.result.TestDescription;
21 
22 public final class FailureCollectingListener implements ITestInvocationListener {
23     private String mTestTrace = null;
24 
25     @Override
testFailed(TestDescription test, String trace)26     public void testFailed(TestDescription test, String trace) {
27         setStackTrace(trace != null ? trace : "unknown failure");
28     }
29 
30     @Override
testAssumptionFailure(TestDescription test, String trace)31     public void testAssumptionFailure(TestDescription test, String trace) {
32         setStackTrace(trace != null ? trace : "unknown assumption failure");
33     }
34 
35     /** {@inheritDoc} */
36     @Override
testRunFailed(String errorMessage)37     public void testRunFailed(String errorMessage) {
38         setStackTrace(errorMessage);
39     }
40 
41     /**
42      * Fetches the stack trace if any.
43      *
44      * @return the stack trace.
45      */
getStackTrace()46     public String getStackTrace() {
47         return mTestTrace;
48     }
49 
50     /**
51      * Sets the stack trace.
52      *
53      * @param stackTrace {@link String} stack trace to set.
54      */
setStackTrace(String stackTrace)55     public void setStackTrace(String stackTrace) {
56         this.mTestTrace = stackTrace;
57     }
58 }
59