123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- /*
- * Copyright (c) 2006-2013 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.config.prefs;
-
- import com.dmdirc.actions.ActionManager;
- import com.dmdirc.actions.CoreActionType;
- import com.dmdirc.config.ConfigManager;
- import com.dmdirc.interfaces.ActionListener;
- import com.dmdirc.plugins.PluginManager;
- import com.dmdirc.plugins.Service;
-
- import java.util.ArrayList;
- import java.util.List;
-
- import org.junit.Before;
- import org.junit.Test;
-
- import static org.junit.Assert.*;
- import static org.mockito.Mockito.*;
-
- public class PreferencesDialogModelTest {
-
- private ActionManager actionManager;
- private PluginManager pluginManager;
-
- @Before
- public void setup() {
- actionManager = mock(ActionManager.class);
- pluginManager = mock(PluginManager.class);
-
- final List<Service> services = new ArrayList<Service>();
- final Service tabcompleter = mock(Service.class);
- when(tabcompleter.getName()).thenReturn("tabber");
- services.add(tabcompleter);
-
- when(pluginManager.getServicesByType("tabcompletion")).thenReturn(services);
- }
-
- @Test
- public void testDefaults() {
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- assertNotNull(pm.getCategory("General"));
- assertNotNull(pm.getCategory("Connection"));
- assertNotNull(pm.getCategory("Messages"));
- assertNotNull(pm.getCategory("Advanced"));
- assertNotNull(pm.getCategory("GUI"));
- assertNotNull(pm.getCategory("Plugins"));
- assertNotNull(pm.getCategory("Updates"));
- assertNotNull(pm.getCategory("URL Handlers"));
- }
-
- @Test
- public void testDismiss() {
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
- final PreferencesCategory category = mock(PreferencesCategory.class);
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- pm.addCategory(category);
- pm.dismiss();
-
- verify(category).dismiss();
- }
-
- @Test
- public void testSaveNoRestart() {
- final PreferencesCategory category = mock(PreferencesCategory.class);
- when(category.save()).thenReturn(false);
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
-
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- pm.addCategory(category);
- assertFalse(pm.save());
-
- verify(category).save();
- }
-
- @Test
- public void testSaveRestart() {
- final PreferencesCategory category = mock(PreferencesCategory.class);
- when(category.save()).thenReturn(true);
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
-
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- pm.addCategory(category);
- assertTrue(pm.save());
-
- verify(category).save();
- }
-
- @Test
- public void testGetCategory() {
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
-
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- assertNull(pm.getCategory("unittest123"));
- }
-
- @Test
- public void testGetCategories() {
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
-
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- assertNotNull(pm.getCategories());
- assertFalse(pm.getCategories().isEmpty());
-
- for (PreferencesCategory cat : pm.getCategories()) {
- assertNotNull(pm.getCategory(cat.getTitle()));
- }
- }
-
- @Test
- public void testSaveListener() {
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
-
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- final PreferencesInterface tpi = mock(PreferencesInterface.class);
-
- pm.registerSaveListener(tpi);
- pm.fireSaveListeners();
- verify(tpi).save();
- }
-
- @Test
- public void testOpenAction() {
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
-
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
-
- verify(actionManager).triggerEvent(CoreActionType.CLIENT_PREFS_OPENED, null, pm);
- }
-
- @Test
- public void testCloseAction() {
- final ActionListener tal = mock(ActionListener.class);
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- pm.close();
-
- verify(actionManager).triggerEvent(CoreActionType.CLIENT_PREFS_CLOSED, null);
- }
-
- @Test
- public void testCategoryObjectSaveListeners() {
- ConfigManager cm = mock(ConfigManager.class);
- when(cm.getOption("domain", "option")).thenReturn("fallback");
-
- final PreferencesDialogModel pm = new PreferencesDialogModel(null, null,
- null, null, cm, null, actionManager, pluginManager);
- final PreferencesCategory category = mock(PreferencesCategory.class);
- final PreferencesInterface tpi = mock(PreferencesInterface.class);
- when(category.hasObject()).thenReturn(true);
- when(category.getObject()).thenReturn(tpi);
-
- pm.addCategory(category);
- pm.fireSaveListeners();
- verify(tpi).save();
- }
-
- }
|