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

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