package com.fundynamic.d2tm.game.event;

import com.fundynamic.d2tm.game.controls.DraggingSelectionBoxMouse;
import com.fundynamic.d2tm.game.controls.Mouse;
import com.fundynamic.d2tm.game.controls.PlacingStructureMouse;
import com.fundynamic.d2tm.game.controls.PlacingUnitMouse;
import com.fundynamic.d2tm.game.entities.EntityRepository;
import com.fundynamic.d2tm.game.entities.Player;
import com.fundynamic.d2tm.game.map.Map;
import com.fundynamic.d2tm.game.rendering.Recolorer;
import com.fundynamic.d2tm.game.rendering.Viewport;
import com.fundynamic.d2tm.graphics.Shroud;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class DebugKeysListenerTest {

    public static final char ANY_CHAR = '#';

    @Mock private Mouse mouse;
    @Mock private Viewport viewport;
    @Mock private EntityRepository entityRepository;
    private final Player player = new Player("Stefan", Recolorer.FactionColor.BLUE);
    private DebugKeysListener debugKeysListener;

    @Before
    public void setUp() {
        debugKeysListener = new DebugKeysListener(mouse, viewport, entityRepository, player);
    }

    @Test
    public void keySEnablesPlacingStructure() {
        debugKeysListener.keyPressed(Input.KEY_S, ANY_CHAR);

        verify(mouse).setMouseBehavior(isA(PlacingStructureMouse.class));
        verifyZeroInteractions(viewport);
    }

    @Test
    public void keyUEnablesPlacingUnit() {
        debugKeysListener.keyPressed(Input.KEY_U, ANY_CHAR);

        verify(mouse).setMouseBehavior(isA(PlacingUnitMouse.class));
        verifyZeroInteractions(viewport);
    }

    @Test
    public void keyDEnablesDrawDebugMode() {
        debugKeysListener.keyPressed(Input.KEY_D, ANY_CHAR);

        verifyZeroInteractions(mouse);
        verify(viewport).toggleDrawDebugMode();
    }

    @Test
    public void keyREnablesShroudRevealingForPlayer() throws SlickException {
        Map map = mock(Map.class);
        when(viewport.getMap()).thenReturn(map);

        debugKeysListener.keyPressed(Input.KEY_R, ANY_CHAR);

        verifyZeroInteractions(mouse);
        verify(map).revealAllShroudFor(player);
    }

    @Test
    public void anyOtherKeyDoesNothing() {
        debugKeysListener.keyPressed(Input.KEY_Z, ANY_CHAR);
        verifyZeroInteractions(mouse);
        verifyZeroInteractions(viewport);
        verifyZeroInteractions(entityRepository);
    }
}
@@ -1093,16 +1093,71 @@
 R = '#';
+%0A    public static final int ANY_KEY = Input.KEY_COLON;
 %0A%0A    @M
@@ -2655,19 +2655,263 @@
 sed(
-Input.
+ANY_KEY, ANY_CHAR);%0A        verifyZeroInteractions(mouse);%0A        verifyZeroInteractions(viewport);%0A        verifyZeroInteractions(entityRepository);%0A    %7D%0A%0A    @Test%0A    public void keyReleaseDoesNothing() %7B%0A        debugKeysListener.keyReleased(ANY_
 KEY
-_Z
 , AN

Test nothing happens on key release