-
Notifications
You must be signed in to change notification settings - Fork 0
/
BirthdateTests.java
76 lines (66 loc) · 1.66 KB
/
BirthdateTests.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
package tests;
import java.util.Calendar;
import junit.framework.TestCase;
import models.Student;
import models.UserFactory;
import models.UserType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class BirthdateTests extends TestCase {
private Student stud;
public BirthdateTests(String name) {
super(name);
}
@Before
public void setUp() {
try {
this.stud = (Student) UserFactory.createUser(UserType.STUDENT);
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
@Test
public void testBirthdayCorrect() {
Calendar calendar = Calendar.getInstance();
calendar.set(1993, 10, 10);
this.stud.setBirthdate(calendar.getTime());
}
@Test
public void testBirthdayWrong1() {
try {
this.stud.setBirthdate(null);
} catch (Exception ex) {
System.out.println(ex.toString());
assertEquals(null, this.stud.getBirthdate());
}
}
@Test(expected = AssertionError.class)
public void testBirthdayWrong2() {
Calendar calendar = null;
try {
calendar = Calendar.getInstance();
calendar.set(1950, 01, 01);
this.stud.setBirthdate(calendar.getTime());
} catch (Exception ex) {
System.out.println(ex.toString());
assertEquals(calendar.getTime(), this.stud.getBirthdate());
}
}
@Test(expected = AssertionError.class)
public void testBirthdayWrong3() {
Calendar calendar = null;
try {
calendar = Calendar.getInstance();
calendar.set(2000, 01, 01);
this.stud.setBirthdate(calendar.getTime());
} catch (Exception ex) {
System.out.println(ex.toString());
assertEquals(calendar.getTime(), this.stud.getBirthdate());
}
}
@After
public void tearDown() {
this.stud = null;
}
}