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

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