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