1 /*
2  * Copyright (C) 2018 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.textclassifier;
18 
19 import android.content.Context;
20 import com.android.textclassifier.common.ModelFileManager;
21 import com.android.textclassifier.common.ModelFileManager.RegularFileFullMatchLister;
22 import com.android.textclassifier.common.ModelType;
23 import com.google.common.collect.ImmutableList;
24 import java.io.File;
25 
26 /** Utils to access test data files. */
27 public final class TestDataUtils {
28   private static final String TEST_ANNOTATOR_MODEL_PATH = "testdata/annotator.model";
29   private static final String TEST_ACTIONS_MODEL_PATH = "testdata/actions.model";
30   private static final String TEST_LANGID_MODEL_PATH = "testdata/langid.model";
31 
32   /** Returns the root folder that contains the test data. */
getTestDataFolder()33   public static File getTestDataFolder() {
34     return new File("/data/local/tmp/TextClassifierServiceTest/");
35   }
36 
getTestAnnotatorModelFile()37   public static File getTestAnnotatorModelFile() {
38     return new File(getTestDataFolder(), TEST_ANNOTATOR_MODEL_PATH);
39   }
40 
getTestActionsModelFile()41   public static File getTestActionsModelFile() {
42     return new File(getTestDataFolder(), TEST_ACTIONS_MODEL_PATH);
43   }
44 
getLangIdModelFile()45   public static File getLangIdModelFile() {
46     return new File(getTestDataFolder(), TEST_LANGID_MODEL_PATH);
47   }
48 
createModelFileManagerForTesting(Context context)49   public static ModelFileManager createModelFileManagerForTesting(Context context) {
50     return new ModelFileManager(
51         context,
52         ImmutableList.of(
53             new RegularFileFullMatchLister(
54                 ModelType.ANNOTATOR, getTestAnnotatorModelFile(), () -> true),
55             new RegularFileFullMatchLister(
56                 ModelType.ACTIONS_SUGGESTIONS, getTestActionsModelFile(), () -> true),
57             new RegularFileFullMatchLister(ModelType.LANG_ID, getLangIdModelFile(), () -> true)));
58   }
59 
TestDataUtils()60   private TestDataUtils() {}
61 }
62