blob: 8891d3fd2dca7227f47134389dc3df28ad539c05 [file] [log] [blame]
Tony Makfc039c32019-01-17 19:32:08 +00001/*
Tony Mak8ab9b182019-03-01 16:44:17 +00002 * Copyright (C) 2019 The Android Open Source Project
Tony Makfc039c32019-01-17 19:32:08 +00003 *
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
Tony Mak8ab9b182019-03-01 16:44:17 +000017package android.view.textclassifier.intent;
Tony Makfc039c32019-01-17 19:32:08 +000018
19import static com.google.common.truth.Truth.assertThat;
20
21import android.content.Intent;
Tony Mak8ab9b182019-03-01 16:44:17 +000022import android.view.textclassifier.TextClassifier;
Tony Makfc039c32019-01-17 19:32:08 +000023
24import androidx.test.InstrumentationRegistry;
25import androidx.test.filters.SmallTest;
26import androidx.test.runner.AndroidJUnit4;
27
28import com.google.android.textclassifier.AnnotatorModel;
29
30import org.junit.Before;
31import org.junit.Test;
32import org.junit.runner.RunWith;
33
34import java.util.List;
35
36@SmallTest
37@RunWith(AndroidJUnit4.class)
Tony Mak8ab9b182019-03-01 16:44:17 +000038public class LegacyIntentClassificationFactoryTest {
Tony Makfc039c32019-01-17 19:32:08 +000039
40 private static final String TEXT = "text";
41
Tony Mak8ab9b182019-03-01 16:44:17 +000042 private LegacyClassificationIntentFactory mLegacyIntentClassificationFactory;
Tony Makfc039c32019-01-17 19:32:08 +000043
44 @Before
45 public void setup() {
Tony Mak8ab9b182019-03-01 16:44:17 +000046 mLegacyIntentClassificationFactory = new LegacyClassificationIntentFactory();
Tony Makfc039c32019-01-17 19:32:08 +000047 }
48
49 @Test
50 public void create_typeDictionary() {
51 AnnotatorModel.ClassificationResult classificationResult =
52 new AnnotatorModel.ClassificationResult(
53 TextClassifier.TYPE_DICTIONARY,
54 1.0f,
55 null,
56 null,
57 null,
58 null,
59 null,
60 null,
61 null,
Tony Makac9b4d82019-02-15 13:57:38 +000062 null,
63 null,
64 null,
Tony Mak159f0282019-03-01 14:03:25 +000065 null,
Tony Mak2a3adb72019-03-20 17:55:53 +000066 null,
Tony Mak237f37b2019-03-22 13:35:40 +000067 null,
Tony Mak221bb4f2019-09-12 17:17:14 +010068 null,
69 0L,
70 0L,
71 0d);
Tony Makfc039c32019-01-17 19:32:08 +000072
Tony Mak8ab9b182019-03-01 16:44:17 +000073 List<LabeledIntent> intents = mLegacyIntentClassificationFactory.create(
Tony Makfc039c32019-01-17 19:32:08 +000074 InstrumentationRegistry.getContext(),
75 TEXT,
76 /* foreignText */ false,
77 null,
78 classificationResult);
79
80 assertThat(intents).hasSize(1);
Tony Makac9b4d82019-02-15 13:57:38 +000081 LabeledIntent labeledIntent = intents.get(0);
82 Intent intent = labeledIntent.intent;
Tony Makfc039c32019-01-17 19:32:08 +000083 assertThat(intent.getAction()).isEqualTo(Intent.ACTION_DEFINE);
84 assertThat(intent.getStringExtra(Intent.EXTRA_TEXT)).isEqualTo(TEXT);
Tony Makfc039c32019-01-17 19:32:08 +000085 }
86
87 @Test
88 public void create_translateAndDictionary() {
89 AnnotatorModel.ClassificationResult classificationResult =
90 new AnnotatorModel.ClassificationResult(
91 TextClassifier.TYPE_DICTIONARY,
92 1.0f,
93 null,
94 null,
95 null,
96 null,
97 null,
98 null,
99 null,
Tony Makac9b4d82019-02-15 13:57:38 +0000100 null,
101 null,
102 null,
Tony Mak159f0282019-03-01 14:03:25 +0000103 null,
Tony Mak2a3adb72019-03-20 17:55:53 +0000104 null,
Tony Mak237f37b2019-03-22 13:35:40 +0000105 null,
Tony Mak221bb4f2019-09-12 17:17:14 +0100106 null,
107 0L,
108 0L,
109 0d);
Tony Makfc039c32019-01-17 19:32:08 +0000110
Tony Mak8ab9b182019-03-01 16:44:17 +0000111 List<LabeledIntent> intents = mLegacyIntentClassificationFactory.create(
Tony Makfc039c32019-01-17 19:32:08 +0000112 InstrumentationRegistry.getContext(),
113 TEXT,
114 /* foreignText */ true,
115 null,
116 classificationResult);
117
118 assertThat(intents).hasSize(2);
Tony Makac9b4d82019-02-15 13:57:38 +0000119 assertThat(intents.get(0).intent.getAction()).isEqualTo(Intent.ACTION_DEFINE);
120 assertThat(intents.get(1).intent.getAction()).isEqualTo(Intent.ACTION_TRANSLATE);
Tony Makfc039c32019-01-17 19:32:08 +0000121 }
122}