選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

HistoryWindowTest.java 3.7KB

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