package control;

import data.CameraShot;
import data.ScriptingProject;
import gui.CameraShotBlock;
import gui.CameraShotBlockUpdatedEvent;
import gui.RootPane;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;

/**
 * @author alex
 */
public class TimelineControllerTest {
    TimelineController timelineController;
    private ScriptingProject project;
    private CameraShot shot;
    private CameraShotBlock shotBlock;

    @Before
    public void initialize() {
        RootPane rootPane = Mockito.mock(RootPane.class);
        timelineController = new TimelineController(rootPane);
        project = timelineController.getScriptingProject();

        shot = new CameraShot("Shot test", "", 1, 2);
        project.getCameraTimelines().get(0).addShot(shot);

        shotBlock = Mockito.mock(CameraShotBlock.class);
        when(shotBlock.getShotId()).thenReturn(shot.getInstance());
    }

    @Test
    public void shotChangedLengthTest() {
        when(shotBlock.getBeginCount()).thenReturn(1.0);
        when(shotBlock.getEndCount()).thenReturn(5.0);
        when(shotBlock.getTimetableNumber()).thenReturn(0);

        timelineController.shotChangedHandler(new CameraShotBlockUpdatedEvent(
                shotBlock, 0
        ));

        assertEquals(shot.getEndCount(), 5.0, 0);
    }

    @Test
    public void shotChangedStartPositionTest() {
        when(shotBlock.getBeginCount()).thenReturn(0.0);
        when(shotBlock.getEndCount()).thenReturn(2.0);
        when(shotBlock.getTimetableNumber()).thenReturn(0);

        timelineController.shotChangedHandler(new CameraShotBlockUpdatedEvent(
                shotBlock, 0
        ));

        assertEquals(shot.getStartCount(), 0.0, 0);
    }

    @Test
    public void shotChangedTimelinesTest() {
        when(shotBlock.getBeginCount()).thenReturn(1.0);
        when(shotBlock.getEndCount()).thenReturn(2.0);
        when(shotBlock.getTimetableNumber()).thenReturn(1);

        timelineController.shotChangedHandler(new CameraShotBlockUpdatedEvent(
                shotBlock, 0
        ));

        // Verify movement between timelines
        assertEquals(project.getCameraTimelines().get(0).getShots().size(), 0);
        assertEquals(project.getCameraTimelines().get(1).getShots().size(), 1);
    }
}

@@ -1263,32 +1263,49 @@
 tChangedHandler(
+%0A                
 new CameraShotBl
@@ -1320,33 +1320,16 @@
 edEvent(
-%0A                
 shotBloc
@@ -1324,32 +1324,33 @@
 ent(shotBlock, 0
+)
 %0A        ));%0A%0A  
@@ -1334,33 +1334,32 @@
 ock, 0)%0A        
-)
 );%0A%0A        asse
@@ -1673,32 +1673,49 @@
 tChangedHandler(
+%0A                
 new CameraShotBl
@@ -1730,33 +1730,16 @@
 edEvent(
-%0A                
 shotBloc
@@ -1734,32 +1734,33 @@
 ent(shotBlock, 0
+)
 %0A        ));%0A%0A  
@@ -1744,33 +1744,32 @@
 ock, 0)%0A        
-)
 );%0A%0A        asse
@@ -2089,16 +2089,33 @@
 Handler(
+%0A                
 new Came
@@ -2138,33 +2138,16 @@
 edEvent(
-%0A                
 shotBloc
@@ -2150,16 +2150,17 @@
 Block, 0
+)
 %0A       
@@ -2160,17 +2160,16 @@
         
-)
 );%0A%0A    

Fix indentation TimelineControllerTest