package com.fundynamic.d2tm.game.controls;

import com.fundynamic.d2tm.game.AbstractD2TMTest;
import com.fundynamic.d2tm.game.behaviors.Selectable;
import com.fundynamic.d2tm.game.entities.EntitiesData;
import com.fundynamic.d2tm.game.entities.EntityType;
import com.fundynamic.d2tm.math.Coordinate;
import com.fundynamic.d2tm.math.Vector2D;
import org.junit.Before;
import org.junit.Test;
import org.newdawn.slick.SlickException;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertFalse;


public class DraggingSelectionBoxMouseTest extends AbstractD2TMTest {

    private DraggingSelectionBoxMouse draggingSelectionBoxMouse;

    @Before
    public void setUp() throws SlickException {
        super.setUp();

        // start dragging from 0,0
        draggingSelectionBoxMouse = new DraggingSelectionBoxMouse(battleField, entityRepository, Vector2D.zero());
        battleField.setMouseBehavior(draggingSelectionBoxMouse);

    }

    @Test
    public void draggingOverNothingSelectsNoUnits() throws SlickException {
        mouse.draggedToCoordinates(Vector2D.create(10, 10));

        mouse.leftButtonReleased();
    }

    @Test
    public void draggingOverUnitsSelectsUnits() {
        Coordinate coordinate = Coordinate.create(32, 32);
        Selectable entity = (Selectable) entityRepository.placeOnMap(coordinate, EntityType.UNIT, EntitiesData.QUAD, player);
        assertFalse(entity.isSelected());

        mouse.draggedToCoordinates(Vector2D.create(64, 64)); // == 2, 2 on map

        mouse.leftButtonReleased();

        assertTrue(entity.isSelected());
    }

    @Test
    public void whenReleasingLeftButtonDeselectAllPreviouslySelectedUnitsFirst() {
        Coordinate coordinate = Coordinate.create(1, 1);
        Selectable entity = (Selectable) entityRepository.placeOnMap(coordinate, EntityType.UNIT, EntitiesData.QUAD, player);
        entity.select();
        assertTrue(entity.isSelected());

        mouse.draggedToCoordinates(Vector2D.create(0, 0));

        // this will select nothing
        mouse.leftButtonReleased();

        assertFalse(entity.isSelected());
    }

    @Test
    public void render() {
        draggingSelectionBoxMouse.render(graphics);
    }

}
@@ -778,16 +778,72 @@
 rom 0,0%0A
+        Vector2D startingCoordinates = Vector2D.zero();%0A
         
@@ -935,92 +935,30 @@
 ry, 
-Vector2D.zero());%0A        battleField.setMouseBehavior(draggingSelectionBoxMouse
+startingCoordinates
 );%0A
-%0A
     
@@ -1046,33 +1046,53 @@
 ption %7B%0A        
-m
+draggingSelectionBoxM
 ouse.draggedToCo
@@ -1128,33 +1128,53 @@
  10));%0A%0A        
-m
+draggingSelectionBoxM
 ouse.leftButtonR
@@ -1479,33 +1479,53 @@
 ed());%0A%0A        
-m
+draggingSelectionBoxM
 ouse.draggedToCo
@@ -1579,33 +1579,53 @@
 on map%0A%0A        
-m
+draggingSelectionBoxM
 ouse.leftButtonR
@@ -2031,25 +2031,45 @@
 );%0A%0A        
-m
+draggingSelectionBoxM
 ouse.dragged
@@ -2151,17 +2151,37 @@
         
-m
+draggingSelectionBoxM
 ouse.lef

Fix last remaining broken tests