|
7 | 7 | import java.util.Arrays; |
8 | 8 | import java.util.Calendar; |
9 | 9 | import java.util.Date; |
| 10 | +import java.util.Locale; |
10 | 11 |
|
11 | 12 | /** |
12 | 13 | * Created by Rico on 20.11.2017. |
@@ -59,47 +60,61 @@ public void testGetDaysCount() { |
59 | 60 | } |
60 | 61 |
|
61 | 62 | public void testGetFutureDaysCount() { |
| 63 | + SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.GERMANY); |
62 | 64 | assertEquals(0, timeTable.getFutureDaysCount()); |
63 | 65 |
|
64 | 66 | Calendar cal = Calendar.getInstance(); |
65 | | - cal.set(Calendar.HOUR_OF_DAY,15); |
66 | | - cal.set(Calendar.MINUTE,59); |
67 | | - cal.set(Calendar.SECOND,0); |
68 | | - cal.set(Calendar.MILLISECOND,0); |
69 | | - |
70 | | - Date today1559 = cal.getTime(); |
71 | | - |
72 | | - cal.set(Calendar.HOUR_OF_DAY,16); |
73 | | - cal.set(Calendar.MINUTE,1); |
74 | | - Date today1601 = cal.getTime(); |
75 | 67 |
|
| 68 | + // Check if one day in the future is counted towards "future days" |
| 69 | + cal.set(Calendar.HOUR_OF_DAY,0); |
| 70 | + cal.set(Calendar.MINUTE,0); |
| 71 | + cal.set(Calendar.SECOND,0); |
| 72 | + cal.add(Calendar.DATE, 1); |
| 73 | + Date tomorrow = cal.getTime(); |
| 74 | + System.out.println(sdf.format(tomorrow)); |
76 | 75 | ArrayList<ArrayList<String>> arrayLists = new ArrayList<>(); |
77 | | - TimeTableDay ttd = new TimeTableDay("31.12.", WEEK_A, arrayLists); |
| 76 | + TimeTableDay ttd = new TimeTableDay(sdf.format(tomorrow), WEEK_A, arrayLists); |
78 | 77 | timeTable.addDay(ttd); |
79 | 78 |
|
80 | 79 | assertEquals(1, timeTable.getFutureDaysCount()); |
81 | 80 |
|
82 | | - TimeTableDay ttd2 = new TimeTableDay("30.12.", WEEK_A, arrayLists); |
| 81 | + // Check if 2 days in the future are counted towards "future days" |
| 82 | + |
| 83 | + cal.add(Calendar.DATE, 1); |
| 84 | + Date dayAfterTomorrow = cal.getTime(); |
| 85 | + TimeTableDay ttd2 = new TimeTableDay(sdf.format(dayAfterTomorrow), WEEK_A, arrayLists); |
83 | 86 | timeTable.addDay(ttd2); |
84 | 87 |
|
85 | 88 | assertEquals(2, timeTable.getFutureDaysCount()); |
86 | 89 |
|
87 | | - TimeTableDay ttd3 = new TimeTableDay("01.01.", WEEK_A, arrayLists); |
| 90 | + // Check if prior days are counted towards "future days" |
| 91 | + cal.add(Calendar.DATE, -3); |
| 92 | + Date yesterday = cal.getTime(); |
| 93 | + TimeTableDay ttd3 = new TimeTableDay(sdf.format(yesterday), WEEK_A, arrayLists); |
88 | 94 | timeTable.addDay(ttd3); |
89 | 95 |
|
90 | 96 | assertEquals(2, timeTable.getFutureDaysCount()); |
91 | 97 |
|
92 | 98 | // Check if a TimeTableDay on the same date is considered "future", if it is currently 15:59. |
93 | | - Calendar testCal = Calendar.getInstance(); |
| 99 | + Calendar testCal = Calendar.getInstance(Locale.GERMANY); |
| 100 | + testCal.set(Calendar.HOUR_OF_DAY,15); |
| 101 | + testCal.set(Calendar.MINUTE,59); |
| 102 | + testCal.set(Calendar.SECOND,0); |
| 103 | + testCal.set(Calendar.MILLISECOND,0); |
| 104 | + |
| 105 | + Date today1559 = testCal.getTime(); |
| 106 | + |
| 107 | + testCal.set(Calendar.HOUR_OF_DAY,16); |
| 108 | + testCal.set(Calendar.MINUTE,1); |
| 109 | + Date today1601 = testCal.getTime(); |
| 110 | + |
94 | 111 | testCal.set(Calendar.HOUR_OF_DAY,0); |
95 | 112 | testCal.set(Calendar.MINUTE,0); |
96 | 113 | testCal.set(Calendar.SECOND,0); |
97 | 114 | testCal.set(Calendar.MILLISECOND,0); |
98 | | - Date testDate = testCal.getTime(); |
99 | | - SimpleDateFormat sdf = new SimpleDateFormat("dd.MM."); |
100 | | - String dateString = sdf.format(testDate); |
| 115 | + Date currentDate = new Date(testCal.getTime().getTime()); |
101 | 116 |
|
102 | | - TimeTableDay ttd4 = new TimeTableDay(dateString, WEEK_A, arrayLists); |
| 117 | + TimeTableDay ttd4 = new TimeTableDay(sdf.format(currentDate), WEEK_A, arrayLists); |
103 | 118 | timeTable.addDay(ttd4); |
104 | 119 |
|
105 | 120 | // The day should count as a future day |
|
0 commit comments