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.

CoreFeedbackDialogModelTest.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (c) 2006-2015 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.ui.core.feedback;
  23. import com.dmdirc.interfaces.ui.FeedbackDialogModelListener;
  24. import java.util.Optional;
  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.junit.Assert.assertEquals;
  31. import static org.junit.Assert.assertFalse;
  32. import static org.junit.Assert.assertTrue;
  33. import static org.mockito.Mockito.verify;
  34. @RunWith(MockitoJUnitRunner.class)
  35. public class CoreFeedbackDialogModelTest {
  36. private static final String NAME = "Bob Dole";
  37. private static final String EMAIL = "bob@dole.com";
  38. private static final String FEEDBACK = "DMDirc Rocks.";
  39. @Mock private FeedbackSenderFactory feedbackSenderFactory;
  40. @Mock private FeedbackDialogModelListener listener;
  41. @Mock private FeedbackHelper feedbackHelper;
  42. private CoreFeedbackDialogModel instance;
  43. @Before
  44. public void setup() {
  45. instance = new CoreFeedbackDialogModel(feedbackSenderFactory, feedbackHelper);
  46. }
  47. @Test
  48. public void testName() {
  49. assertEquals("testName", Optional.<String>empty(), instance.getName());
  50. instance.setName(Optional.of(NAME));
  51. assertEquals("testName", Optional.of(NAME), instance.getName());
  52. }
  53. @Test
  54. public void testEmail() {
  55. assertEquals("testEmail", Optional.<String>empty(), instance.getEmail());
  56. instance.setEmail(Optional.of(EMAIL));
  57. assertEquals("testEmail", Optional.of(EMAIL), instance.getEmail());
  58. }
  59. @Test
  60. public void testFeedback() {
  61. assertEquals("testFeedback", Optional.<String>empty(), instance.getFeedback());
  62. instance.setFeedback(Optional.of(FEEDBACK));
  63. assertEquals("testFeedback", Optional.of(FEEDBACK), instance.getFeedback());
  64. }
  65. @Test
  66. public void testServerInfo() {
  67. assertFalse("testServerInfo", instance.getIncludeServerInfo());
  68. instance.setIncludeServerInfo(true);
  69. assertTrue("testServerInfo", instance.getIncludeServerInfo());
  70. }
  71. @Test
  72. public void testDMDircInfo() {
  73. assertFalse("testDMDircInfo", instance.getIncludeDMDircInfo());
  74. instance.setIncludeDMDircInfo(true);
  75. assertTrue("testDMDircInfo", instance.getIncludeDMDircInfo());
  76. }
  77. @Test
  78. public void testSaveWithoutServerWithoutDMDirc() {
  79. instance.setIncludeDMDircInfo(false);
  80. instance.setIncludeServerInfo(false);
  81. instance.setName(Optional.of(NAME));
  82. instance.setEmail(Optional.of(EMAIL));
  83. instance.setFeedback(Optional.of(FEEDBACK));
  84. instance.save();
  85. verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
  86. feedbackHelper.getVersion(), "", "");
  87. }
  88. @Test
  89. public void testSaveWithoutServerWithDMDirc() {
  90. instance.setIncludeDMDircInfo(true);
  91. instance.setIncludeServerInfo(false);
  92. instance.setName(Optional.of(NAME));
  93. instance.setEmail(Optional.of(EMAIL));
  94. instance.setFeedback(Optional.of(FEEDBACK));
  95. instance.save();
  96. verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
  97. feedbackHelper.getVersion(), "", feedbackHelper.getDMDircInfo());
  98. }
  99. @Test
  100. public void testSaveWithoutDMDircWithServer() {
  101. instance.setIncludeDMDircInfo(false);
  102. instance.setIncludeServerInfo(true);
  103. instance.setName(Optional.of(NAME));
  104. instance.setEmail(Optional.of(EMAIL));
  105. instance.setFeedback(Optional.of(FEEDBACK));
  106. instance.save();
  107. verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
  108. feedbackHelper.getVersion(), feedbackHelper.getServerInfo(), "");
  109. }
  110. @Test
  111. public void testSaveWithServerWithDMDirc() {
  112. instance.setIncludeDMDircInfo(true);
  113. instance.setIncludeServerInfo(true);
  114. instance.setName(Optional.of(NAME));
  115. instance.setEmail(Optional.of(EMAIL));
  116. instance.setFeedback(Optional.of(FEEDBACK));
  117. instance.save();
  118. verify(feedbackSenderFactory).getFeedbackSender(NAME, EMAIL, FEEDBACK,
  119. feedbackHelper.getVersion(), feedbackHelper.getServerInfo(),
  120. feedbackHelper.getDMDircInfo());
  121. }
  122. @Test
  123. public void testNameListener() {
  124. instance.addListener(listener);
  125. instance.setName(Optional.of(NAME));
  126. verify(listener).nameChanged(Optional.of(NAME));
  127. }
  128. @Test
  129. public void testEmailListener() {
  130. instance.addListener(listener);
  131. instance.setEmail(Optional.of(EMAIL));
  132. verify(listener).emailChanged(Optional.of(EMAIL));
  133. }
  134. @Test
  135. public void testFeedbackListener() {
  136. instance.addListener(listener);
  137. instance.setFeedback(Optional.of(FEEDBACK));
  138. verify(listener).feedbackChanged(Optional.of(FEEDBACK));
  139. }
  140. @Test
  141. public void testServerInfoListener() {
  142. instance.addListener(listener);
  143. instance.setIncludeServerInfo(true);
  144. verify(listener).includeServerInfoChanged(true);
  145. }
  146. @Test
  147. public void testDMDircInfoListener() {
  148. instance.addListener(listener);
  149. instance.setIncludeDMDircInfo(true);
  150. verify(listener).includeDMDircInfoChanged(true);
  151. }
  152. }