Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

UrlCatcherPluginTest.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.urlcatcher;
  23. import com.dmdirc.FrameContainer;
  24. import com.dmdirc.actions.CoreActionType;
  25. import com.dmdirc.config.ConfigManager;
  26. import com.dmdirc.config.IdentityManager;
  27. import com.dmdirc.config.InvalidIdentityFileException;
  28. import com.dmdirc.ui.messages.Styliser;
  29. import org.junit.BeforeClass;
  30. import org.junit.Test;
  31. import static org.junit.Assert.*;
  32. import static org.mockito.Mockito.*;
  33. public class UrlCatcherPluginTest {
  34. private static FrameContainer<?> container;
  35. @BeforeClass
  36. public static void setupClass() {
  37. container = mock(FrameContainer.class);
  38. final ConfigManager manager = mock(ConfigManager.class);
  39. when(container.getConfigManager()).thenReturn(manager);
  40. final Styliser styliser = new Styliser(container);
  41. when(container.getStyliser()).thenReturn(styliser);
  42. }
  43. @Test
  44. public void testURLCounting() throws InvalidIdentityFileException {
  45. IdentityManager.load();
  46. final UrlCatcherPlugin plugin = new UrlCatcherPlugin();
  47. plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
  48. container, "This is a message - http://www.google.com/ foo");
  49. plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
  50. container, "This is a message - http://www.google.com/ foo");
  51. plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
  52. container, "This is a message - http://www.google.com/ foo");
  53. assertEquals(1, plugin.getURLS().size());
  54. assertEquals(3, (int) plugin.getURLS().get("http://www.google.com/"));
  55. }
  56. @Test
  57. public void testURLCatching() throws InvalidIdentityFileException {
  58. IdentityManager.load();
  59. final UrlCatcherPlugin plugin = new UrlCatcherPlugin();
  60. plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
  61. container, "http://www.google.com/ www.example.com foo://bar.baz");
  62. plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
  63. container, "No URLs here, no sir!");
  64. assertEquals(3, plugin.getURLS().size());
  65. assertTrue(plugin.getURLS().containsKey("http://www.google.com/"));
  66. assertTrue(plugin.getURLS().containsKey("www.example.com"));
  67. assertTrue(plugin.getURLS().containsKey("foo://bar.baz"));
  68. }
  69. }