diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/utils/CalendarUtilsTest.java')
-rw-r--r-- | tests/src/cgeo/geocaching/utils/CalendarUtilsTest.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/utils/CalendarUtilsTest.java b/tests/src/cgeo/geocaching/utils/CalendarUtilsTest.java new file mode 100644 index 0000000..c074903 --- /dev/null +++ b/tests/src/cgeo/geocaching/utils/CalendarUtilsTest.java @@ -0,0 +1,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(); + } +} |