| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import org.junit.Before;
- import org.junit.Ignore;
- import org.junit.Test;
-
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.List;
- import java.util.Collection;
-
- import org.hamcrest.Matcher;
- import org.hamcrest.collection.IsIterableContainingInOrder;
- import static org.hamcrest.CoreMatchers.*;
- import static org.junit.Assert.assertThat;
- import static org.junit.Assert.assertTrue;
- import static org.junit.Assert.assertEquals;
-
- public class SchoolTest {
- private School school;
-
- @Before
- public void setUp() {
- school = new School();
- }
-
- @Test
- public void startsWithNoStudents() {
- assertThat(school.numberOfStudents(), is(0));
- }
-
- @Ignore
- @Test
- public void addsStudents() {
- school.add("Aimee", 2);
- assertThat(school.grade(2), hasItem("Aimee"));
- }
-
- @Ignore
- @Test
- public void addsMoreStudentsInSameGrade() {
- final int grade = 2;
- school.add("James", grade);
- school.add("Blair", grade);
- school.add("Paul", grade);
-
- assertThat(school.grade(grade).size(), is(3));
- assertThat(school.grade(grade), allOf(hasItem("James"), hasItem("Blair"), hasItem("Paul")));
- }
-
- @Ignore
- @Test
- public void addsStudentsInMultipleGrades() {
- school.add("Chelsea", 3);
- school.add("Logan", 7);
-
- assertThat(school.numberOfStudents(), is(2));
- assertThat(school.grade(3).size(), is(1));
- assertThat(school.grade(3), hasItem("Chelsea"));
- assertThat(school.grade(7).size(), is(1));
- assertThat(school.grade(7), hasItem("Logan"));
- }
-
- @Ignore
- @Test
- public void getsStudentsInEmptyGrade() {
- assertTrue(school.grade(1).isEmpty());
- }
-
- @Ignore
- @Test
- public void sortsSchool() {
- school.add("Kyle", 4);
- school.add("Zed", 4);
- school.add("Adam", 4);
- school.add("Jennifer", 4);
- school.add("Kareem", 6);
- school.add("Christopher", 4);
- school.add("Kylie", 3);
- Map<Integer, Matcher> sortedStudents = new HashMap<Integer, Matcher>();
- sortedStudents.put(6, IsIterableContainingInOrder
- .contains("Kareem"));
- sortedStudents.put(4, IsIterableContainingInOrder
- .contains("Adam", "Christopher", "Jennifer", "Kyle", "Zed"));
- sortedStudents.put(3, IsIterableContainingInOrder
- .contains("Kylie"));
-
- Map schoolStudents = school.studentsByGradeAlphabetical();
- for (Map.Entry<?, Matcher> entry : sortedStudents.entrySet()) {
-
- assertThat((Collection) schoolStudents.get(entry.getKey()), entry.getValue());
- }
- }
-
- @Ignore
- @Test
- public void modifyingFetchedGradeShouldNotModifyInternalDatabase() {
- String shouldNotBeAdded = "Should not be added to school";
- int grade = 1;
-
- Collection students = school.grade(grade);
-
- try {
- students.add(shouldNotBeAdded);
- } catch (Exception exception) {
- // Also valid that the add operation throws an exception
- // Such as UnsupportedOperationException when an umodifiable collection type is used
- }
-
- assertThat(school.grade(grade), not(hasItem(shouldNotBeAdded)));
- }
-
- @Ignore
- @Test
- public void modifyingSortedStudentsShouldNotModifyInternalDatabase() {
- int grade = 2;
- String studentWhichShouldNotBeAdded = "Should not be added";
- List<String> listWhichShouldNotBeAdded = new ArrayList<>();
- listWhichShouldNotBeAdded.add(studentWhichShouldNotBeAdded);
-
- Map sortedStudents = school.studentsByGradeAlphabetical();
-
- try {
- sortedStudents.put(grade, listWhichShouldNotBeAdded);
- } catch (Exception exception) {
- // Also valid that the put operation throws an exception
- // Such as UnsupportedOperationException when an unmodifiableMap is used
- }
-
- assertThat(school.studentsByGradeAlphabetical().get(grade),
- not(hasItem(studentWhichShouldNotBeAdded)));
- }
- }
|