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.

GroupChatHandlerTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.addons.jpq;
  23. import com.dmdirc.DMDircMBassador;
  24. import com.dmdirc.config.ConfigBinder;
  25. import com.dmdirc.events.ChannelJoinEvent;
  26. import com.dmdirc.events.ChannelPartEvent;
  27. import com.dmdirc.events.ChannelQuitEvent;
  28. import com.dmdirc.events.DisplayProperty;
  29. import com.dmdirc.interfaces.GroupChat;
  30. import com.dmdirc.interfaces.WindowModel;
  31. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  32. import org.junit.Before;
  33. import org.junit.Test;
  34. import org.junit.runner.RunWith;
  35. import org.mockito.Mock;
  36. import org.mockito.runners.MockitoJUnitRunner;
  37. import static org.mockito.Mockito.never;
  38. import static org.mockito.Mockito.verify;
  39. import static org.mockito.Mockito.when;
  40. @RunWith(MockitoJUnitRunner.class)
  41. public class GroupChatHandlerTest {
  42. @Mock private GroupChat groupChat;
  43. @Mock private WindowModel windowModel;
  44. @Mock private AggregateConfigProvider configProvider;
  45. @Mock private ConfigBinder configBinder;
  46. @Mock private DMDircMBassador eventBus;
  47. @Mock private ChannelJoinEvent channelJoinEvent;
  48. @Mock private ChannelPartEvent channelPartEvent;
  49. @Mock private ChannelQuitEvent channelQuitEvent;
  50. private GroupChatHandler instance;
  51. @Before
  52. public void setUp() throws Exception {
  53. when(groupChat.getEventBus()).thenReturn(eventBus);
  54. when(groupChat.getWindowModel()).thenReturn(windowModel);
  55. when(windowModel.getConfigManager()).thenReturn(configProvider);
  56. when(configProvider.getBinder()).thenReturn(configBinder);
  57. when(configBinder.withDefaultDomain("domain")).thenReturn(configBinder);
  58. instance = new GroupChatHandler("domain", groupChat);
  59. }
  60. @Test
  61. public void testLoad() throws Exception {
  62. instance.load();
  63. verify(configBinder).bind(instance, GroupChatHandler.class);
  64. verify(eventBus).subscribe(instance);
  65. }
  66. @Test
  67. public void testUnload() throws Exception {
  68. instance.unload();
  69. verify(configBinder).unbind(instance);
  70. verify(eventBus).unsubscribe(instance);
  71. }
  72. @Test
  73. public void testHandleJoin_On() throws Exception {
  74. instance.load();
  75. instance.handleSettingChange(true);
  76. instance.handleJoin(channelJoinEvent);
  77. verify(channelJoinEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  78. }
  79. @Test
  80. public void testHandlePart_On() throws Exception {
  81. instance.load();
  82. instance.handleSettingChange(true);
  83. instance.handlePart(channelPartEvent);
  84. verify(channelPartEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  85. }
  86. @Test
  87. public void testHandleQuit_On() throws Exception {
  88. instance.load();
  89. instance.handleSettingChange(true);
  90. instance.handleQuit(channelQuitEvent);
  91. verify(channelQuitEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  92. }
  93. @Test
  94. public void testHandleJoin_Off() throws Exception {
  95. instance.load();
  96. instance.handleSettingChange(false);
  97. instance.handleJoin(channelJoinEvent);
  98. verify(channelJoinEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  99. }
  100. @Test
  101. public void testHandlePart_Off() throws Exception {
  102. instance.load();
  103. instance.handleSettingChange(false);
  104. instance.handlePart(channelPartEvent);
  105. verify(channelPartEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  106. }
  107. @Test
  108. public void testHandleQuit_Off() throws Exception {
  109. instance.load();
  110. instance.handleSettingChange(false);
  111. instance.handleJoin(channelJoinEvent);
  112. verify(channelJoinEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  113. }
  114. }