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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.jpq;
  18. import com.dmdirc.config.ConfigBinder;
  19. import com.dmdirc.events.ChannelJoinEvent;
  20. import com.dmdirc.events.ChannelPartEvent;
  21. import com.dmdirc.events.ChannelQuitEvent;
  22. import com.dmdirc.events.DisplayProperty;
  23. import com.dmdirc.events.eventbus.EventBus;
  24. import com.dmdirc.interfaces.GroupChat;
  25. import com.dmdirc.interfaces.WindowModel;
  26. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  27. import org.junit.Before;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import org.mockito.Mock;
  31. import org.mockito.runners.MockitoJUnitRunner;
  32. import static org.mockito.Mockito.never;
  33. import static org.mockito.Mockito.verify;
  34. import static org.mockito.Mockito.when;
  35. @RunWith(MockitoJUnitRunner.class)
  36. public class GroupChatHandlerTest {
  37. @Mock private GroupChat groupChat;
  38. @Mock private WindowModel windowModel;
  39. @Mock private AggregateConfigProvider configProvider;
  40. @Mock private ConfigBinder configBinder;
  41. @Mock private EventBus eventBus;
  42. @Mock private ChannelJoinEvent channelJoinEvent;
  43. @Mock private ChannelPartEvent channelPartEvent;
  44. @Mock private ChannelQuitEvent channelQuitEvent;
  45. private GroupChatHandler instance;
  46. @Before
  47. public void setUp() throws Exception {
  48. when(groupChat.getEventBus()).thenReturn(eventBus);
  49. when(groupChat.getWindowModel()).thenReturn(windowModel);
  50. when(windowModel.getConfigManager()).thenReturn(configProvider);
  51. when(configProvider.getBinder()).thenReturn(configBinder);
  52. when(configBinder.withDefaultDomain("domain")).thenReturn(configBinder);
  53. when(channelJoinEvent.getChannel()).thenReturn(groupChat);
  54. when(channelPartEvent.getChannel()).thenReturn(groupChat);
  55. when(channelQuitEvent.getChannel()).thenReturn(groupChat);
  56. instance = new GroupChatHandler("domain", groupChat);
  57. }
  58. @Test
  59. public void testLoad() throws Exception {
  60. instance.load();
  61. verify(configBinder).bind(instance, GroupChatHandler.class);
  62. verify(eventBus).subscribe(instance);
  63. }
  64. @Test
  65. public void testUnload() throws Exception {
  66. instance.unload();
  67. verify(configBinder).unbind(instance);
  68. verify(eventBus).unsubscribe(instance);
  69. }
  70. @Test
  71. public void testHandleJoin_On() throws Exception {
  72. instance.load();
  73. instance.handleSettingChange(true);
  74. instance.handleJoin(channelJoinEvent);
  75. verify(channelJoinEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  76. }
  77. @Test
  78. public void testHandlePart_On() throws Exception {
  79. instance.load();
  80. instance.handleSettingChange(true);
  81. instance.handlePart(channelPartEvent);
  82. verify(channelPartEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  83. }
  84. @Test
  85. public void testHandleQuit_On() throws Exception {
  86. instance.load();
  87. instance.handleSettingChange(true);
  88. instance.handleQuit(channelQuitEvent);
  89. verify(channelQuitEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  90. }
  91. @Test
  92. public void testHandleJoin_Off() throws Exception {
  93. instance.load();
  94. instance.handleSettingChange(false);
  95. instance.handleJoin(channelJoinEvent);
  96. verify(channelJoinEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  97. }
  98. @Test
  99. public void testHandlePart_Off() throws Exception {
  100. instance.load();
  101. instance.handleSettingChange(false);
  102. instance.handlePart(channelPartEvent);
  103. verify(channelPartEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  104. }
  105. @Test
  106. public void testHandleQuit_Off() throws Exception {
  107. instance.load();
  108. instance.handleSettingChange(false);
  109. instance.handleJoin(channelJoinEvent);
  110. verify(channelJoinEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  111. }
  112. }