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.

ChannelWhoManagerTest.java 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.channelwho;
  18. import com.dmdirc.events.ServerConnectingEvent;
  19. import com.dmdirc.events.ServerDisconnectedEvent;
  20. import com.dmdirc.interfaces.Connection;
  21. import com.dmdirc.interfaces.ConnectionManager;
  22. import com.dmdirc.interfaces.EventBus;
  23. import com.google.common.collect.Lists;
  24. import java.net.URI;
  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.mockito.Mockito.never;
  31. import static org.mockito.Mockito.verify;
  32. import static org.mockito.Mockito.when;
  33. @RunWith(MockitoJUnitRunner.class)
  34. public class ChannelWhoManagerTest {
  35. @Mock private ConnectionHandlerFactory connectionHandlerFactory;
  36. @Mock private ConnectionHandler connectionHandler;
  37. @Mock private ConnectionManager connectionManager;
  38. @Mock private Connection connection;
  39. @Mock private Connection connection2;
  40. @Mock private EventBus eventBus;
  41. private ChannelWhoManager instance;
  42. @Before
  43. public void setUp() throws Exception {
  44. when(connectionManager.getConnections()).thenReturn(Lists.newArrayList(connection));
  45. when(connectionHandlerFactory.get(connection)).thenReturn(connectionHandler);
  46. instance = new ChannelWhoManager("domain", connectionHandlerFactory, connectionManager,
  47. eventBus);
  48. instance.load();
  49. }
  50. @Test
  51. public void testLoad() throws Exception {
  52. verify(eventBus).subscribe(instance);
  53. verify(connectionHandlerFactory).get(connection);
  54. }
  55. @Test
  56. public void testUnload() throws Exception {
  57. instance.unload();
  58. verify(eventBus).unsubscribe(instance);
  59. verify(connectionHandler).unload();
  60. }
  61. @Test
  62. public void testServerConnectionEvent() throws Exception {
  63. instance.handleServerConnectingEvent(
  64. new ServerConnectingEvent(connection2, URI.create("irc://foo.bar")));
  65. verify(connectionHandlerFactory).get(connection);
  66. }
  67. @Test
  68. public void testServerDisconnectionEvent_Existing() throws Exception {
  69. instance.handleServerDisconnectedEvent(new ServerDisconnectedEvent(connection));
  70. verify(connectionHandler).unload();
  71. }
  72. @Test
  73. public void testServerDisconnectionEvent_Unknown() throws Exception {
  74. instance.handleServerDisconnectedEvent(new ServerDisconnectedEvent(connection2));
  75. verify(connectionHandler, never()).unload();
  76. }
  77. }