package wabri.MMU_UniversityManager;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

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

import org.junit.Before;
import org.junit.Test;

public class SchoolControllerTest {

	private SchoolController schoolController;
	private Database database;
	private List<Student> students;
	
	@Before
	public void setUp() throws Exception {
		database = mock(Database.class);
		schoolController = new SchoolController(database);
		students = new ArrayList<Student>();
		when(database.getAllStudentsList()).thenReturn(students);
	}

	@Test
	public void testGetAllStudentsWhenThereAreNoStudents() {
		List<Student> allStudents = schoolController.getAllStudents();
		verify(database).getAllStudentsList();
		assertEquals(0, allStudents.size());
	}
	
	@Test
	public void testGetAllStudentsWhenThereIsOneStudent() {
		students.add(newStudentTest(""));
		List<Student> allStudents = schoolController.getAllStudents();
		verify(database).getAllStudentsList();
		assertEquals(1, allStudents.size());
	}
	
	@Test
	public void testGetStudentByIdWhenStudentIsNotThere() {
		students.add(newStudentTest("idTest"));
		Student student = schoolController.getStudentByID("idWrong");
		verify(database).findStudentById("idWrong");
		assertNull(student);
	}

	private Student newStudentTest(String idStudent) {
		return new Student("", "", idStudent, null, null);
	}

}

@@ -346,18 +346,17 @@
 udents;%0A
-%09
 %0A
+
 %09@Before
@@ -792,34 +792,33 @@
 nts.size());%0A%09%7D%0A
-%09
 %0A
+
 %09@Test%0A%09public v
@@ -1053,10 +1053,9 @@
 %0A%09%7D%0A
-%09
 %0A
+
 %09@Te
@@ -1267,16 +1267,16 @@
 rong%22);%0A
-
 %09%09assert
@@ -1294,16 +1294,367 @@
 t);%0A%09%7D%0A%0A
+%09@Test%0A%09public void testGetStudentByIdWhenStudentIsThere() %7B%0A%09%09String idStudent = %22idTest%22;%0A%09%09students.add(newStudentTest(idStudent));%09%09%0A%09%09when(database.findStudentById(idStudent)).thenReturn(students.get(0));%0A%09%09Student student = schoolController.getStudentByID(idStudent);%0A%09%09verify(database).findStudentById(idStudent);%0A%09%09assertNotNull(student);%0A%09%7D%0A%0A
 %09private

create test for right student finding