1 package com.farmerbb.taskbar.ui;
3 import android.content.Context;
4 import android.content.SharedPreferences;
6 import androidx.test.core.app.ApplicationProvider;
8 import com.farmerbb.taskbar.util.TaskbarPosition;
9 import com.farmerbb.taskbar.util.U;
11 import org.junit.After;
12 import org.junit.Before;
13 import org.junit.Rule;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.powermock.core.classloader.annotations.PowerMockIgnore;
17 import org.powermock.core.classloader.annotations.PrepareForTest;
18 import org.powermock.modules.junit4.rule.PowerMockRule;
19 import org.robolectric.RobolectricTestRunner;
21 import static com.farmerbb.taskbar.util.Constants.PREF_SHOW_SEARCH_BAR;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
25 @RunWith(RobolectricTestRunner.class)
26 @PowerMockIgnore({"org.mockito.*", "org.robolectric.*",
27 "android.*", "androidx.*", "com.farmerbb.taskbar.shadow.*"})
28 @PrepareForTest(value = {U.class, TaskbarPosition.class})
29 public class StartMenuControllerTest {
30 private static final String UNSUPPORTED = "unsupported";
33 public PowerMockRule rule = new PowerMockRule();
35 private StartMenuController uiController;
36 private Context context;
37 private SharedPreferences prefs;
38 private UIHost host = new MockUIHost();
42 context = ApplicationProvider.getApplicationContext();
43 uiController = new StartMenuController(context);
44 prefs = U.getSharedPreferences(context);
46 uiController.onCreateHost(host);
50 public void tearDown() {
51 prefs.edit().remove(PREF_SHOW_SEARCH_BAR).apply();
52 uiController.onDestroyHost(host);
56 public void testShouldShowSearchBox() {
57 prefs.edit().remove(PREF_SHOW_SEARCH_BAR).apply();
58 assertTrue(uiController.shouldShowSearchBox(prefs, false));
60 prefs.edit().putString(PREF_SHOW_SEARCH_BAR, "always").apply();
61 assertTrue(uiController.shouldShowSearchBox(prefs, false));
63 prefs.edit().putString(PREF_SHOW_SEARCH_BAR, "keyboard").apply();
64 assertFalse(uiController.shouldShowSearchBox(prefs, false));
65 assertTrue(uiController.shouldShowSearchBox(prefs, true));
67 prefs.edit().putString(PREF_SHOW_SEARCH_BAR, "never").apply();
68 assertFalse(uiController.shouldShowSearchBox(prefs, true));
70 prefs.edit().putString(PREF_SHOW_SEARCH_BAR, UNSUPPORTED).apply();
71 assertFalse(uiController.shouldShowSearchBox(prefs, true));