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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.DMDircMBassador;
  24. import com.dmdirc.config.ConfigBinder;
  25. import com.dmdirc.events.DisplayPropertyMap;
  26. import com.dmdirc.interfaces.Connection;
  27. import com.dmdirc.interfaces.WindowModel;
  28. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  29. import com.dmdirc.ui.messages.BackBuffer;
  30. import com.dmdirc.ui.messages.BackBufferFactory;
  31. import com.dmdirc.ui.messages.IRCDocument;
  32. import java.nio.file.Paths;
  33. import java.text.SimpleDateFormat;
  34. import java.util.Optional;
  35. import org.junit.Before;
  36. import org.junit.Test;
  37. import org.junit.runner.RunWith;
  38. import org.mockito.InOrder;
  39. import org.mockito.Mock;
  40. import org.mockito.runners.MockitoJUnitRunner;
  41. import static junit.framework.TestCase.assertEquals;
  42. import static org.mockito.Matchers.any;
  43. import static org.mockito.Matchers.eq;
  44. import static org.mockito.Mockito.inOrder;
  45. import static org.mockito.Mockito.when;
  46. @RunWith(MockitoJUnitRunner.class)
  47. public class HistoryWindowTest {
  48. @Mock private IRCDocument document;
  49. @Mock private BackBuffer backBuffer;
  50. @Mock private AggregateConfigProvider config;
  51. @Mock private ConfigBinder configBinder;
  52. @Mock private Connection connection;
  53. @Mock private WindowModel frameContainer;
  54. @Mock private DMDircMBassador eventBus;
  55. @Mock private BackBufferFactory backBufferFactory;
  56. private HistoryWindow instance;
  57. @Before
  58. public void setUp() throws Exception {
  59. when(backBufferFactory.getBackBuffer(any())).thenReturn(backBuffer);
  60. when(backBuffer.getDocument()).thenReturn(document);
  61. when(config.getBinder()).thenReturn(configBinder);
  62. when(frameContainer.getConfigManager()).thenReturn(config);
  63. when(frameContainer.getConnection()).thenReturn(Optional.of(connection));
  64. instance = new HistoryWindow("Awesome",
  65. Paths.get(getClass().getResource("logfile.txt").toURI()),
  66. frameContainer, eventBus, backBufferFactory, 4);
  67. }
  68. @Test
  69. public void testGetConnection() throws Exception {
  70. assertEquals(Optional.of(connection), instance.getConnection());
  71. }
  72. @Test
  73. public void testOutputLoggingBackBuffer() throws Exception {
  74. instance.outputLoggingBackBuffer(4);
  75. final InOrder inOrder = inOrder(document);
  76. inOrder.verify(document).addText(eq(new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]")
  77. .parse("[21/12/2015 12:58:02]").getTime()), eq
  78. (DisplayPropertyMap.EMPTY), eq("RAAR"));
  79. inOrder.verify(document).addText(eq(new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]")
  80. .parse("[21/12/2015 12:59:03]").getTime()), eq
  81. (DisplayPropertyMap.EMPTY), eq("RAAAR"));
  82. inOrder.verify(document).addText(eq(new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]")
  83. .parse("[21/12/2015 13:00:04]").getTime()), eq
  84. (DisplayPropertyMap.EMPTY), eq("RAAAAR"));
  85. inOrder.verify(document).addText(eq(new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]")
  86. .parse("[21/12/2015 13:01:05]").getTime()), eq
  87. (DisplayPropertyMap.EMPTY), eq("RAAAAAR"));
  88. inOrder.verifyNoMoreInteractions();
  89. }
  90. }