aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/files/LocParserTest.java
blob: 6e00b354739bd1a0eaebb85681b61a2002ade87f (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cgeo.geocaching.files;

import cgeo.geocaching.Geocache;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class LocParserTest extends AbstractResourceInstrumentationTestCase {
    private List<Geocache> readLoc(int resourceId) throws IOException, ParserException {
        final LocParser parser = new LocParser(getTemporaryListId());
        Collection<Geocache> caches = null;
        final InputStream instream = getResourceStream(resourceId);
        try {
            caches = parser.parse(instream, null);
            assertNotNull(caches);
            assertTrue(caches.size() > 0);
        } finally {
            instream.close();
        }

        return new ArrayList<Geocache>(caches);
    }

    public void testOCLoc() throws IOException, ParserException {
        final List<Geocache> caches = readLoc(R.raw.oc5952_loc);
        assertEquals(1, caches.size());
        final Geocache cache = caches.get(0);
        assertNotNull(cache);
        assertEquals("OC5952", cache.getGeocode());
        assertEquals("Die Schatzinsel / treasure island", cache.getName());
        assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName());
        assertEquals(new Geopoint(48.85968, 9.18740), cache.getCoords());
    }

    public void testGCLoc() throws IOException, ParserException {
        final List<Geocache> caches = readLoc(R.raw.gc1bkp3_loc);
        assertEquals(1, caches.size());
        final Geocache cache = caches.get(0);
        assertNotNull(cache);
        assertEquals("GC1BKP3", cache.getGeocode());
        assertEquals("Die Schatzinsel / treasure island", cache.getName());
        assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName());
        assertEquals(new Geopoint(48.859683, 9.1874), cache.getCoords());
        assertEquals(1.0f, cache.getDifficulty());
        assertEquals(5.0f, cache.getTerrain());
        assertEquals(CacheSize.MICRO, cache.getSize());
    }

    public void testWaymarkingLoc() throws IOException, ParserException {
        final List<Geocache> waymarks = readLoc(R.raw.waymarking_loc);
        assertEquals(1, waymarks.size());
        final Geocache waymark = waymarks.get(0);
        assertNotNull(waymark);
        assertEquals("WM7BK7", waymark.getGeocode());
        assertEquals("Römerstrasse Kornwestheim", waymark.getName());
        assertEquals("travelling", waymark.getOwnerDisplayName());
        assertEquals(new Geopoint(48.856733, 9.197683), waymark.getCoords());
        // links are not yet stored for single caches
        // assertEquals("http://www.waymarking.com/waymarks/WM7BK7_Rmerstrasse_Kornwestheim", waymark.getUrl());
        assertEquals(CacheSize.UNKNOWN, waymark.getSize());
        assertEquals(CacheType.UNKNOWN, waymark.getType());
    }

}