You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProfileManagerModelTest.java 26KB

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