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.4KB

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