blob: c0749031bc6ed0fbe87b8488b9aa28817550be23 (
plain)
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
|
package cgeo.geocaching.utils;
import static org.assertj.core.api.Assertions.assertThat;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.enumerations.CacheType;
import junit.framework.TestCase;
import java.util.Calendar;
public class CalendarUtilsTest extends TestCase {
public static void testDaysSince() {
final Calendar start = Calendar.getInstance();
for (int hour = 0; hour < 24; hour++) {
start.set(Calendar.HOUR_OF_DAY, hour);
assertThat(CalendarUtils.daysSince(start.getTimeInMillis())).isEqualTo(0);
}
}
public static void testIsPastEvent() {
final Calendar start = Calendar.getInstance();
start.set(Calendar.HOUR_OF_DAY, 0);
start.set(Calendar.MINUTE, 10);
assertPastEvent(start, false);
start.set(Calendar.HOUR_OF_DAY, 23);
assertPastEvent(start, false);
start.add(Calendar.DAY_OF_MONTH, -1);
assertPastEvent(start, true);
}
private static void assertPastEvent(final Calendar start, final boolean expectedPast) {
final Geocache cache = new Geocache();
cache.setType(CacheType.EVENT);
cache.setHidden(start.getTime());
assertThat(CalendarUtils.isPastEvent(cache)).isEqualTo(expectedPast);
}
public static void testIsFuture() {
final Calendar date = Calendar.getInstance();
assertThat(CalendarUtils.isFuture(date)).isFalse();
date.add(Calendar.DAY_OF_MONTH, 1);
assertThat(CalendarUtils.isFuture(date)).isFalse();
date.add(Calendar.DAY_OF_MONTH, 1);
assertThat(CalendarUtils.isFuture(date)).isTrue();
}
}
|