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.

HistoryWindowTest.java 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.logging;
  18. import static junit.framework.TestCase.assertEquals;
  19. import static org.mockito.Matchers.any;
  20. import static org.mockito.Mockito.times;
  21. import static org.mockito.Mockito.verify;
  22. import static org.mockito.Mockito.when;
  23. import com.dmdirc.config.ConfigBinder;
  24. import com.dmdirc.interfaces.Connection;
  25. import com.dmdirc.events.eventbus.EventBus;
  26. import com.dmdirc.interfaces.WindowModel;
  27. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  28. import com.dmdirc.ui.messages.BackBufferFactory;
  29. import com.dmdirc.ui.messages.BackBufferImpl;
  30. import java.nio.file.Paths;
  31. import java.util.Optional;
  32. import org.junit.Before;
  33. import org.junit.Test;
  34. import org.junit.runner.RunWith;
  35. import org.mockito.ArgumentCaptor;
  36. import org.mockito.Captor;
  37. import org.mockito.Mock;
  38. import org.mockito.runners.MockitoJUnitRunner;
  39. @RunWith(MockitoJUnitRunner.class)
  40. public class HistoryWindowTest {
  41. @Mock private BackBufferImpl backBuffer;
  42. @Mock private AggregateConfigProvider config;
  43. @Mock private ConfigBinder configBinder;
  44. @Mock private Connection connection;
  45. @Mock private WindowModel frameContainer;
  46. @Mock private EventBus eventBus;
  47. @Mock private BackBufferFactory backBufferFactory;
  48. @Captor private ArgumentCaptor<HistoricalLineRestoredEvent> eventCaptor;
  49. private HistoryWindow instance;
  50. @Before
  51. public void setUp() throws Exception {
  52. when(backBufferFactory.getBackBuffer(any())).thenReturn(backBuffer);
  53. when(config.getBinder()).thenReturn(configBinder);
  54. when(frameContainer.getConfigManager()).thenReturn(config);
  55. when(frameContainer.getConnection()).thenReturn(Optional.of(connection));
  56. instance = new HistoryWindow("Awesome",
  57. Paths.get(getClass().getResource("logfile.txt").toURI()),
  58. frameContainer, eventBus, backBufferFactory, 4);
  59. }
  60. @Test
  61. public void testGetConnection() throws Exception {
  62. assertEquals(Optional.of(connection), instance.getConnection());
  63. }
  64. @Test
  65. public void testOutputLoggingBackBuffer() throws Exception {
  66. instance.outputLoggingBackBuffer(4);
  67. verify(eventBus, times(4)).publishAsync(eventCaptor.capture());
  68. assertEquals("[21/12/2015 12:58:02] RAAR", eventCaptor.getAllValues().get(0).getLine());
  69. assertEquals("[21/12/2015 12:59:03] RAAAR", eventCaptor.getAllValues().get(1).getLine());
  70. assertEquals("[21/12/2015 13:00:04] RAAAAR", eventCaptor.getAllValues().get(2).getLine());
  71. assertEquals("[21/12/2015 13:01:05] RAAAAAR", eventCaptor.getAllValues().get(3).getLine());
  72. }
  73. }