1 /*
2  * Copyright (C) 2015 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 android.databinding.compilationTest;
18 
19 import android.databinding.tool.processing.ScopedErrorReport;
20 import android.databinding.tool.processing.ScopedException;
21 
22 import java.util.List;
23 
24 import static org.junit.Assert.assertEquals;
25 
26 public class CompilationResult {
27     public final int resultCode;
28     public final String output;
29     public final String error;
30 
CompilationResult(int resultCode, String output, String error)31     public CompilationResult(int resultCode, String output, String error) {
32         this.resultCode = resultCode;
33         this.output = output;
34         this.error = error;
35     }
36 
resultContainsText(String text)37     public boolean resultContainsText(String text) {
38         return resultCode == 0 && output.indexOf(text) > 0;
39     }
40 
errorContainsText(String text)41     public boolean errorContainsText(String text) {
42         return resultCode != 0 && error.indexOf(text) > 0;
43     }
44 
getBindingException()45     public ScopedException getBindingException() {
46         List<ScopedException> errors = ScopedException.extractErrors(error);
47         if (errors.isEmpty()) {
48             return null;
49         }
50         assertEquals(error, 1, errors.size());
51         return errors.get(0);
52     }
53 
getBindingExceptions()54     public List<ScopedException> getBindingExceptions() {
55         return ScopedException.extractErrors(error);
56     }
57 }
58