Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

GroupChatHandlerTest.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.config.ConfigBinder;
  24. import com.dmdirc.events.ChannelJoinEvent;
  25. import com.dmdirc.events.ChannelPartEvent;
  26. import com.dmdirc.events.ChannelQuitEvent;
  27. import com.dmdirc.events.DisplayProperty;
  28. import com.dmdirc.interfaces.EventBus;
  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 EventBus 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. when(channelJoinEvent.getChannel()).thenReturn(groupChat);
  59. when(channelPartEvent.getChannel()).thenReturn(groupChat);
  60. when(channelQuitEvent.getChannel()).thenReturn(groupChat);
  61. instance = new GroupChatHandler("domain", groupChat);
  62. }
  63. @Test
  64. public void testLoad() throws Exception {
  65. instance.load();
  66. verify(configBinder).bind(instance, GroupChatHandler.class);
  67. verify(eventBus).subscribe(instance);
  68. }
  69. @Test
  70. public void testUnload() throws Exception {
  71. instance.unload();
  72. verify(configBinder).unbind(instance);
  73. verify(eventBus).unsubscribe(instance);
  74. }
  75. @Test
  76. public void testHandleJoin_On() throws Exception {
  77. instance.load();
  78. instance.handleSettingChange(true);
  79. instance.handleJoin(channelJoinEvent);
  80. verify(channelJoinEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  81. }
  82. @Test
  83. public void testHandlePart_On() throws Exception {
  84. instance.load();
  85. instance.handleSettingChange(true);
  86. instance.handlePart(channelPartEvent);
  87. verify(channelPartEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  88. }
  89. @Test
  90. public void testHandleQuit_On() throws Exception {
  91. instance.load();
  92. instance.handleSettingChange(true);
  93. instance.handleQuit(channelQuitEvent);
  94. verify(channelQuitEvent).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  95. }
  96. @Test
  97. public void testHandleJoin_Off() throws Exception {
  98. instance.load();
  99. instance.handleSettingChange(false);
  100. instance.handleJoin(channelJoinEvent);
  101. verify(channelJoinEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  102. }
  103. @Test
  104. public void testHandlePart_Off() throws Exception {
  105. instance.load();
  106. instance.handleSettingChange(false);
  107. instance.handlePart(channelPartEvent);
  108. verify(channelPartEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  109. }
  110. @Test
  111. public void testHandleQuit_Off() throws Exception {
  112. instance.load();
  113. instance.handleSettingChange(false);
  114. instance.handleJoin(channelJoinEvent);
  115. verify(channelJoinEvent, never()).setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
  116. }
  117. }