blob: 06b48c61c38c25829d5062c6ce15b1afc41f81e4 [file] [log] [blame]
Brian Muramatsu7f64e852011-02-17 16:52:16 -08001/*
2 * Copyright (C) 2011 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
17import vogar.Expectation;
18import vogar.ExpectationStore;
19import vogar.ModeId;
20
21import java.io.File;
22import java.io.FilenameFilter;
23import java.io.IOException;
24import java.util.Arrays;
25import java.util.HashSet;
26import java.util.Set;
27
28public class VogarUtils {
29
30 public static boolean isVogarKnownFailure(ExpectationStore expectationStore,
31 final String testClassName,
32 final String testMethodName) {
33 String fullTestName = String.format("%s#%s", testClassName, testMethodName);
34 return expectationStore != null
35 && expectationStore.get(fullTestName) != Expectation.SUCCESS;
36 }
37
38 public static ExpectationStore provideExpectationStore(String dir) throws IOException {
39 if (dir == null) {
40 return null;
41 }
42 ExpectationStore result = ExpectationStore.parse(getExpectationFiles(dir), ModeId.DEVICE);
43 return result;
44 }
45
46 private static Set<File> getExpectationFiles(String dir) {
47 Set<File> expectSet = new HashSet<File>();
48 File[] files = new File(dir).listFiles(new FilenameFilter() {
49 // ignore obviously temporary files
50 public boolean accept(File dir, String name) {
51 return !name.endsWith("~") && !name.startsWith(".");
52 }
53 });
54 if (files != null) {
55 expectSet.addAll(Arrays.asList(files));
56 }
57 return expectSet;
58 }
59}