-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathFindClassmatesTest.java
96 lines (70 loc) · 2.15 KB
/
FindClassmatesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import static org.junit.Assert.*;
import java.util.List;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
/*
* This class includes test cases for the basic/normal functionality of the
* FriendFinder.findClassmates method, but does not check for any error handling.
*/
public class FindClassmatesTest {
protected FriendFinder ff;
protected ClassesDataSource defaultClassesDataSource = new ClassesDataSource() {
@Override
public List<String> getClasses(String studentName) {
if (studentName.equals("A")) {
return List.of("1", "2", "3");
}
else if (studentName.equals("B")) {
return List.of("1", "2", "3");
}
else if (studentName.equals("C")) {
return List.of("2", "4");
}
else return null;
}
};
protected StudentsDataSource defaultStudentsDataSource = new StudentsDataSource() {
@Override
public List<Student> getStudents(String className) {
Student a = new Student("A", 101);
Student b = new Student("B", 102);
Student c = new Student("C", 103);
if (className.equals("1")) {
return List.of(a, b);
}
else if (className.equals("2")) {
return List.of(a, b, c);
}
else if (className.equals("3")) {
return List.of(a, b);
}
else if (className.equals("4")) {
return List.of(c);
}
else return null;
}
};
@Test
public void testFindOneFriend() {
ff = new FriendFinder(defaultClassesDataSource, defaultStudentsDataSource);
Set<String> response = ff.findClassmates(new Student("A", 101));
assertNotNull(response);
assertEquals(1, response.size());
assertTrue(response.contains("B"));
}
@Test
public void testFindNoFriends() {
ff = new FriendFinder(defaultClassesDataSource, defaultStudentsDataSource);
Set<String> response = ff.findClassmates(new Student("C", 103));
assertNotNull(response);
assertTrue(response.isEmpty());
}
@Test
public void testClassesDataSourceReturnsNullForInputStudent() {
ff = new FriendFinder(defaultClassesDataSource, defaultStudentsDataSource);
Set<String> response = ff.findClassmates(new Student("D", 104));
assertNotNull(response);
assertTrue(response.isEmpty());
}
}