-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentTests.java
100 lines (88 loc) · 3.09 KB
/
StudentTests.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
97
98
99
100
package tests;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import models.Grade;
import models.Student;
import models.UserFactory;
import models.UserType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import junit.framework.TestCase;
import static org.mockito.Mockito.*;
public class StudentTests extends TestCase {
private Student stud;
public StudentTests(String name) {
super(name);
}
@Before
public void setUp() throws Exception {
// this.stud = (Student) UserFactory.createUser(UserType.STUDENT);
this.stud = mock(Student.class);
when(stud.getUsername()).thenReturn("ionut.petre");
when(stud.getPassword()).thenReturn("a1A@a");
when(stud.getFirstName()).thenReturn("Petre");
when(stud.getLastName()).thenReturn("Ionut");
Calendar calendar = Calendar.getInstance();
calendar.set(1993, 10, 10);
when(stud.getBirthdate()).thenReturn(calendar.getTime());
when(stud.getPlaceOfBirth()).thenReturn("Moreni");
when(stud.getCountry()).thenReturn("România");
when(stud.getCounty()).thenReturn("Dâmbovița");
when(stud.getCity()).thenReturn("Ocnița");
when(stud.getStreet()).thenReturn("Mihail Moxa");
when(stud.getStreetNumber()).thenReturn(11);
when(stud.getZipCode()).thenReturn("123456");
when(stud.getPhone()).thenReturn("0721120747");
when(stud.getEmail()).thenReturn("ionutpetre.ro@gmail.com");
when(stud.getUniversity()).thenReturn("ASE Bucuresti");
when(stud.getSpecialization()).thenReturn(
"Cibernetica, Statistica si Informatica Economica");
when(stud.getStudyYear()).thenReturn(3);
when(stud.getGroup()).thenReturn(1054);
when(stud.getSeries()).thenReturn("B");
when(stud.getGrades()).thenAnswer(new Answer<List<Grade>>() {
public List<Grade> answer(InvocationOnMock invocation)
throws Throwable {
List<Grade> grades = new ArrayList<Grade>();
grades.add(new Grade("SDD", 8.0, 5, 2));
grades.add(new Grade("PAW", 8.0, 4, 2));
grades.add(new Grade("JAVA", 9.0, 4, 2));
return grades;
}
});
}
@Test
public void testStudentGrades() throws Exception {
if (this.stud.getUsername().equals("ionut.petre")
&& this.stud.getPassword().equals("a1A@a")) {
assertEquals("Petre", this.stud.getFirstName());
assertEquals("Ionut", this.stud.getLastName());
List<Grade> grades = new ArrayList<Grade>();
grades.add(new Grade("SDD", 8.0, 5, 2));
grades.add(new Grade("PAW", 8.0, 4, 2));
grades.add(new Grade("JAVA", 9.0, 4, 2));
System.out.println(this.stud.getGrades());
assertEquals(grades, this.stud.getGrades());
}
}
@Test
public void testAverageOfGrades() {
try {
Student stud = (Student) UserFactory.createUser(UserType.STUDENT);
stud.addGrade(new Grade("SDD", 8.0, 5, 2));
stud.addGrade(new Grade("PAW", 8.0, 4, 2));
stud.addGrade(new Grade("JAVA", 9.0, 4, 2));
assertEquals(8.3, stud.getAverageOfGradeByStudyYear(2), 0.5);
} catch (Exception ex) {
ex.printStackTrace();
}
}
@After
public void tearDown() throws Exception {
this.stud = null;
}
}