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.

ProfileManagerControllerTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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
  20. * THE SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.dialogs.profiles;
  23. import com.dmdirc.actions.wrappers.Profile;
  24. import com.dmdirc.interfaces.config.IdentityFactory;
  25. import org.junit.Before;
  26. import org.junit.Test;
  27. import org.junit.runner.RunWith;
  28. import org.mockito.Mock;
  29. import org.mockito.runners.MockitoJUnitRunner;
  30. import static org.mockito.Mockito.mock;
  31. import static org.mockito.Mockito.verify;
  32. import static org.mockito.Mockito.when;
  33. /**
  34. * Tests for ProfileManagerController.
  35. */
  36. @RunWith(MockitoJUnitRunner.class)
  37. public class ProfileManagerControllerTest {
  38. @Mock private ProfileManagerDialog dialog;
  39. @Mock private ProfileManagerModel model;
  40. @Mock private IdentityFactory identityFactory;
  41. private ProfileManagerController instance;
  42. @Before
  43. public void setup() {
  44. instance = new ProfileManagerController(dialog, model, identityFactory);
  45. }
  46. /**
  47. * Test of addProfile method, of class ProfileManagerController.
  48. */
  49. @Test
  50. public void testAddProfile() {
  51. instance.addProfile("New Profile");
  52. verify(model).addProfile(new Profile("New Profile", identityFactory));
  53. }
  54. /**
  55. * Test of deleteProfile method, of class ProfileManagerController.
  56. */
  57. @Test
  58. public void testDeleteProfile() {
  59. final Profile selectedProfile = mock(Profile.class);
  60. when(model.getSelectedProfile()).thenReturn(selectedProfile);
  61. instance.deleteProfile();
  62. verify(model).deleteProfile(selectedProfile);
  63. }
  64. /**
  65. * Test of addNickname method, of class ProfileManagerController.
  66. */
  67. @Test
  68. public void testAddNickname() {
  69. instance.addNickname("test");
  70. verify(model).addNickname("test");
  71. }
  72. /**
  73. * Test of editNickname method, of class ProfileManagerController.
  74. */
  75. @Test
  76. public void testEditNickname() {
  77. when(model.getSelectedNickname()).thenReturn("test");
  78. instance.editNickname("test2");
  79. verify(model).editNickname("test", "test2");
  80. }
  81. /**
  82. * Test of deleteNickname method, of class ProfileManagerController.
  83. */
  84. @Test
  85. public void testDeleteNickname() {
  86. when(model.getSelectedNickname()).thenReturn("test");
  87. instance.deleteNickname();
  88. verify(model).deleteNickname((Object) "test");
  89. }
  90. /**
  91. * Test of closeDialog method, of class ProfileManagerController.
  92. */
  93. @Test
  94. public void testCloseDialog() {
  95. instance.closeDialog();
  96. verify(dialog).dispose();
  97. }
  98. /**
  99. * Test of saveAndCloseDialog method, of class ProfileManagerController.
  100. */
  101. @Test
  102. public void testSaveAndCloseDialog() {
  103. instance.saveAndCloseDialog();
  104. verify(model).save();
  105. verify(dialog).dispose();
  106. }
  107. }