• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 package com.android.launcher3.folder;
17 
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertTrue;
20 
21 import android.content.ComponentName;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.UserHandle;
25 
26 import com.android.launcher3.model.data.AppInfo;
27 import com.android.launcher3.model.data.WorkspaceItemInfo;
28 import com.android.launcher3.util.Executors;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.robolectric.RobolectricTestRunner;
34 import org.robolectric.RuntimeEnvironment;
35 import org.robolectric.annotation.LooperMode;
36 import org.robolectric.annotation.LooperMode.Mode;
37 
38 import java.util.ArrayList;
39 
40 @RunWith(RobolectricTestRunner.class)
41 @LooperMode(Mode.PAUSED)
42 public final class FolderNameProviderTest {
43     private Context mContext;
44     private WorkspaceItemInfo mItem1;
45     private WorkspaceItemInfo mItem2;
46 
47     @Before
setUp()48     public void setUp() {
49         mContext = RuntimeEnvironment.application;
50         mItem1 = new WorkspaceItemInfo(new AppInfo(
51                 new ComponentName("a.b.c", "a.b.c/a.b.c.d"),
52                 "title1",
53                 UserHandle.of(10),
54                 new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))
55         ));
56         mItem2 = new WorkspaceItemInfo(new AppInfo(
57                 new ComponentName("a.b.c", "a.b.c/a.b.c.d"),
58                 "title2",
59                 UserHandle.of(10),
60                 new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))
61         ));
62     }
63 
64     @Test
getSuggestedFolderName_workAssignedToEnd()65     public void getSuggestedFolderName_workAssignedToEnd() throws Exception {
66         ArrayList<WorkspaceItemInfo> list = new ArrayList<>();
67         list.add(mItem1);
68         list.add(mItem2);
69         FolderNameInfos nameInfos = new FolderNameInfos();
70         Executors.MODEL_EXECUTOR.submit(() ->
71                 new FolderNameProvider().getSuggestedFolderName(mContext, list, nameInfos)).get();
72         assertEquals("Work", nameInfos.getLabels()[0]);
73 
74         nameInfos.setLabel(0, "candidate1", 1.0f);
75         nameInfos.setLabel(1, "candidate2", 1.0f);
76         nameInfos.setLabel(2, "candidate3", 1.0f);
77         Executors.MODEL_EXECUTOR.submit(() ->
78                 new FolderNameProvider().getSuggestedFolderName(mContext, list, nameInfos)).get();
79         assertEquals("Work", nameInfos.getLabels()[3]);
80         assertTrue(nameInfos.hasSuggestions());
81         assertTrue(nameInfos.hasPrimary());
82     }
83 }
84