aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/activity/waypoint/AbstractWaypointActivityTest.java
blob: 36c4302a29a0949cc67fc6908a3acba7d00a8650 (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
package cgeo.geocaching.activity.waypoint;

import static org.assertj.core.api.Assertions.assertThat;

import cgeo.geocaching.DataStore;
import cgeo.geocaching.EditWaypointActivity_;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.activity.AbstractEspressoTest;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;

import java.util.Collections;

public abstract class AbstractWaypointActivityTest extends AbstractEspressoTest<EditWaypointActivity_> {

    private Geocache cache;

    public AbstractWaypointActivityTest() {
        super(EditWaypointActivity_.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        cache = createTestCache();
        DataStore.saveCache(cache, Collections.singleton(SaveFlag.CACHE));
    }

    @Override
    protected void tearDown() throws Exception {
        removeTestCache();
        super.tearDown();
    }

    protected final Geocache getCache() {
        return cache;
    }

    private void removeTestCache() {
        DataStore.removeCache(cache.getGeocode(), LoadFlags.REMOVE_ALL);
        assertThat(DataStore.loadCache(cache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB)).isNull();
    }

    @SuppressWarnings("static-method")
    protected Geocache createTestCache() {
        Geocache testCache = new Geocache();
        testCache.setGeocode("TEST");
        testCache.setType(CacheType.TRADITIONAL);
        return testCache;
    }
}