123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755 |
- /*
- * Copyright (c) 2006-2014 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.addons.ui_swing.dialogs.profiles;
-
- import com.dmdirc.interfaces.config.ConfigProvider;
- import com.dmdirc.interfaces.config.IdentityController;
- import com.dmdirc.interfaces.config.IdentityFactory;
-
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.List;
-
- import org.junit.Before;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.mockito.Mock;
- import org.mockito.runners.MockitoJUnitRunner;
-
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertFalse;
- import static org.junit.Assert.assertNotSame;
- import static org.junit.Assert.assertNull;
- import static org.junit.Assert.assertTrue;
- import static org.mockito.Mockito.mock;
- import static org.mockito.Mockito.verify;
- import static org.mockito.Mockito.when;
-
- /**
- * Test for ProfileManagerModel
- */
- @RunWith(MockitoJUnitRunner.class)
- public class ProfileManagerModelTest {
-
- @Mock private IdentityController manager;
- @Mock private IdentityFactory identityFactory;
-
- private Profile defaultProfile;
-
- private Profile createProfile(final String prefix) {
- final List<String> nicknames = new ArrayList<>();
- nicknames.add(prefix + "nickname");
-
- final ConfigProvider configProvider = mock(ConfigProvider.class);
- when(configProvider.getName()).thenReturn(prefix + "profile");
- when(configProvider.getOption("identity", "name")).thenReturn(prefix + "profile");
- when(configProvider.getOptionList("profile", "nicknames")).thenReturn(nicknames);
- when(configProvider.getOption("profile", "realname")).thenReturn(prefix + "realname");
- when(configProvider.getOption("profile", "ident")).thenReturn(prefix + "ident");
-
- final Profile profile = new Profile(identityFactory, configProvider);
- return profile;
- }
-
- private ProfileManagerModel createModel() {
- defaultProfile = createProfile("1");
- final ProfileManagerModel model = new ProfileManagerModel(manager, identityFactory);
- model.addProfile(defaultProfile);
- return model;
- }
-
- @Before
- public void setup() throws Exception {
- final List<ConfigProvider> identities = Collections.emptyList();
- manager = mock(IdentityController.class);
- when(manager.getProvidersByType("profile")).thenReturn(identities);
- }
-
- /**
- * Test creating profiles from identities.
- */
- @Test
- public void testLoad() {
- final List<String> nicknames = new ArrayList<>();
- nicknames.add("nickname");
- final ConfigProvider configProvider = mock(ConfigProvider.class);
- when(configProvider.getName()).thenReturn("profile");
- when(configProvider.getOption("identity", "name")).thenReturn("profile");
- when(configProvider.getOptionList("profile", "nicknames")).thenReturn(nicknames);
- when(configProvider.getOption("profile", "realname")).thenReturn("realname");
- when(configProvider.getOption("profile", "ident")).thenReturn("ident");
- final List<ConfigProvider> identities = new ArrayList<>();
- identities.add(configProvider);
- final IdentityController im = mock(IdentityController.class);
- when(im.getProvidersByType("profile")).thenReturn(identities);
-
- ProfileManagerModel instance = new ProfileManagerModel(im, identityFactory);
- instance.load();
-
- assertEquals(Arrays.asList(new Profile[]{new Profile(identityFactory, configProvider), }), instance.getProfiles());
- }
-
- /**
- * Test of setProfiles method, of class ProfileManagerModel.
- */
- @Test
- public void testGetAndSetProfiles() {
- final List<Profile> newProfiles = Arrays.asList(
- new Profile[]{createProfile("2"),});
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertEquals(Collections.emptyList(), instance.getProfiles());
- instance.setProfiles(newProfiles);
- assertEquals(newProfiles, instance.getProfiles());
- }
-
- /**
- * Test of addProfiles method, of class ProfileManagerModel.
- */
- @Test
- public void testAddProfiles() {
- final Profile newProfile = createProfile("2");
- ProfileManagerModel instance = createModel();
- assertEquals(Arrays.asList(new Profile[]{defaultProfile,}), instance.getProfiles());
- final List<Profile> newProfiles = new ArrayList<>();
- newProfiles.add(defaultProfile);
- newProfiles.add(newProfile);
- instance.addProfile(newProfile);
- assertEquals(newProfiles, instance.getProfiles());
- }
-
- /**
- * Test deleting a null profile.
- */
- @Test
- public void testDeleteProfileNullProfile() {
- final Profile first = createProfile("1");
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(first);
- instance.setSelectedProfile(first);
- assertEquals(first, instance.getSelectedProfile());
- instance.deleteProfile(null);
- assertEquals(first, instance.getSelectedProfile());
- }
-
- /**
- * Test selected profile behaviour upon deleting profiles.
- */
- @Test
- public void testDeleteProfileNotSelected() {
- final Profile first = createProfile("1");
- final Profile second = createProfile("2");
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(first);
- instance.addProfile(second);
- instance.setSelectedProfile(second);
- assertEquals(second, instance.getSelectedProfile());
- instance.deleteProfile(first);
- assertEquals(second, instance.getSelectedProfile());
- }
-
- /**
- * Test selected profile behaviour upon deleting profiles.
- */
- @Test
- public void testDeleteProfileLastProfile() {
- final Profile first = createProfile("1");
- final Profile second = createProfile("2");
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(first);
- instance.addProfile(second);
- instance.setSelectedProfile(second);
- assertEquals(second, instance.getSelectedProfile());
- instance.deleteProfile(second);
- assertEquals(first, instance.getSelectedProfile());
- }
-
- /**
- * Test selected profile behaviour upon deleting profiles.
- */
- @Test
- public void testDeleteProfileFirstProfile() {
- final Profile first = createProfile("1");
- final Profile second = createProfile("2");
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(first);
- instance.addProfile(second);
- instance.setSelectedProfile(first);
- assertEquals(first, instance.getSelectedProfile());
- instance.deleteProfile(first);
- assertEquals(second, instance.getSelectedProfile());
- }
-
- /**
- * Test selected profile behaviour upon deleting profiles.
- */
- @Test
- public void testDeleteProfileMiddleProfile() {
- final Profile first = createProfile("1");
- final Profile second = createProfile("2");
- final Profile third = createProfile("3");
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(first);
- instance.addProfile(second);
- instance.addProfile(third);
- instance.setSelectedProfile(second);
- assertEquals(second, instance.getSelectedProfile());
- instance.deleteProfile(second);
- assertEquals(first, instance.getSelectedProfile());
- }
-
- /**
- * Test deleting a null profile.
- */
- @Test
- public void testDeleteProfileOnlyProfile() {
- final Profile first = createProfile("1");
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(first);
- instance.setSelectedProfile(first);
- assertEquals(first, instance.getSelectedProfile());
- instance.deleteProfile(first);
- assertNull(instance.getSelectedProfile());
- }
-
- /**
- * Test of setSelectedProfile method, of class ProfileManagerModel.
- */
- @Test
- public void testGetAndSetSelectedProfile() {
- Profile profile2 = createProfile("2");
- Profile profile3 = createProfile("3");
- Profile profile4 = createProfile("4");
- ProfileManagerModel instance = createModel();
- assertEquals(defaultProfile, instance.getSelectedProfile());
- instance.addProfile(profile2);
- assertEquals(profile2, instance.getSelectedProfile());
- instance.addProfile(profile3);
- instance.setSelectedProfile(profile2);
- assertEquals(profile2, instance.getSelectedProfile());
- instance.setSelectedProfile(profile4);
- assertNotSame(profile4, instance.getSelectedProfile());
- }
-
- /**
- * Test of getNicknames method, of class ProfileManagerModel.
- */
- @Test
- public void testGetAndSetNicknames() {
- ProfileManagerModel instance = createModel();
- final List<String> expResult = defaultProfile.getNicknames();
- List<String> result = instance.getNicknames();
- assertEquals(expResult, result);
- result = Arrays.asList(new String[]{"foo", "bar",});
- instance.setNicknames(result);
- assertEquals(result, instance.getNicknames());
- }
-
- /**
- * Test of addNickname method, of class ProfileManagerModel.
- */
- @Test
- public void testAddNickname() {
- String nickname = "foo";
- ProfileManagerModel instance = createModel();
- assertEquals(defaultProfile.getNicknames(), instance.getNicknames());
- final List<String> nicknames = new ArrayList<>(defaultProfile.getNicknames());
- instance.addNickname(nickname);
- nicknames.add(nickname);
- assertEquals(nicknames, instance.getNicknames());
- }
-
- /**
- * Test of deleteNickname method, of class ProfileManagerModel.
- */
- @Test
- public void testDeleteNicknameObject() {
- ProfileManagerModel instance = createModel();
- final List<String> nicknames = new ArrayList<>(instance.getNicknames());
- Object nickname = (Object) "";
- assertEquals(nicknames, instance.getNicknames());
- instance.deleteNickname(nickname);
- assertEquals(nicknames, instance.getNicknames());
- nickname = new Object();
- assertEquals(nicknames, instance.getNicknames());
- instance.deleteNickname(nickname);
- assertEquals(nicknames, instance.getNicknames());
- }
-
- /**
- * Test selected nickname behaviour upon deleting nickname.
- */
- @Test
- public void testDeleteNicknameNullSelectedProfile() {
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertNull(instance.getSelectedProfile());
- assertTrue(instance.getNicknames().isEmpty());
- instance.deleteNickname("1nickname");
- }
-
- /**
- * Test selected nickname behaviour upon deleting nickname.
- */
- @Test
- public void testDeleteNicknameNullNickname() {
- final Profile profile = createProfile("1");
- final String first = "1nickname";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(profile);
- instance.setSelectedProfile(profile);
- instance.setSelectedNickname(first);
- assertEquals(first, instance.getSelectedNickname());
- instance.deleteNickname(null);
- assertEquals(first, instance.getSelectedNickname());
- }
-
- /**
- * Test selected nickname behaviour upon deleting nickname.
- */
- @Test
- public void testDeleteNicknameNotSelected() {
- final Profile profile = createProfile("1");
- final String first = "1nickname";
- final String second = "1nickname2";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(profile);
- instance.setSelectedProfile(profile);
- instance.addNickname(second);
- instance.setSelectedNickname(second);
- assertEquals(second, instance.getSelectedNickname());
- instance.deleteNickname(first);
- assertEquals(second, instance.getSelectedNickname());
- }
-
- /**
- * Test selected nickname behaviour upon deleting nickname.
- */
- @Test
- public void testDeleteNicknameLastNickname() {
- final Profile profile = createProfile("1");
- final String first = "1nickname";
- final String second = "1nickname2";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(profile);
- instance.setSelectedProfile(profile);
- instance.addNickname(second);
- instance.setSelectedNickname(second);
- assertEquals(second, instance.getSelectedNickname());
- instance.deleteNickname(second);
- assertEquals(first, instance.getSelectedNickname());
- }
-
- /**
- * Test selected nickname behaviour upon deleting nickname.
- */
- @Test
- public void testDeleteNicknameFirstNickname() {
- final Profile profile = createProfile("1");
- final String first = "1nickname";
- final String second = "1nickname2";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(profile);
- instance.setSelectedProfile(profile);
- instance.addNickname(second);
- instance.setSelectedNickname(first);
- assertEquals(first, instance.getSelectedNickname());
- instance.deleteNickname(first);
- assertEquals(second, instance.getSelectedNickname());
- }
-
- /**
- * Test selected nickname behaviour upon deleting nickname.
- */
- @Test
- public void testDeleteNicknameMiddleNickname() {
- final Profile profile = createProfile("1");
- final String first = "1nickname";
- final String second = "1nickname2";
- final String third = "1nickname3";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(profile);
- instance.setSelectedProfile(profile);
- instance.addNickname(second);
- instance.addNickname(third);
- instance.setSelectedNickname(second);
- assertEquals(second, instance.getSelectedNickname());
- instance.deleteNickname(second);
- assertEquals(first, instance.getSelectedNickname());
- }
-
- /**
- * Test selected nickname behaviour upon deleting nickname.
- */
- @Test
- public void testDeleteNicknameOnlyNickname() {
- final Profile profile = createProfile("1");
- final String first = "1nickname";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.addProfile(profile);
- instance.setSelectedProfile(profile);
- instance.setSelectedNickname(first);
- assertEquals(first, instance.getSelectedNickname());
- instance.deleteNickname(first);
- assertNull(instance.getSelectedNickname());
- }
-
- /**
- * Test of setSelectedNickname method, of class ProfileManagerModel.
- */
- @Test
- public void testGetAndSetSelectedNickname() {
- final String selectedNickname = "1nickname";
- ProfileManagerModel instance = createModel();
- assertNull(instance.getSelectedNickname());
- instance.setSelectedNickname(selectedNickname);
- assertEquals(selectedNickname, instance.getSelectedNickname());
- instance.setSelectedNickname("foo");
- assertNotSame("foo", instance.getSelectedNickname());
- }
-
- /**
- * Test of editNickname method, of class ProfileManagerModel.
- */
- @Test
- public void testEditNickname() {
- ProfileManagerModel instance = createModel();
- final List<String> nicknames = new ArrayList<>(instance.getNicknames());
- final String nickname = nicknames.get(0);
- assertEquals(nicknames, instance.getNicknames());
- instance.editNickname(nickname, "foo");
- final int index = nicknames.indexOf(nickname);
- nicknames.remove(nickname);
- nicknames.add(index, "foo");
- assertEquals(nicknames, instance.getNicknames());
- }
-
- /**
- * Test of getName method, of class ProfileManagerModel.
- */
- @Test
- public void testGetAndSetName() {
- ProfileManagerModel instance = createModel();
- final String name = defaultProfile.getName();
- final String newName = "foo";
- assertEquals(name, instance.getName());
- instance.setName(newName);
- assertEquals(newName, ((Profile) instance.getSelectedProfile()).getName());
- }
-
- /**
- * Test of getRealname method, of class ProfileManagerModel.
- */
- @Test
- public void testGetAndSetRealname() {
- ProfileManagerModel instance = createModel();
- final String name = "1realname";
- final String newName = "foo";
- assertEquals(name, instance.getRealname());
- instance.setRealname(newName);
- assertEquals(newName, ((Profile) instance.getSelectedProfile()).getRealname());
- }
-
- /**
- * Test of getIdent method, of class ProfileManagerModel.
- */
- @Test
- public void testGetAndSetIdent() {
- ProfileManagerModel instance = createModel();
- final String name = "1ident";
- final String newName = "foo";
- assertEquals(name, instance.getIdent());
- instance.setIdent(newName);
- assertEquals(newName, ((Profile) instance.getSelectedProfile()).getIdent());
- }
-
- /**
- * Test of isManipulateProfileAllowed method, of class ProfileManagerModel.
- */
- @Test
- public void testIsManipulateProfileAllowed() {
- ProfileManagerModel instance = createModel();
- assertTrue(instance.isManipulateProfileAllowed());
- instance.setProfiles(Arrays.asList(new Profile[]{}));
- assertFalse(instance.isManipulateProfileAllowed());
- }
-
- /**
- * Test of isManipulateNicknameAllowed method, of class ProfileManagerModel.
- */
- @Test
- public void testIsManipulateNicknameAllowed() {
- ProfileManagerModel instance = createModel();
- assertFalse(instance.isManipulateNicknameAllowed());
- instance.setSelectedNickname("1nickname");
- assertTrue(instance.isManipulateNicknameAllowed());
- }
-
- /**
- * Test of isOKAllowed method, of class ProfileManagerModel.
- */
- @Test
- public void testIsOKAllowed() {
- final Profile profile = new Profile("New Profile", null);
- profile.setName("*");
- profile.setRealname("");
- profile.setIdent("*");
- ProfileManagerModel instance = createModel();
- assertTrue(instance.isOKAllowed());
- instance.setProfiles(Arrays.asList(new Profile[]{}));
- assertFalse(instance.isOKAllowed());
- instance.setProfiles(Arrays.asList(new Profile[]{profile,}));
- assertFalse(instance.isOKAllowed());
- profile.setName("profile");
- assertFalse(instance.isOKAllowed());
- profile.addNickname("nickname");
- assertFalse(instance.isOKAllowed());
- profile.setRealname("realname");
- assertFalse(instance.isOKAllowed());
- profile.setIdent("ident");
- assertTrue(instance.isOKAllowed());
- }
-
- /**
- * Test of isNameValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsNameInValid() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setName("\\");
- assertTrue(instance.isNameValid().isFailure());
- }
-
- /**
- * Test of isNameValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsNameValid() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setName("profile");
- assertFalse(instance.isNameValid().isFailure());
- }
-
- /**
- * Test of isNicknamesValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsNicknamesInValid() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setNicknames(Arrays.asList(new String[]{}));
- assertTrue(instance.isNicknamesValid().isFailure());
- }
-
- /**
- * Test of isNicknamesValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsNicknamesValid() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setNicknames(Arrays.asList(new String[]{"nickname"}));
- assertFalse(instance.isNicknamesValid().isFailure());
- }
-
- /**
- * Test of isRealnameValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsRealnameInValid() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setRealname("");
- assertTrue(instance.isRealnameValid().isFailure());
- }
-
- /**
- * Test of isRealnameValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsRealnameValid() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setRealname("realname");
- assertFalse(instance.isRealnameValid().isFailure());
- }
-
- /**
- * Test of isIdentValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsIdentInValid() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setIdent("*");
- assertTrue(instance.isIdentValid().isFailure());
- }
-
- /**
- * Test of isIdentValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsIdentValid() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setIdent("ident");
- assertFalse(instance.isIdentValid().isFailure());
- }
-
- /**
- * Test of isIdentValid method, of class ProfileManagerModel.
- */
- @Test
- public void testIsIdentValidEmptyString() {
- ProfileManagerModel instance = createModel();
- instance.setProfiles(Arrays.asList(defaultProfile));
- instance.setIdent("");
- assertFalse(instance.isIdentValid().isFailure());
- }
-
- /**
- * Test getters without selected profiles.
- */
- @Test
- public void testNullSelectedProfileGetters() {
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertTrue("".equals(instance.getSelectedNickname()));
- assertTrue("".equals(instance.getName()));
- assertTrue("".equals(instance.getRealname()));
- assertTrue("".equals(instance.getIdent()));
- assertTrue(instance.getNicknames().isEmpty());
- }
-
- /**
- * Test validators without selected profiles.
- */
- @Test
- public void testNullSelectedProfileValidators() {
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertFalse(instance.isNameValid().isFailure());
- assertFalse(instance.isNicknamesValid().isFailure());
- assertFalse(instance.isRealnameValid().isFailure());
- assertFalse(instance.isIdentValid().isFailure());
- }
-
- /**
- * Test setters without selected profiles.
- */
- @Test
- public void testNullSelectedProfileSetSelectedNickname() {
- final String test = "test";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertTrue("".equals(instance.getSelectedNickname()));
- instance.setSelectedNickname(test);
- assertTrue("".equals(instance.getSelectedNickname()));
- }
-
- /**
- * Test setters without selected profiles.
- */
- @Test
- public void testNullSelectedProfileSetName() {
- final String test = "test";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertTrue("".equals(instance.getName()));
- instance.setName(test);
- assertTrue("".equals(instance.getName()));
- }
-
- /**
- * Test setters without selected profiles.
- */
- @Test
- public void testNullSelectedProfileSetRealname() {
- final String test = "test";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertTrue("".equals(instance.getRealname()));
- instance.setRealname(test);
- assertTrue("".equals(instance.getRealname()));
- }
-
- /**
- * Test setters without selected profiles.
- */
- @Test
- public void testNullSelectedProfileSetIdent() {
- final String test = "test";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertTrue("".equals(instance.getIdent()));
- instance.setIdent(test);
- assertTrue("".equals(instance.getIdent()));
- }
-
- /**
- * Test setters without selected profiles.
- */
- @Test
- public void testNullSelectedProfileSetNicknames() {
- final String test = "test";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertTrue(instance.getNicknames().isEmpty());
- instance.setNicknames(Arrays.asList(new String[]{test, }));
- assertTrue(instance.getNicknames().isEmpty());
- }
-
- /**
- * Test setters without selected profiles.
- */
- @Test
- public void testNullSelectedProfileAddNickname() {
- final String test = "test";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertTrue(instance.getNicknames().isEmpty());
- instance.addNickname(test);
- assertTrue(instance.getNicknames().isEmpty());
- }
-
- /**
- * Test setters without selected profiles.
- */
- @Test
- public void testNullSelectedProfileDeleteNickname() {
- final String test = "test";
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- assertTrue(instance.getNicknames().isEmpty());
- instance.deleteNickname(test);
- assertTrue(instance.getNicknames().isEmpty());
- }
-
- /**
- * Test method save of class ProfileManagerModel
- */
- @Test
- public void save() {
- final Profile first = mock(Profile.class);
- final Profile second = mock(Profile.class);
- when(first.isDeleted()).thenReturn(false);
- when(second.isDeleted()).thenReturn(true);
- ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
- instance.setProfiles(Arrays.asList(new Profile[]{first, second, }));
- instance.save();
- verify(first).save();
- verify(second).delete();
- }
- }
|