aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/export/ExportTest.java
blob: 7befacf090da5fb7df6a9048b525e47fa450940d (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
package cgeo.geocaching.export;

import cgeo.CGeoTestCase;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogEntry;
import cgeo.geocaching.cgData;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.geopoint.Geopoint;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

public class ExportTest extends CGeoTestCase {

    public static void testGSAKExport() {
        final Geocache cache = new Geocache();
        cache.setGeocode("GCX1234");
        final LogEntry log = new LogEntry(1353244820000L, LogType.FOUND_IT, "Hidden in a tree");
        final StringBuilder logStr = new StringBuilder();
        FieldnoteExport.appendFieldNote(logStr, cache, log);
        assertEquals("Non matching export " + logStr.toString(), "GCX1234,2012-11-18T13:20:20Z,Found it,\"Hidden in a tree\"\n", logStr.toString());
    }

    public static void testGpxExportSmilies() {
        final Geocache cache = new Geocache();
        cache.setGeocode("GCX1234");
        cache.setCoords(new Geopoint("N 49 44.000 E 8 37.000"));
        final LogEntry log = new LogEntry(1353244820000L, LogType.FOUND_IT, "Smile: \ud83d\ude0a");
        cache.getLogs().add(log);
        cgData.saveCache(cache, LoadFlags.SAVE_ALL);
        ArrayList<Geocache> exportList = new ArrayList<Geocache>();
        exportList.add(cache);
        GpxExportTester gpxExport = new GpxExportTester();
        File result = null;
        try {
            result = gpxExport.testExportSync(exportList);
        } catch (InterruptedException e) {
            fail(e.getCause().toString());
        } catch (ExecutionException e) {
            fail(e.getCause().toString());
        } finally {
            cgData.removeCache(cache.getGeocode(), LoadFlags.REMOVE_ALL);
        }

        assertNotNull(result);

        result.delete();
    }

    private static class GpxExportTester extends GpxExport {

        protected GpxExportTester() {
            super();
        }

        public File testExportSync(List<Geocache> caches) throws InterruptedException, ExecutionException {
            ExportTask task = new ExportTask(caches, null);

            task.execute((Void) null);

            return task.get();
        }

    }

}