Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ProfileManagerModelTest.java 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.dialogs.profiles;
  23. import com.dmdirc.actions.wrappers.Profile;
  24. import com.dmdirc.interfaces.config.ConfigProvider;
  25. import com.dmdirc.interfaces.config.IdentityController;
  26. import com.dmdirc.interfaces.config.IdentityFactory;
  27. import java.io.IOException;
  28. import java.util.ArrayList;
  29. import java.util.Arrays;
  30. import java.util.Collections;
  31. import java.util.List;
  32. import org.junit.Before;
  33. import org.junit.Test;
  34. import org.junit.runner.RunWith;
  35. import org.mockito.Mock;
  36. import org.mockito.runners.MockitoJUnitRunner;
  37. import static org.junit.Assert.assertEquals;
  38. import static org.junit.Assert.assertFalse;
  39. import static org.junit.Assert.assertNotSame;
  40. import static org.junit.Assert.assertNull;
  41. import static org.junit.Assert.assertTrue;
  42. import static org.mockito.Mockito.mock;
  43. import static org.mockito.Mockito.verify;
  44. import static org.mockito.Mockito.when;
  45. /**
  46. * Test for ProfileManagerModel
  47. */
  48. @RunWith(MockitoJUnitRunner.class)
  49. public class ProfileManagerModelTest {
  50. @Mock private IdentityController manager;
  51. @Mock private IdentityFactory identityFactory;
  52. private Profile defaultProfile;
  53. private Profile createProfile(final String prefix) {
  54. final List<String> nicknames = new ArrayList<>();
  55. nicknames.add(prefix + "nickname");
  56. final ConfigProvider configProvider = mock(ConfigProvider.class);
  57. when(configProvider.getName()).thenReturn(prefix + "profile");
  58. when(configProvider.getOption("identity", "name")).thenReturn(prefix + "profile");
  59. when(configProvider.getOptionList("profile", "nicknames")).thenReturn(nicknames);
  60. when(configProvider.getOption("profile", "realname")).thenReturn(prefix + "realname");
  61. when(configProvider.getOption("profile", "ident")).thenReturn(prefix + "ident");
  62. return new Profile(identityFactory, configProvider);
  63. }
  64. private ProfileManagerModel createModel() {
  65. defaultProfile = createProfile("1");
  66. final ProfileManagerModel model = new ProfileManagerModel(manager, identityFactory);
  67. model.addProfile(defaultProfile);
  68. return model;
  69. }
  70. @Before
  71. public void setup() {
  72. final List<ConfigProvider> identities = Collections.emptyList();
  73. manager = mock(IdentityController.class);
  74. when(manager.getProvidersByType("profile")).thenReturn(identities);
  75. }
  76. /**
  77. * Test creating profiles from identities.
  78. */
  79. @Test
  80. public void testLoad() {
  81. final List<String> nicknames = new ArrayList<>();
  82. nicknames.add("nickname");
  83. final ConfigProvider configProvider = mock(ConfigProvider.class);
  84. when(configProvider.getName()).thenReturn("profile");
  85. when(configProvider.getOption("identity", "name")).thenReturn("profile");
  86. when(configProvider.getOptionList("profile", "nicknames")).thenReturn(nicknames);
  87. when(configProvider.getOption("profile", "realname")).thenReturn("realname");
  88. when(configProvider.getOption("profile", "ident")).thenReturn("ident");
  89. final List<ConfigProvider> identities = new ArrayList<>();
  90. identities.add(configProvider);
  91. final IdentityController im = mock(IdentityController.class);
  92. when(im.getProvidersByType("profile")).thenReturn(identities);
  93. final ProfileManagerModel instance = new ProfileManagerModel(im, identityFactory);
  94. instance.load();
  95. assertEquals(Arrays.asList(new Profile[]{new Profile(identityFactory, configProvider), }), instance.getProfiles());
  96. }
  97. /**
  98. * Test of setProfiles method, of class ProfileManagerModel.
  99. */
  100. @Test
  101. public void testGetAndSetProfiles() {
  102. final List<Profile> newProfiles = Arrays.asList(
  103. new Profile[]{createProfile("2"),});
  104. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  105. assertEquals(Collections.emptyList(), instance.getProfiles());
  106. instance.setProfiles(newProfiles);
  107. assertEquals(newProfiles, instance.getProfiles());
  108. }
  109. /**
  110. * Test of addProfiles method, of class ProfileManagerModel.
  111. */
  112. @Test
  113. public void testAddProfiles() {
  114. final Profile newProfile = createProfile("2");
  115. final ProfileManagerModel instance = createModel();
  116. assertEquals(Arrays.asList(new Profile[]{defaultProfile,}), instance.getProfiles());
  117. final List<Profile> newProfiles = new ArrayList<>();
  118. newProfiles.add(defaultProfile);
  119. newProfiles.add(newProfile);
  120. instance.addProfile(newProfile);
  121. assertEquals(newProfiles, instance.getProfiles());
  122. }
  123. /**
  124. * Test deleting a null profile.
  125. */
  126. @Test
  127. public void testDeleteProfileNullProfile() {
  128. final Profile first = createProfile("1");
  129. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  130. instance.addProfile(first);
  131. instance.setSelectedProfile(first);
  132. assertEquals(first, instance.getSelectedProfile());
  133. instance.deleteProfile(null);
  134. assertEquals(first, instance.getSelectedProfile());
  135. }
  136. /**
  137. * Test selected profile behaviour upon deleting profiles.
  138. */
  139. @Test
  140. public void testDeleteProfileNotSelected() {
  141. final Profile first = createProfile("1");
  142. final Profile second = createProfile("2");
  143. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  144. instance.addProfile(first);
  145. instance.addProfile(second);
  146. instance.setSelectedProfile(second);
  147. assertEquals(second, instance.getSelectedProfile());
  148. instance.deleteProfile(first);
  149. assertEquals(second, instance.getSelectedProfile());
  150. }
  151. /**
  152. * Test selected profile behaviour upon deleting profiles.
  153. */
  154. @Test
  155. public void testDeleteProfileLastProfile() {
  156. final Profile first = createProfile("1");
  157. final Profile second = createProfile("2");
  158. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  159. instance.addProfile(first);
  160. instance.addProfile(second);
  161. instance.setSelectedProfile(second);
  162. assertEquals(second, instance.getSelectedProfile());
  163. instance.deleteProfile(second);
  164. assertEquals(first, instance.getSelectedProfile());
  165. }
  166. /**
  167. * Test selected profile behaviour upon deleting profiles.
  168. */
  169. @Test
  170. public void testDeleteProfileFirstProfile() {
  171. final Profile first = createProfile("1");
  172. final Profile second = createProfile("2");
  173. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  174. instance.addProfile(first);
  175. instance.addProfile(second);
  176. instance.setSelectedProfile(first);
  177. assertEquals(first, instance.getSelectedProfile());
  178. instance.deleteProfile(first);
  179. assertEquals(second, instance.getSelectedProfile());
  180. }
  181. /**
  182. * Test selected profile behaviour upon deleting profiles.
  183. */
  184. @Test
  185. public void testDeleteProfileMiddleProfile() {
  186. final Profile first = createProfile("1");
  187. final Profile second = createProfile("2");
  188. final Profile third = createProfile("3");
  189. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  190. instance.addProfile(first);
  191. instance.addProfile(second);
  192. instance.addProfile(third);
  193. instance.setSelectedProfile(second);
  194. assertEquals(second, instance.getSelectedProfile());
  195. instance.deleteProfile(second);
  196. assertEquals(first, instance.getSelectedProfile());
  197. }
  198. /**
  199. * Test deleting a null profile.
  200. */
  201. @Test
  202. public void testDeleteProfileOnlyProfile() {
  203. final Profile first = createProfile("1");
  204. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  205. instance.addProfile(first);
  206. instance.setSelectedProfile(first);
  207. assertEquals(first, instance.getSelectedProfile());
  208. instance.deleteProfile(first);
  209. assertNull(instance.getSelectedProfile());
  210. }
  211. /**
  212. * Test of setSelectedProfile method, of class ProfileManagerModel.
  213. */
  214. @Test
  215. public void testGetAndSetSelectedProfile() {
  216. final Profile profile2 = createProfile("2");
  217. final Profile profile3 = createProfile("3");
  218. final Profile profile4 = createProfile("4");
  219. final ProfileManagerModel instance = createModel();
  220. assertEquals(defaultProfile, instance.getSelectedProfile());
  221. instance.addProfile(profile2);
  222. assertEquals(profile2, instance.getSelectedProfile());
  223. instance.addProfile(profile3);
  224. instance.setSelectedProfile(profile2);
  225. assertEquals(profile2, instance.getSelectedProfile());
  226. instance.setSelectedProfile(profile4);
  227. assertNotSame(profile4, instance.getSelectedProfile());
  228. }
  229. /**
  230. * Test of getNicknames method, of class ProfileManagerModel.
  231. */
  232. @Test
  233. public void testGetAndSetNicknames() {
  234. final ProfileManagerModel instance = createModel();
  235. final List<String> expResult = defaultProfile.getNicknames();
  236. List<String> result = instance.getNicknames();
  237. assertEquals(expResult, result);
  238. result = Arrays.asList(new String[]{"foo", "bar",});
  239. instance.setNicknames(result);
  240. assertEquals(result, instance.getNicknames());
  241. }
  242. /**
  243. * Test of addNickname method, of class ProfileManagerModel.
  244. */
  245. @Test
  246. public void testAddNickname() {
  247. final String nickname = "foo";
  248. final ProfileManagerModel instance = createModel();
  249. assertEquals(defaultProfile.getNicknames(), instance.getNicknames());
  250. final List<String> nicknames = new ArrayList<>(defaultProfile.getNicknames());
  251. instance.addNickname(nickname);
  252. nicknames.add(nickname);
  253. assertEquals(nicknames, instance.getNicknames());
  254. }
  255. /**
  256. * Test of deleteNickname method, of class ProfileManagerModel.
  257. */
  258. @Test
  259. public void testDeleteNicknameObject() {
  260. final ProfileManagerModel instance = createModel();
  261. final List<String> nicknames = new ArrayList<>(instance.getNicknames());
  262. Object nickname = (Object) "";
  263. assertEquals(nicknames, instance.getNicknames());
  264. instance.deleteNickname(nickname);
  265. assertEquals(nicknames, instance.getNicknames());
  266. nickname = new Object();
  267. assertEquals(nicknames, instance.getNicknames());
  268. instance.deleteNickname(nickname);
  269. assertEquals(nicknames, instance.getNicknames());
  270. }
  271. /**
  272. * Test selected nickname behaviour upon deleting nickname.
  273. */
  274. @Test
  275. public void testDeleteNicknameNullSelectedProfile() {
  276. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  277. assertNull(instance.getSelectedProfile());
  278. assertTrue(instance.getNicknames().isEmpty());
  279. instance.deleteNickname("1nickname");
  280. }
  281. /**
  282. * Test selected nickname behaviour upon deleting nickname.
  283. */
  284. @Test
  285. public void testDeleteNicknameNullNickname() {
  286. final Profile profile = createProfile("1");
  287. final String first = "1nickname";
  288. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  289. instance.addProfile(profile);
  290. instance.setSelectedProfile(profile);
  291. instance.setSelectedNickname(first);
  292. assertEquals(first, instance.getSelectedNickname());
  293. instance.deleteNickname(null);
  294. assertEquals(first, instance.getSelectedNickname());
  295. }
  296. /**
  297. * Test selected nickname behaviour upon deleting nickname.
  298. */
  299. @Test
  300. public void testDeleteNicknameNotSelected() {
  301. final Profile profile = createProfile("1");
  302. final String first = "1nickname";
  303. final String second = "1nickname2";
  304. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  305. instance.addProfile(profile);
  306. instance.setSelectedProfile(profile);
  307. instance.addNickname(second);
  308. instance.setSelectedNickname(second);
  309. assertEquals(second, instance.getSelectedNickname());
  310. instance.deleteNickname(first);
  311. assertEquals(second, instance.getSelectedNickname());
  312. }
  313. /**
  314. * Test selected nickname behaviour upon deleting nickname.
  315. */
  316. @Test
  317. public void testDeleteNicknameLastNickname() {
  318. final Profile profile = createProfile("1");
  319. final String first = "1nickname";
  320. final String second = "1nickname2";
  321. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  322. instance.addProfile(profile);
  323. instance.setSelectedProfile(profile);
  324. instance.addNickname(second);
  325. instance.setSelectedNickname(second);
  326. assertEquals(second, instance.getSelectedNickname());
  327. instance.deleteNickname(second);
  328. assertEquals(first, instance.getSelectedNickname());
  329. }
  330. /**
  331. * Test selected nickname behaviour upon deleting nickname.
  332. */
  333. @Test
  334. public void testDeleteNicknameFirstNickname() {
  335. final Profile profile = createProfile("1");
  336. final String first = "1nickname";
  337. final String second = "1nickname2";
  338. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  339. instance.addProfile(profile);
  340. instance.setSelectedProfile(profile);
  341. instance.addNickname(second);
  342. instance.setSelectedNickname(first);
  343. assertEquals(first, instance.getSelectedNickname());
  344. instance.deleteNickname(first);
  345. assertEquals(second, instance.getSelectedNickname());
  346. }
  347. /**
  348. * Test selected nickname behaviour upon deleting nickname.
  349. */
  350. @Test
  351. public void testDeleteNicknameMiddleNickname() {
  352. final Profile profile = createProfile("1");
  353. final String first = "1nickname";
  354. final String second = "1nickname2";
  355. final String third = "1nickname3";
  356. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  357. instance.addProfile(profile);
  358. instance.setSelectedProfile(profile);
  359. instance.addNickname(second);
  360. instance.addNickname(third);
  361. instance.setSelectedNickname(second);
  362. assertEquals(second, instance.getSelectedNickname());
  363. instance.deleteNickname(second);
  364. assertEquals(first, instance.getSelectedNickname());
  365. }
  366. /**
  367. * Test selected nickname behaviour upon deleting nickname.
  368. */
  369. @Test
  370. public void testDeleteNicknameOnlyNickname() {
  371. final Profile profile = createProfile("1");
  372. final String first = "1nickname";
  373. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  374. instance.addProfile(profile);
  375. instance.setSelectedProfile(profile);
  376. instance.setSelectedNickname(first);
  377. assertEquals(first, instance.getSelectedNickname());
  378. instance.deleteNickname(first);
  379. assertNull(instance.getSelectedNickname());
  380. }
  381. /**
  382. * Test of setSelectedNickname method, of class ProfileManagerModel.
  383. */
  384. @Test
  385. public void testGetAndSetSelectedNickname() {
  386. final String selectedNickname = "1nickname";
  387. final ProfileManagerModel instance = createModel();
  388. assertNull(instance.getSelectedNickname());
  389. instance.setSelectedNickname(selectedNickname);
  390. assertEquals(selectedNickname, instance.getSelectedNickname());
  391. instance.setSelectedNickname("foo");
  392. assertNotSame("foo", instance.getSelectedNickname());
  393. }
  394. /**
  395. * Test of editNickname method, of class ProfileManagerModel.
  396. */
  397. @Test
  398. public void testEditNickname() {
  399. final ProfileManagerModel instance = createModel();
  400. final List<String> nicknames = new ArrayList<>(instance.getNicknames());
  401. final String nickname = nicknames.get(0);
  402. assertEquals(nicknames, instance.getNicknames());
  403. instance.editNickname(nickname, "foo");
  404. final int index = nicknames.indexOf(nickname);
  405. nicknames.remove(nickname);
  406. nicknames.add(index, "foo");
  407. assertEquals(nicknames, instance.getNicknames());
  408. }
  409. /**
  410. * Test of getName method, of class ProfileManagerModel.
  411. */
  412. @Test
  413. public void testGetAndSetName() {
  414. final ProfileManagerModel instance = createModel();
  415. final String name = defaultProfile.getName();
  416. final String newName = "foo";
  417. assertEquals(name, instance.getName());
  418. instance.setName(newName);
  419. assertEquals(newName, ((Profile) instance.getSelectedProfile()).getName());
  420. }
  421. /**
  422. * Test of getRealname method, of class ProfileManagerModel.
  423. */
  424. @Test
  425. public void testGetAndSetRealname() {
  426. final ProfileManagerModel instance = createModel();
  427. final String name = "1realname";
  428. final String newName = "foo";
  429. assertEquals(name, instance.getRealname());
  430. instance.setRealname(newName);
  431. assertEquals(newName, ((Profile) instance.getSelectedProfile()).getRealname());
  432. }
  433. /**
  434. * Test of getIdent method, of class ProfileManagerModel.
  435. */
  436. @Test
  437. public void testGetAndSetIdent() {
  438. final ProfileManagerModel instance = createModel();
  439. final String name = "1ident";
  440. final String newName = "foo";
  441. assertEquals(name, instance.getIdent());
  442. instance.setIdent(newName);
  443. assertEquals(newName, ((Profile) instance.getSelectedProfile()).getIdent());
  444. }
  445. /**
  446. * Test of isManipulateProfileAllowed method, of class ProfileManagerModel.
  447. */
  448. @Test
  449. public void testIsManipulateProfileAllowed() {
  450. final ProfileManagerModel instance = createModel();
  451. assertTrue(instance.isManipulateProfileAllowed());
  452. instance.setProfiles(Arrays.asList(new Profile[]{}));
  453. assertFalse(instance.isManipulateProfileAllowed());
  454. }
  455. /**
  456. * Test of isManipulateNicknameAllowed method, of class ProfileManagerModel.
  457. */
  458. @Test
  459. public void testIsManipulateNicknameAllowed() {
  460. final ProfileManagerModel instance = createModel();
  461. assertFalse(instance.isManipulateNicknameAllowed());
  462. instance.setSelectedNickname("1nickname");
  463. assertTrue(instance.isManipulateNicknameAllowed());
  464. }
  465. @Test
  466. public void testIsChangeProfileAllowed() {
  467. final Profile profile = new Profile("New Profile", null);
  468. profile.setName("*");
  469. profile.setRealname("");
  470. profile.setIdent("*");
  471. final ProfileManagerModel instance = createModel();
  472. assertTrue(instance.isChangeProfileAllowed());
  473. instance.setProfiles(Arrays.asList(new Profile[]{profile,}));
  474. assertFalse(instance.isChangeProfileAllowed());
  475. profile.setName("profile");
  476. assertFalse(instance.isChangeProfileAllowed());
  477. profile.addNickname("nickname");
  478. assertFalse(instance.isChangeProfileAllowed());
  479. profile.setRealname("realname");
  480. assertFalse(instance.isChangeProfileAllowed());
  481. profile.setIdent("ident");
  482. assertTrue(instance.isChangeProfileAllowed());
  483. }
  484. /**
  485. * Test of isOKAllowed method, of class ProfileManagerModel.
  486. */
  487. @Test
  488. public void testIsOKAllowed() {
  489. final Profile profile = new Profile("New Profile", null);
  490. profile.setName("*");
  491. profile.setRealname("");
  492. profile.setIdent("*");
  493. final ProfileManagerModel instance = createModel();
  494. assertTrue(instance.isOKAllowed());
  495. instance.setProfiles(Arrays.asList(new Profile[]{}));
  496. assertFalse(instance.isOKAllowed());
  497. instance.setProfiles(Arrays.asList(new Profile[]{profile,}));
  498. assertFalse(instance.isOKAllowed());
  499. profile.setName("profile");
  500. assertFalse(instance.isOKAllowed());
  501. profile.addNickname("nickname");
  502. assertFalse(instance.isOKAllowed());
  503. profile.setRealname("realname");
  504. assertFalse(instance.isOKAllowed());
  505. profile.setIdent("ident");
  506. assertTrue(instance.isOKAllowed());
  507. }
  508. /**
  509. * Test of isNameValid method, of class ProfileManagerModel.
  510. */
  511. @Test
  512. public void testIsNameInValid() {
  513. final ProfileManagerModel instance = createModel();
  514. instance.setProfiles(Arrays.asList(defaultProfile));
  515. instance.setName("\\");
  516. assertTrue(instance.isNameValid().isFailure());
  517. }
  518. /**
  519. * Test of isNameValid method, of class ProfileManagerModel.
  520. */
  521. @Test
  522. public void testIsNameValid() {
  523. final ProfileManagerModel instance = createModel();
  524. instance.setProfiles(Arrays.asList(defaultProfile));
  525. instance.setName("profile");
  526. assertFalse(instance.isNameValid().isFailure());
  527. }
  528. /**
  529. * Test of isNicknamesValid method, of class ProfileManagerModel.
  530. */
  531. @Test
  532. public void testIsNicknamesInValid() {
  533. final ProfileManagerModel instance = createModel();
  534. instance.setProfiles(Arrays.asList(defaultProfile));
  535. instance.setNicknames(Arrays.asList(new String[]{}));
  536. assertTrue(instance.isNicknamesValid().isFailure());
  537. }
  538. /**
  539. * Test of isNicknamesValid method, of class ProfileManagerModel.
  540. */
  541. @Test
  542. public void testIsNicknamesValid() {
  543. final ProfileManagerModel instance = createModel();
  544. instance.setProfiles(Arrays.asList(defaultProfile));
  545. instance.setNicknames(Arrays.asList(new String[]{"nickname"}));
  546. assertFalse(instance.isNicknamesValid().isFailure());
  547. }
  548. /**
  549. * Test of isRealnameValid method, of class ProfileManagerModel.
  550. */
  551. @Test
  552. public void testIsRealnameInValid() {
  553. final ProfileManagerModel instance = createModel();
  554. instance.setProfiles(Arrays.asList(defaultProfile));
  555. instance.setRealname("");
  556. assertTrue(instance.isRealnameValid().isFailure());
  557. }
  558. /**
  559. * Test of isRealnameValid method, of class ProfileManagerModel.
  560. */
  561. @Test
  562. public void testIsRealnameValid() {
  563. final ProfileManagerModel instance = createModel();
  564. instance.setProfiles(Arrays.asList(defaultProfile));
  565. instance.setRealname("realname");
  566. assertFalse(instance.isRealnameValid().isFailure());
  567. }
  568. /**
  569. * Test of isIdentValid method, of class ProfileManagerModel.
  570. */
  571. @Test
  572. public void testIsIdentInValid() {
  573. final ProfileManagerModel instance = createModel();
  574. instance.setProfiles(Arrays.asList(defaultProfile));
  575. instance.setIdent("*");
  576. assertTrue(instance.isIdentValid().isFailure());
  577. }
  578. /**
  579. * Test of isIdentValid method, of class ProfileManagerModel.
  580. */
  581. @Test
  582. public void testIsIdentValid() {
  583. final ProfileManagerModel instance = createModel();
  584. instance.setProfiles(Arrays.asList(defaultProfile));
  585. instance.setIdent("ident");
  586. assertFalse(instance.isIdentValid().isFailure());
  587. }
  588. /**
  589. * Test of isIdentValid method, of class ProfileManagerModel.
  590. */
  591. @Test
  592. public void testIsIdentValidEmptyString() {
  593. final ProfileManagerModel instance = createModel();
  594. instance.setProfiles(Arrays.asList(defaultProfile));
  595. instance.setIdent("");
  596. assertFalse(instance.isIdentValid().isFailure());
  597. }
  598. /**
  599. * Test getters without selected profiles.
  600. */
  601. @Test
  602. public void testNullSelectedProfileGetters() {
  603. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  604. assertTrue("".equals(instance.getSelectedNickname()));
  605. assertTrue("".equals(instance.getName()));
  606. assertTrue("".equals(instance.getRealname()));
  607. assertTrue("".equals(instance.getIdent()));
  608. assertTrue(instance.getNicknames().isEmpty());
  609. }
  610. /**
  611. * Test validators without selected profiles.
  612. */
  613. @Test
  614. public void testNullSelectedProfileValidators() {
  615. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  616. assertFalse(instance.isNameValid().isFailure());
  617. assertFalse(instance.isNicknamesValid().isFailure());
  618. assertFalse(instance.isRealnameValid().isFailure());
  619. assertFalse(instance.isIdentValid().isFailure());
  620. }
  621. /**
  622. * Test setters without selected profiles.
  623. */
  624. @Test
  625. public void testNullSelectedProfileSetSelectedNickname() {
  626. final String test = "test";
  627. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  628. assertTrue("".equals(instance.getSelectedNickname()));
  629. instance.setSelectedNickname(test);
  630. assertTrue("".equals(instance.getSelectedNickname()));
  631. }
  632. /**
  633. * Test setters without selected profiles.
  634. */
  635. @Test
  636. public void testNullSelectedProfileSetName() {
  637. final String test = "test";
  638. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  639. assertTrue("".equals(instance.getName()));
  640. instance.setName(test);
  641. assertTrue("".equals(instance.getName()));
  642. }
  643. /**
  644. * Test setters without selected profiles.
  645. */
  646. @Test
  647. public void testNullSelectedProfileSetRealname() {
  648. final String test = "test";
  649. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  650. assertTrue("".equals(instance.getRealname()));
  651. instance.setRealname(test);
  652. assertTrue("".equals(instance.getRealname()));
  653. }
  654. /**
  655. * Test setters without selected profiles.
  656. */
  657. @Test
  658. public void testNullSelectedProfileSetIdent() {
  659. final String test = "test";
  660. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  661. assertTrue("".equals(instance.getIdent()));
  662. instance.setIdent(test);
  663. assertTrue("".equals(instance.getIdent()));
  664. }
  665. /**
  666. * Test setters without selected profiles.
  667. */
  668. @Test
  669. public void testNullSelectedProfileSetNicknames() {
  670. final String test = "test";
  671. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  672. assertTrue(instance.getNicknames().isEmpty());
  673. instance.setNicknames(Arrays.asList(new String[]{test, }));
  674. assertTrue(instance.getNicknames().isEmpty());
  675. }
  676. /**
  677. * Test setters without selected profiles.
  678. */
  679. @Test
  680. public void testNullSelectedProfileAddNickname() {
  681. final String test = "test";
  682. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  683. assertTrue(instance.getNicknames().isEmpty());
  684. instance.addNickname(test);
  685. assertTrue(instance.getNicknames().isEmpty());
  686. }
  687. /**
  688. * Test setters without selected profiles.
  689. */
  690. @Test
  691. public void testNullSelectedProfileDeleteNickname() {
  692. final String test = "test";
  693. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  694. assertTrue(instance.getNicknames().isEmpty());
  695. instance.deleteNickname(test);
  696. assertTrue(instance.getNicknames().isEmpty());
  697. }
  698. /**
  699. * Test method save of class ProfileManagerModel
  700. *
  701. * @throws IOException
  702. */
  703. @Test
  704. public void save() throws IOException {
  705. final Profile first = mock(Profile.class);
  706. final Profile second = mock(Profile.class);
  707. when(first.isDeleted()).thenReturn(false);
  708. when(second.isDeleted()).thenReturn(true);
  709. final ProfileManagerModel instance = new ProfileManagerModel(manager, identityFactory);
  710. instance.setProfiles(Arrays.asList(new Profile[]{first, second, }));
  711. instance.save();
  712. verify(first).save();
  713. verify(second).delete();
  714. }
  715. }