package fr.unice.polytech.si5.al.projet.s3.truck;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class TourTest {

	@Mock
	private Task aDropPoint;
	private List<Task> dropPointList = new ArrayList<>();

	@Mock
	private Task aDelivery;
	private List<Task> deliveries = new ArrayList<>();

	private Tour tour;

	@Before
	public void setUp() {
		buildDropPoints();
		buildDeliveries();
	}

	@Test
	public void aTour_WhenBuiltWithNoTasks_ShouldNotThrow() {
		dropPointList = new ArrayList<>();
		this.tour = new Tour(dropPointList);
	}

	@Test
	public void aTour_WhenBuiltWithTasks_ShouldHaveDropPoint() {
		this.tour = new Tour(dropPointList);
		assertEquals(1,this.tour.getTaskStack().size());
	}

	@Test
	public void aTour_WhenExecuteIsCalled_ShouldCallDevelopOnTopOfTheStack() {
		this.tour = new Tour(dropPointList);
		this.tour.execute();
		verify(aDropPoint).develop();
	}

	@Test
	public void aTour_WhenExecuteIsCalled_ShouldPushTasksOnTopOfTheStack() {
		this.tour = new Tour(dropPointList);
		this.tour.execute();
		assertEquals(2, this.tour.getTaskStack().size());
	}

	@Test
	public void aTour_WhenExecuteIsCalled_ShouldCallExecuteOnTopOfTheStack() {
		this.tour = new Tour(dropPointList);
		this.tour.execute();
		verify(aDelivery).execute();
	}

	@Test
	public void aTour_WhenExecuteIsCalledAndStackIsEmpty_ShouldNotThrow() {
		dropPointList = new ArrayList<>();
		this.tour = new Tour(dropPointList);
		this.tour.execute();
	}

	//	To test that an exception is raised:
	// @Test(expected = Exception)

	private void buildDropPoints() {
		dropPointList.add(aDropPoint);
	}

	private void buildDeliveries() {
		//	Add mock to list of mocks
		this.deliveries.add(aDelivery);

		//	DropPoint#develop will return the list of mocks
		willReturn(deliveries).given(aDropPoint).develop();
	}
}

@@ -993,9 +993,28 @@
 als(
-1
+dropPointList.size()
 ,thi
@@ -1391,9 +1391,29 @@
 als(
-2
+deliveries.size() + 1
 , th
@@ -1776,32 +1776,32 @@
 dropPointList);%0A
-
 %09%09this.tour.exec
@@ -1811,16 +1811,583 @@
 ();%0A%09%7D%0A%0A
+%09@Test%0A%09public void aTour_WhenExecuteIsCalledAndTopOfStackIsDone_ShouldNotDeployIt() %7B%0A%09%09this.tour = new Tour(dropPointList);%0A%0A%09%09willReturn(true).given(aDropPoint).isDone();%0A%09%09this.tour.execute();%0A%0A%09%09assertEquals(dropPointList.size(), this.tour.getTaskStack().size());%0A%09%7D%0A%0A%09@Test%0A%09public void aTour_WhenExecuteIsCalledAndTopOfStackIsNotDone_ShouldDeployIt() %7B%0A%09%09this.tour = new Tour(dropPointList);%0A%0A%09%09willReturn(false).given(aDropPoint).isDone();%0A%09%09this.tour.execute();%0A%0A%09%09assertEquals(deliveries.size() + dropPointList.size(), this.tour.getTaskStack().size());%0A%09%7D%0A%0A
 %09//%09To t

Update Tour test