]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/TestCalendarUtil.java
upd: rename package name and all references to it
[gigi.git] / tests / club / wpia / gigi / TestCalendarUtil.java
1 package club.wpia.gigi;
2
3 import static org.junit.Assert.*;
4
5 import java.util.Calendar;
6 import java.util.TimeZone;
7
8 import org.junit.Test;
9
10 import club.wpia.gigi.util.CalendarUtil;
11 import club.wpia.gigi.util.DayDate;
12
13 public class TestCalendarUtil {
14
15     @Test
16     public void testGetDateFromComponents() {
17
18         Calendar now = Calendar.getInstance();
19         now.setTimeZone(TimeZone.getTimeZone("UTC"));
20
21         int year = now.get(Calendar.YEAR);
22         int month = now.get(Calendar.MONTH) + 1;
23         int days = now.get(Calendar.DATE);
24         now.setTimeInMillis(0);
25         now.set(year, month - 1, days, 0, 0, 0);
26
27         DayDate dob = CalendarUtil.getDateFromComponents(year, month, days);
28         DayDate d = new DayDate(now.getTimeInMillis());
29
30         assertEquals(d.getTime(), dob.getTime());
31         dob = CalendarUtil.getDateFromComponents(year + 1, month, days);
32
33         assertNotEquals(d.getTime(), dob.getTime());
34
35     }
36
37     @Test
38     public void testIsOfAge() {
39
40         Calendar now = Calendar.getInstance();
41         int year = now.get(Calendar.YEAR);
42         int month = now.get(Calendar.MONTH) + 1;
43         int days = now.get(Calendar.DATE);
44
45         DayDate dob = CalendarUtil.getDateFromComponents(year - 14, month, days);
46
47         assertTrue(CalendarUtil.isOfAge(dob, 13));
48
49         assertTrue(CalendarUtil.isOfAge(dob, 14));
50
51         dob = CalendarUtil.getDateFromComponents(year - 14, month, days + 1);
52         assertFalse(CalendarUtil.isOfAge(dob, 14));
53
54     }
55
56     static {
57         TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
58     }
59
60     @Test
61     public void testIsDateValid() {
62         assertTrue(CalendarUtil.isDateValid(2016, 2, 28));
63         assertTrue(CalendarUtil.isDateValid(2016, 2, 29));
64         assertFalse(CalendarUtil.isDateValid(2016, 2, 30));
65         assertFalse(CalendarUtil.isDateValid(2016, 4, 31));
66
67         assertTrue(CalendarUtil.isDateValid(2000, 2, 28));
68         assertTrue(CalendarUtil.isDateValid(2000, 2, 29));
69         assertFalse(CalendarUtil.isDateValid(2000, 2, 30));
70         assertFalse(CalendarUtil.isDateValid(2000, 4, 31));
71
72         assertTrue(CalendarUtil.isDateValid(2015, 2, 28));
73         assertFalse(CalendarUtil.isDateValid(2015, 2, 29));
74         assertFalse(CalendarUtil.isDateValid(2015, 2, 30));
75         assertFalse(CalendarUtil.isDateValid(2015, 4, 31));
76
77     }
78
79 }