Debian Codegraph @

compilationTests/src/test/java/android/databinding/compilationTest/CompilationResult.java

raw
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 import android.databinding.tool.util.StringUtils;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import static org.junit.Assert.assertEquals;
27
28 public class CompilationResult {
29 public final int resultCode;
30 public final String output;
31 public final String error;
32
33 public CompilationResult(int resultCode, String output, String error) {
34 this.resultCode = resultCode;
35 this.output = output;
36 this.error = error;
37 }
38
39 public boolean resultContainsText(String text) {
40 return resultCode == 0 && output.indexOf(text) > 0;
41 }
42
43 public boolean errorContainsText(String text) {
44 return resultCode != 0 && error.indexOf(text) > 0;
45 }
46
47 public ScopedException getBindingException() {
48 List<ScopedException> errors = ScopedException.extractErrors(error);
49 if (errors.isEmpty()) {
50 return null;
51 }
52 assertEquals(error, 1, errors.size());
53 return errors.get(0);
54 }
55
56 public List<String> getBindingWarnings() {
57 List<String> warnings = new ArrayList<String>();
58 for (String line : error.split(StringUtils.LINE_SEPARATOR)) {
59 if (line.startsWith("warning:")) {
60 warnings.add(line.substring("warning:".length()));
61 }
62 }
63 return warnings;
64 }
65
66 public List<ScopedException> getBindingExceptions() {
67 return ScopedException.extractErrors(error);
68 }
69 }