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 
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.robolectric.RobolectricTestRunner;
33 import org.robolectric.RuntimeEnvironment;
34 
35 import java.util.ArrayList;
36 
37 @RunWith(RobolectricTestRunner.class)
38 public final class FolderNameProviderTest {
39     private Context mContext;
40     private WorkspaceItemInfo mItem1;
41     private WorkspaceItemInfo mItem2;
42 
43     @Before
setUp()44     public void setUp() {
45         mContext = RuntimeEnvironment.application;
46         mItem1 = new WorkspaceItemInfo(new AppInfo(
47                 new ComponentName("a.b.c", "a.b.c/a.b.c.d"),
48                 "title1",
49                 UserHandle.of(10),
50                 new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))
51         ));
52         mItem2 = new WorkspaceItemInfo(new AppInfo(
53                 new ComponentName("a.b.c", "a.b.c/a.b.c.d"),
54                 "title2",
55                 UserHandle.of(10),
56                 new Intent().setComponent(new ComponentName("a.b.c", "a.b.c/a.b.c.d"))
57         ));
58     }
59 
60     @Test
getSuggestedFolderName_workAssignedToEnd()61     public void getSuggestedFolderName_workAssignedToEnd() {
62         ArrayList<WorkspaceItemInfo> list = new ArrayList<>();
63         list.add(mItem1);
64         list.add(mItem2);
65         FolderNameInfos nameInfos = new FolderNameInfos();
66         new FolderNameProvider().getSuggestedFolderName(mContext, list, nameInfos);
67         assertEquals("Work", nameInfos.getLabels()[0]);
68 
69         nameInfos.setLabel(0, "candidate1", 1.0f);
70         nameInfos.setLabel(1, "candidate2", 1.0f);
71         nameInfos.setLabel(2, "candidate3", 1.0f);
72         new FolderNameProvider().getSuggestedFolderName(mContext, list, nameInfos);
73         assertEquals("Work", nameInfos.getLabels()[3]);
74         assertTrue(nameInfos.hasSuggestions());
75         assertTrue(nameInfos.hasPrimary());
76     }
77 }
78