/*
 * Copyright (c) 2006-2013 DMDirc Developers
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.addons.urlcatcher;

import com.dmdirc.TestMain;
import com.dmdirc.FrameContainer;
import com.dmdirc.actions.CoreActionType;
import com.dmdirc.config.ConfigManager;
import com.dmdirc.config.InvalidIdentityFileException;
import com.dmdirc.interfaces.CommandController;
import com.dmdirc.ui.messages.Styliser;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class UrlCatcherPluginTest {

    private static FrameContainer container;

    @BeforeClass
    public static void setupClass() {
        container = mock(FrameContainer.class);

        final ConfigManager manager = mock(ConfigManager.class);

        when(container.getConfigManager()).thenReturn(manager);

        final Styliser styliser = new Styliser(container);

        when(container.getStyliser()).thenReturn(styliser);
    }

    @Test
    public void testURLCounting() throws InvalidIdentityFileException {
        TestMain.getTestMain();

        final UrlCatcherPlugin plugin = new UrlCatcherPlugin(mock(CommandController.class));

        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
                container, "This is a message - http://www.google.com/ foo");
        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
                container, "This is a message - http://www.google.com/ foo");
        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
                container, "This is a message - http://www.google.com/ foo");

        assertEquals(1, plugin.getURLS().size());
        assertEquals(3, (int) plugin.getURLS().get("http://www.google.com/"));
    }

    @Test
    public void testURLCatching() throws InvalidIdentityFileException {
        TestMain.getTestMain();

        final UrlCatcherPlugin plugin = new UrlCatcherPlugin(mock(CommandController.class));

        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
                container, "http://www.google.com/ www.example.com foo://bar.baz");
        plugin.processEvent(CoreActionType.CHANNEL_MESSAGE, null,
                container, "No URLs here, no sir!");

        assertEquals(3, plugin.getURLS().size());
        assertTrue(plugin.getURLS().containsKey("http://www.google.com/"));
        assertTrue(plugin.getURLS().containsKey("www.example.com"));
        assertTrue(plugin.getURLS().containsKey("foo://bar.baz"));
    }

}

@@ -1164,36 +1164,8 @@
 r;%0A%0A
-import com.dmdirc.TestMain;%0A
 impo
@@ -1415,24 +1415,25 @@
 s.Styliser;%0A
+%0A
 import org.j
@@ -1443,21 +1443,16 @@
 t.Before
-Class
 ;%0Aimport
@@ -1466,16 +1466,121 @@
 nit.Test
+;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner
 ;%0Aimport
@@ -1645,16 +1645,51 @@
 ito.*;%0A%0A
+@RunWith(MockitoJUnitRunner.class)%0A
 public c
@@ -1725,16 +1725,22 @@
     
+@Mock 
 private 
 stat
@@ -1735,23 +1735,16 @@
 private 
-static 
 FrameCon
@@ -1765,178 +1765,140 @@
 er;%0A
-%0A
     @
-BeforeClass%0A    public static void setupClass() %7B%0A        container = mock(FrameContainer.class);%0A%0A        final ConfigManager manager = mock(ConfigManager.class);%0A
+Mock private ConfigManager manager;%0A    @Mock private CommandController controller;%0A%0A    @Before%0A    public void setupClass() %7B
 %0A   
@@ -1954,25 +1954,24 @@
 n(manager);%0A
-%0A
         fina
@@ -2017,17 +2017,16 @@
 ainer);%0A
-%0A
         
@@ -2170,41 +2170,8 @@
 n %7B%0A
-        TestMain.getTestMain();%0A%0A
     
@@ -2223,37 +2223,25 @@
 tcherPlugin(
-mock(CommandC
+c
 ontroller.cl
@@ -2229,39 +2229,32 @@
 lugin(controller
-.class)
 );%0A%0A        plug
@@ -2896,41 +2896,8 @@
 n %7B%0A
-        TestMain.getTestMain();%0A%0A
     
@@ -2957,21 +2957,9 @@
 gin(
-mock(CommandC
+c
 ontr
@@ -2963,23 +2963,16 @@
 ntroller
-.class)
 );%0A%0A    

Fix the URL Catcher plugin tests.