aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java
blob: 88873a19d4373dc48a37fa7a1aa5d0609e99c0fb (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
package cgeo.geocaching.connector.gc;

import cgeo.geocaching.SearchResult;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.test.mock.GC2CJPF;
import cgeo.geocaching.test.mock.MockedCache;
import cgeo.test.Compare;

import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

public class GCBaseTest extends TestCase {

    public static void testSplitJSONKey() {
        assertKey("(1, 2)", 1, 2);
        assertKey("(12, 34)", 12, 34);
        assertKey("(1234,56)", 1234, 56);
        assertKey("(1234,  567)", 1234, 567);
    }

    private static void assertKey(String key, int x, int y) {
        UTFGridPosition pos = UTFGridPosition.fromString(key);
        assertEquals(x, pos.getX());
        assertEquals(y, pos.getY());
    }

    public static void testSearchByGeocodes() {

        MockedCache mockedCache = new GC2CJPF();

        Set<String> geocodes = new HashSet<String>();
        geocodes.add(mockedCache.getGeocode());

        SearchResult result = GCBase.searchByGeocodes(geocodes);
        cgCache parsedCache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);

        Compare.assertCompareCaches(mockedCache, parsedCache, false);

    }
}