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 27KB

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