Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ProfileManagerControllerTest.java 3.8KB

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