Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ProfileManagerModelTest.java 28KB

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