aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/CacheTest.java
blob: 905cab035039a503d4a73432ce71ae040a5bdb03 (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
package cgeo.geocaching;

import cgeo.geocaching.enumerations.CacheType;

import android.test.AndroidTestCase;

import java.util.Date;

public class CacheTest extends AndroidTestCase {

    final static private class MockedEventCache extends cgCache {
        public MockedEventCache(final Date date) {
            setHidden(date);
            setType(CacheType.EVENT);
        }
    }

    public static void testCanBeAddedToCalendar() {
        final Date today = new Date();
        final cgCache cacheToday = new MockedEventCache(today);
        assertTrue(cacheToday.canBeAddedToCalendar());

        final Date yesterday = new Date(today.getTime() - 86400 * 1000);
        final MockedEventCache cacheYesterday = new MockedEventCache(yesterday);
        assertFalse(cacheYesterday.canBeAddedToCalendar());
    }

    public static void testEquality() {
        final cgCache one = new cgCache();
        final cgCache two = new cgCache();

        // identity
        assertTrue(one.equals(one));

        // different objects without geocode shall not be equal
        assertFalse(one.equals(two));

        one.setGeocode("geocode");
        two.setGeocode("geocode");

        // different objects with same geocode shall be equal
        assertTrue(one.equals(two));
    }

    public static void testGeocodeUppercase() {
        cgCache cache = new cgCache();
        cache.setGeocode("gc1234");
        assertEquals("GC1234", cache.getGeocode());
    }
}