1 /* 2 * Copyright (C) 2019 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.customization.model.grid; 17 18 import static junit.framework.TestCase.fail; 19 20 import static org.mockito.Matchers.anyBoolean; 21 import static org.mockito.Mockito.verify; 22 import static org.mockito.Mockito.when; 23 24 import androidx.annotation.Nullable; 25 26 import com.android.customization.model.CustomizationManager.Callback; 27 import com.android.customization.module.ThemesUserEventLogger; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.mockito.Mock; 33 import org.mockito.MockitoAnnotations; 34 import org.robolectric.Robolectric; 35 import org.robolectric.RobolectricTestRunner; 36 37 @RunWith(RobolectricTestRunner.class) 38 public class GridOptionsManagerTest { 39 40 @Mock LauncherGridOptionsProvider mProvider; 41 @Mock ThemesUserEventLogger mThemesUserEventLogger; 42 private GridOptionsManager mManager; 43 44 @Before setUp()45 public void setUp() { 46 MockitoAnnotations.initMocks(this); 47 mManager = new GridOptionsManager(mProvider, mThemesUserEventLogger); 48 } 49 50 @Test testApply()51 public void testApply() { 52 String gridName = "testName"; 53 GridOption grid = new GridOption("testTitle", gridName, false, 2, 2, null, 1, ""); 54 when(mProvider.applyGrid(gridName)).thenReturn(1); 55 56 mManager.apply(grid, new Callback() { 57 @Override 58 public void onSuccess() { 59 //Nothing to do here, the test passed 60 } 61 62 @Override 63 public void onError(@Nullable Throwable throwable) { 64 fail("onError was called when grid had been applied successfully"); 65 } 66 }); 67 } 68 69 @Test testFetch_backgroundThread()70 public void testFetch_backgroundThread() { 71 mManager.fetchOptions(null, false); 72 Robolectric.flushBackgroundThreadScheduler(); 73 verify(mProvider).fetch(anyBoolean()); 74 } 75 } 76