/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ge.edu.freeuni.sdp.arkanoid.model;

import ge.edu.freeuni.sdp.arkanoid.model.geometry.Point;
import ge.edu.freeuni.sdp.arkanoid.model.geometry.Speed;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.mockito.Mock;
import static org.mockito.Mockito.*;
import org.mockito.MockitoAnnotations;

/**
 *
 * @author dato
 */
public class AutopilotCapsuleTest {
    
    @Mock private Point point;
    @Mock private Room room;
    
    private List<Ball> balls;
    private int speedAngle;
    private Room realRoom;
    
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        balls = new ArrayList<>();
        speedAngle = 30;
        realRoom = new Room();
    }
    
    @Test
    public void capsulCanBeKilled() {
        AutopilotCapsule capsule = new AutopilotCapsule(point, room);
        assertTrue(capsule.isAlive());
    }
    
    @Test
    public void kindIsCapsule(){
        AutopilotCapsule capsule = new AutopilotCapsule(point, room);
        assertEquals(GobjKind.Capsule, capsule.getKind());
    }
    
    @Test
    public void releaseCapsuleInRoom(){
        Capsule capsule = new AutopilotCapsule(point, realRoom);
        
        capsule.release(point);
        
        boolean contains = realRoom.getGobjs().contains(capsule);
        assertTrue(contains);
    }
    
    @Test
    public void capsuleReleaseOnAppropriatePosition(){
        Capsule capsule = new AutopilotCapsule(point, room);
        Point position = new Point(10, 10);
        capsule.release(position);
        
        assertTrue(capsule.getPosition().equals(position));
    }
    
    @Test
    public void createCapsuleMethod() {
        Point otherPoint = new Point(1, 1);
        
        AutopilotCapsule capsule = new AutopilotCapsule(point, room);
        AutopilotCapsule actualCapsule = (AutopilotCapsule)capsule.createCapsule(otherPoint, room);
        
        AutopilotCapsule expected = new AutopilotCapsule(otherPoint, room);
        
        assertTrue(expected.equals(actualCapsule));
    }
    
    @Test
    public void interactCapsuleAndPaddle_KilledPaddle() {
        Paddle mockPaddle = mock(Paddle.class);
        AutopilotCapsule capsule = new AutopilotCapsule(point, room);
        capsule.interact(mockPaddle);
        assertFalse(mockPaddle.isAlive());
    }
    
    @Test
    public void interactCapsule_BallDoubleSpeed() {
        addBallBySpecialSpeed();
        when(room.getGobjs()).thenReturn(new HashSet<>(balls));
        
        Paddle mockPaddle = mock(Paddle.class);
        AutopilotCapsule capsule = new AutopilotCapsule(point, room);
        capsule.interact(mockPaddle);
        
        Speed sp = new Speed(speedAngle);
        sp.setLength(sp.getLength() * 2);
        verify(balls.get(0)).setSpeed(sp);
    }
    
    private void addBallBySpecialSpeed(){
        Ball currentBall = mock(Ball.class);
        when(currentBall.getSpeed()).thenReturn(new Speed(speedAngle));
        balls.add(currentBall);
    }
    
}

@@ -360,24 +360,83 @@
 .ArrayList;%0A
+import java.util.Collection;%0Aimport java.util.Collections;%0A
 import java.
@@ -889,20 +889,20 @@
 te List%3C
-Ball
+Gobj
 %3E balls;
@@ -2476,32 +2476,34 @@
 e));%0A    %7D%0A    %0A
+//
     @Test%0A    pu
@@ -2488,32 +2488,34 @@
    %0A//    @Test%0A
+//
     public void 
@@ -2552,24 +2552,26 @@
 dPaddle() %7B%0A
+//
         Padd
@@ -2598,32 +2598,203 @@
 (Paddle.class);%0A
+//        System.out.println(%22mockPaddle alive:   %22 + mockPaddle.isAlive());%0A//        %0A//        System.out.println(%22mock paddle is alive:   %22 + mockPaddle.isAlive());%0A//
         Autopilo
@@ -2839,32 +2839,47 @@
 e(point, room);%0A
+//        %0A////
         capsule.
@@ -2892,32 +2892,34 @@
 ct(mockPaddle);%0A
+//
         assertFa
@@ -2937,32 +2937,631 @@
 dle.isAlive());%0A
+//    %7D%0A    %0A    @Test%0A    public void interactCapsule_gameWithoutBall()%7B%0A        addPaddleInsteadeOfBall();%0A        when(room.getGobjs()).thenReturn(new HashSet%3C%3E(balls));%0A        %0A        Paddle mockPaddle = mock(Paddle.class);%0A        AutopilotCapsule capsule = new AutopilotCapsule(point, room);%0A        capsule.interact(mockPaddle);%0A        %0A        Speed sp = new Speed(speedAngle);%0A        sp.setLength(sp.getLength() * 2);%0A        verify(balls.get(0), never()).setSpeed(sp);%0A    %7D%0A    %0A    private void addPaddleInsteadeOfBall()%7B%0A        Paddle p = mock(Paddle.class);%0A        balls.add(p);%0A
     %7D%0A    %0A    @

add some edge cases