aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-01-07 22:22:52 +0100
committerBananeweizen <bananeweizen@gmx.de>2013-01-07 22:22:52 +0100
commit60ef814599dfac0959eb1fea758916089c54845c (patch)
tree74b64354952be563ecc1b31bc88ed092a1820f33 /tests/src
parentfbae2b2f87ab1dbc7e912bea9310825d12c6beb5 (diff)
downloadcgeo-60ef814599dfac0959eb1fea758916089c54845c.zip
cgeo-60ef814599dfac0959eb1fea758916089c54845c.tar.gz
cgeo-60ef814599dfac0959eb1fea758916089c54845c.tar.bz2
fix test: some tests need mocked cache filters
* otherwise the options "exclude own" and "exclude disabled" lead to wrong results
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/cgeoApplicationTest.java175
1 files changed, 94 insertions, 81 deletions
diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
index 81c97ee..fbb860c 100644
--- a/tests/src/cgeo/geocaching/cgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
@@ -191,46 +191,60 @@ public class cgeoApplicationTest extends CGeoTestCase {
}
/**
- * Test {@link cgBase#searchByCoords(AbstractSearchThread, Geopoint, String, int, boolean)}
+ * mock the "exclude disabled caches" and "exclude my caches" options for the execution of the runnable
+ *
+ * @param runnable
*/
- @MediumTest
- public static void testSearchByCoords() {
+ private static void withMockedFilters(Runnable runnable) {
// backup user settings
final boolean excludeMine = Settings.isExcludeMyCaches();
+ final boolean excludeDisabled = Settings.isExcludeDisabledCaches();
try {
// set up settings required for test
Settings.setExcludeMine(false);
+ Settings.setExcludeDisabledCaches(false);
+
+ runnable.run();
- final SearchResult search = GCParser.searchByCoords(new Geopoint("N 52° 24.972 E 009° 35.647"), CacheType.MYSTERY, false);
- assertNotNull(search);
- assertTrue(20 <= search.getGeocodes().size());
- assertTrue(search.getGeocodes().contains("GC1RMM2"));
} finally {
// restore user settings
Settings.setExcludeMine(excludeMine);
+ Settings.setExcludeDisabledCaches(excludeDisabled);
}
}
/**
+ * Test {@link cgBase#searchByCoords(AbstractSearchThread, Geopoint, String, int, boolean)}
+ */
+ @MediumTest
+ public static void testSearchByCoords() {
+ withMockedFilters(new Runnable() {
+
+ @Override
+ public void run() {
+ final SearchResult search = GCParser.searchByCoords(new Geopoint("N 52° 24.972 E 009° 35.647"), CacheType.MYSTERY, false);
+ assertNotNull(search);
+ assertTrue(20 <= search.getGeocodes().size());
+ assertTrue(search.getGeocodes().contains("GC1RMM2"));
+ }
+ });
+ }
+
+ /**
* Test {@link cgBase#searchByOwner(String, String, int, boolean, CancellableHandler)}
*/
@MediumTest
public static void testSearchByOwner() {
- // backup user settings
- final boolean excludeMine = Settings.isExcludeMyCaches();
- try {
- // set up settings required for test
- Settings.setExcludeMine(false);
-
- final SearchResult search = GCParser.searchByOwner("blafoo", CacheType.MYSTERY, false);
- assertNotNull(search);
- assertEquals(3, search.getGeocodes().size());
- assertTrue(search.getGeocodes().contains("GC36RT6"));
-
- } finally {
- // restore user settings
- Settings.setExcludeMine(excludeMine);
- }
+ withMockedFilters(new Runnable() {
+
+ @Override
+ public void run() {
+ final SearchResult search = GCParser.searchByOwner("blafoo", CacheType.MYSTERY, false);
+ assertNotNull(search);
+ assertEquals(3, search.getGeocodes().size());
+ assertTrue(search.getGeocodes().contains("GC36RT6"));
+ }
+ });
}
/**
@@ -238,21 +252,16 @@ public class cgeoApplicationTest extends CGeoTestCase {
*/
@MediumTest
public static void testSearchByUsername() {
- // backup user settings
- final boolean excludeMine = Settings.isExcludeMyCaches();
- try {
- // set up settings required for test
- Settings.setExcludeMine(false);
-
- final SearchResult search = GCParser.searchByUsername("blafoo", CacheType.WEBCAM, false);
- assertNotNull(search);
- assertEquals(3, search.getTotal());
- assertTrue(search.getGeocodes().contains("GCP0A9"));
-
- } finally {
- // restore user settings
- Settings.setExcludeMine(excludeMine);
- }
+ withMockedFilters(new Runnable() {
+
+ @Override
+ public void run() {
+ final SearchResult search = GCParser.searchByUsername("blafoo", CacheType.WEBCAM, false);
+ assertNotNull(search);
+ assertEquals(3, search.getTotal());
+ assertTrue(search.getGeocodes().contains("GCP0A9"));
+ }
+ });
}
/**
@@ -260,50 +269,54 @@ public class cgeoApplicationTest extends CGeoTestCase {
*/
@MediumTest
public static void testSearchByViewport() {
- // backup user settings
- final boolean excludeMine = Settings.isExcludeMyCaches();
- final Strategy strategy = Settings.getLiveMapStrategy();
- final CacheType cacheType = Settings.getCacheType();
-
- try {
- // set up settings required for test
- Settings.setExcludeMine(false);
- Settings.setCacheType(CacheType.ALL);
-
- final GC2CJPF mockedCache = new GC2CJPF();
- deleteCacheFromDB(mockedCache.getGeocode());
-
- final String[] tokens = Login.getMapTokens();
- final Viewport viewport = new Viewport(mockedCache, 0.003, 0.003);
-
- // check coords for DETAILED
- Settings.setLiveMapStrategy(Strategy.DETAILED);
- SearchResult search = ConnectorFactory.searchByViewport(viewport, tokens);
- assertNotNull(search);
- assertTrue(search.getGeocodes().contains(mockedCache.getGeocode()));
- cgCache parsedCache = cgData.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB);
-
- assertEquals(Settings.isPremiumMember(), mockedCache.getCoords().equals(parsedCache.getCoords()));
- assertEquals(Settings.isPremiumMember(), parsedCache.isReliableLatLon());
-
- // check update after switch strategy to FAST
- Settings.setLiveMapStrategy(Strategy.FAST);
- Tile.Cache.removeFromTileCache(mockedCache);
-
- search = ConnectorFactory.searchByViewport(viewport, tokens);
- assertNotNull(search);
- assertTrue(search.getGeocodes().contains(mockedCache.getGeocode()));
- parsedCache = cgData.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB);
-
- assertEquals(Settings.isPremiumMember(), mockedCache.getCoords().equals(parsedCache.getCoords()));
- assertEquals(Settings.isPremiumMember(), parsedCache.isReliableLatLon());
-
- } finally {
- // restore user settings
- Settings.setExcludeMine(excludeMine);
- Settings.setLiveMapStrategy(strategy);
- Settings.setCacheType(cacheType);
- }
+ withMockedFilters(new Runnable() {
+
+ @Override
+ public void run() {
+ // backup user settings
+ final Strategy strategy = Settings.getLiveMapStrategy();
+ final CacheType cacheType = Settings.getCacheType();
+
+ try {
+ // set up settings required for test
+ Settings.setExcludeMine(false);
+ Settings.setCacheType(CacheType.ALL);
+
+ final GC2CJPF mockedCache = new GC2CJPF();
+ deleteCacheFromDB(mockedCache.getGeocode());
+
+ final String[] tokens = Login.getMapTokens();
+ final Viewport viewport = new Viewport(mockedCache, 0.003, 0.003);
+
+ // check coords for DETAILED
+ Settings.setLiveMapStrategy(Strategy.DETAILED);
+ SearchResult search = ConnectorFactory.searchByViewport(viewport, tokens);
+ assertNotNull(search);
+ assertTrue(search.getGeocodes().contains(mockedCache.getGeocode()));
+ cgCache parsedCache = cgData.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB);
+
+ assertEquals(Settings.isPremiumMember(), mockedCache.getCoords().equals(parsedCache.getCoords()));
+ assertEquals(Settings.isPremiumMember(), parsedCache.isReliableLatLon());
+
+ // check update after switch strategy to FAST
+ Settings.setLiveMapStrategy(Strategy.FAST);
+ Tile.Cache.removeFromTileCache(mockedCache);
+
+ search = ConnectorFactory.searchByViewport(viewport, tokens);
+ assertNotNull(search);
+ assertTrue(search.getGeocodes().contains(mockedCache.getGeocode()));
+ parsedCache = cgData.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB);
+
+ assertEquals(Settings.isPremiumMember(), mockedCache.getCoords().equals(parsedCache.getCoords()));
+ assertEquals(Settings.isPremiumMember(), parsedCache.isReliableLatLon());
+
+ } finally {
+ // restore user settings
+ Settings.setLiveMapStrategy(strategy);
+ Settings.setCacheType(cacheType);
+ }
+ }
+ });
}
/**