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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2006-2013 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 org.junit.Test;
  24. import static org.junit.Assert.*;
  25. import static org.mockito.Mockito.*;
  26. /**
  27. * Tests for ProfileManagerController.
  28. */
  29. public class ProfileManagerControllerTest {
  30. /**
  31. * Test of addProfile method, of class ProfileManagerController.
  32. */
  33. @Test
  34. public void testAddProfile() {
  35. final ProfileManagerDialog dialog = mock(ProfileManagerDialog.class);
  36. final ProfileManagerModel model = mock(ProfileManagerModel.class);
  37. ProfileManagerController instance = new ProfileManagerController(dialog, model);
  38. instance.addProfile();
  39. verify(model).addProfile(new Profile());
  40. }
  41. /**
  42. * Test of deleteProfile method, of class ProfileManagerController.
  43. */
  44. @Test
  45. public void testDeleteProfile() {
  46. final ProfileManagerDialog dialog = mock(ProfileManagerDialog.class);
  47. final ProfileManagerModel model = mock(ProfileManagerModel.class);
  48. final Profile selectedProfile = mock(Profile.class);
  49. when(model.getSelectedProfile()).thenReturn(selectedProfile);
  50. ProfileManagerController instance = new ProfileManagerController(dialog, model);
  51. instance.deleteProfile();
  52. verify(model).deleteProfile(selectedProfile);
  53. }
  54. /**
  55. * Test of addNickname method, of class ProfileManagerController.
  56. */
  57. @Test
  58. public void testAddNickname() {
  59. final ProfileManagerDialog dialog = mock(ProfileManagerDialog.class);
  60. final ProfileManagerModel model = mock(ProfileManagerModel.class);
  61. ProfileManagerController instance = new ProfileManagerController(dialog, model);
  62. instance.addNickname("test");
  63. verify(model).addNickname("test");
  64. }
  65. /**
  66. * Test of editNickname method, of class ProfileManagerController.
  67. */
  68. @Test
  69. public void testEditNickname() {
  70. final ProfileManagerDialog dialog = mock(ProfileManagerDialog.class);
  71. final ProfileManagerModel model = mock(ProfileManagerModel.class);
  72. when(model.getSelectedNickname()).thenReturn("test");
  73. ProfileManagerController instance = new ProfileManagerController(dialog, model);
  74. instance.editNickname("test2");
  75. verify(model).editNickname("test", "test2");
  76. }
  77. /**
  78. * Test of deleteNickname method, of class ProfileManagerController.
  79. */
  80. @Test
  81. public void testDeleteNickname() {
  82. final ProfileManagerDialog dialog = mock(ProfileManagerDialog.class);
  83. final ProfileManagerModel model = mock(ProfileManagerModel.class);
  84. when(model.getSelectedNickname()).thenReturn("test");
  85. ProfileManagerController instance = new ProfileManagerController(dialog, model);
  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. final ProfileManagerDialog dialog = mock(ProfileManagerDialog.class);
  95. final ProfileManagerModel model = mock(ProfileManagerModel.class);
  96. ProfileManagerController instance = new ProfileManagerController(dialog, model);
  97. instance.closeDialog();
  98. verify(dialog).dispose();
  99. }
  100. /**
  101. * Test of saveAndCloseDialog method, of class ProfileManagerController.
  102. */
  103. @Test
  104. public void testSaveAndCloseDialog() {
  105. final ProfileManagerDialog dialog = mock(ProfileManagerDialog.class);
  106. final ProfileManagerModel model = mock(ProfileManagerModel.class);
  107. ProfileManagerController instance = new ProfileManagerController(dialog, model);
  108. instance.saveAndCloseDialog();
  109. verify(model).save();
  110. verify(dialog).dispose();
  111. }
  112. }