diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/CgeoApplicationTest.java')
-rw-r--r-- | tests/src/cgeo/geocaching/CgeoApplicationTest.java | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java index de3f4ba..6763d7b 100644 --- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java @@ -9,14 +9,14 @@ import cgeo.geocaching.connector.gc.GCParser; import cgeo.geocaching.connector.gc.MapTokens; import cgeo.geocaching.connector.gc.Tile; import cgeo.geocaching.enumerations.CacheType; -import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.StatusCode; -import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.loaders.RecaptchaReceiver; +import cgeo.geocaching.location.Geopoint; +import cgeo.geocaching.location.Viewport; +import cgeo.geocaching.maps.LivemapStrategy; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.TestSettings; import cgeo.geocaching.test.RegExPerformanceTest; @@ -72,7 +72,7 @@ public class CgeoApplicationTest extends CGeoTestCase { public static void testSearchTrackable() { final Trackable tb = GCParser.searchTrackable("TB2J1VZ", null, null); assertThat(tb).isNotNull(); - assert (tb != null); // eclipse bug + assert tb != null; // eclipse bug // fix data assertThat(tb.getGuid()).isEqualTo("aefffb86-099f-444f-b132-605436163aa8"); assertThat(tb.getGeocode()).isEqualTo("TB2J1VZ"); @@ -85,7 +85,8 @@ public class CgeoApplicationTest extends CGeoTestCase { assertThat(tb.getOwnerGuid()).isEqualTo("0564a940-8311-40ee-8e76-7e91b2cf6284"); assertThat(tb.getGoal()).isEqualTo("Kinder erfreuen.<br /><br />Make children happy."); assertThat(tb.getDetails()).startsWith("Auf der CD sind"); - assertThat(tb.getImage()).isEqualTo("http://imgcdn.geocaching.com/track/large/38382780-87a7-4393-8393-78841678ee8c.jpg"); + // the host of the image can vary + assertThat(tb.getImage()).endsWith("geocaching.com/track/large/38382780-87a7-4393-8393-78841678ee8c.jpg"); // Following data can change over time assertThat(tb.getDistance()).isGreaterThanOrEqualTo(10617.8f); assertThat(tb.getLogs().size()).isGreaterThanOrEqualTo(10); @@ -94,7 +95,7 @@ public class CgeoApplicationTest extends CGeoTestCase { // no assumption possible: assertThat(tb.getSpottedName()).isEqualTo("Nice place for a break cache"); // we can't check specifics in the log entries since they change, but we can verify data was parsed - for (LogEntry log : tb.getLogs()) { + for (final LogEntry log : tb.getLogs()) { assertThat(log.date).isGreaterThan(0); assertThat(log.author).isNotEmpty(); if (log.type == LogType.PLACED_IT || log.type == LogType.RETRIEVED_IT) { @@ -107,7 +108,7 @@ public class CgeoApplicationTest extends CGeoTestCase { } /** - * Test {@link GCParser#searchByGeocode(String, String, int, boolean, CancellableHandler)} + * Test {@link Geocache#searchByGeocode(String, String, int, boolean, CancellableHandler)} */ @MediumTest public static Geocache testSearchByGeocode(final String geocode) { @@ -135,7 +136,6 @@ public class CgeoApplicationTest extends CGeoTestCase { /** * Set the login data to the cgeo login, run the given Runnable, and restore the login. * - * @param runnable */ private static void withMockedLoginDo(final Runnable runnable) { final ImmutablePair<String, String> login = Settings.getGcCredentials(); @@ -165,14 +165,14 @@ public class CgeoApplicationTest extends CGeoTestCase { deleteCacheFromDBAndLogout(cache.getGeocode()); - SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); + SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST.id, true, null); assertThat(search).isNotNull(); assertThat(search.getGeocodes()).hasSize(1); assertThat(search.getGeocodes().contains(cache.getGeocode())).isTrue(); final Geocache searchedCache = search.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); // coords must be null if the user is not logged in assertThat(searchedCache).isNotNull(); - assert (searchedCache != null); // eclipse bug + assert searchedCache != null; // eclipse bug assertThat(searchedCache.getCoords()).isNull(); // premium cache. Not visible to guests @@ -180,7 +180,7 @@ public class CgeoApplicationTest extends CGeoTestCase { deleteCacheFromDBAndLogout(cache.getGeocode()); - search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); + search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST.id, true, null); assertThat(search).isNotNull(); assertThat(search.getGeocodes()).isEmpty(); } @@ -201,7 +201,7 @@ public class CgeoApplicationTest extends CGeoTestCase { deleteCacheFromDBAndLogout(cache.getGeocode()); - final SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); + final SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST.id, true, null); assertThat(search).isNotNull(); assertThat(search.getGeocodes()).isEmpty(); } @@ -211,9 +211,8 @@ public class CgeoApplicationTest extends CGeoTestCase { /** * mock the "exclude disabled caches" and "exclude my caches" options for the execution of the runnable * - * @param runnable */ - private static void withMockedFilters(Runnable runnable) { + private static void withMockedFilters(final Runnable runnable) { // backup user settings final boolean excludeMine = Settings.isExcludeMyCaches(); final boolean excludeDisabled = Settings.isExcludeDisabledCaches(); @@ -276,14 +275,14 @@ public class CgeoApplicationTest extends CGeoTestCase { public void run() { final SearchResult search = GCParser.searchByUsername("blafoo", CacheType.WEBCAM, false, null); assertThat(search).isNotNull(); - assertThat(search.getTotalCountGC()).isEqualTo(4); + assertThat(search.getTotalCountGC()).isEqualTo(5); assertThat(search.getGeocodes().contains("GCP0A9")).isTrue(); } }); } /** - * Test {@link ConnectorFactory#searchByViewport(Viewport, String)} + * Test {@link ConnectorFactory#searchByViewport(Viewport, MapTokens)} */ @MediumTest public static void testSearchByViewport() { @@ -292,7 +291,7 @@ public class CgeoApplicationTest extends CGeoTestCase { @Override public void run() { // backup user settings - final Strategy strategy = Settings.getLiveMapStrategy(); + final LivemapStrategy strategy = Settings.getLiveMapStrategy(); final CacheType cacheType = Settings.getCacheType(); try { @@ -307,23 +306,27 @@ public class CgeoApplicationTest extends CGeoTestCase { final Viewport viewport = new Viewport(mockedCache, 0.003, 0.003); // check coords for DETAILED - Settings.setLiveMapStrategy(Strategy.DETAILED); + Settings.setLiveMapStrategy(LivemapStrategy.DETAILED); SearchResult search = ConnectorFactory.searchByViewport(viewport, tokens); assertThat(search).isNotNull(); assertThat(search.getGeocodes().contains(mockedCache.getGeocode())).isTrue(); Geocache parsedCache = DataStore.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); + assert parsedCache != null; + assertThat(parsedCache).isNotNull(); assertThat(mockedCache.getCoords().equals(parsedCache.getCoords())).isEqualTo(Settings.isGCPremiumMember()); assertThat(parsedCache.isReliableLatLon()).isEqualTo(Settings.isGCPremiumMember()); // check update after switch strategy to FAST - Settings.setLiveMapStrategy(Strategy.FAST); + Settings.setLiveMapStrategy(LivemapStrategy.FAST); Tile.cache.removeFromTileCache(mockedCache); search = ConnectorFactory.searchByViewport(viewport, tokens); assertThat(search).isNotNull(); assertThat(search.getGeocodes().contains(mockedCache.getGeocode())).isTrue(); parsedCache = DataStore.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); + assert parsedCache != null; + assertThat(parsedCache).isNotNull(); assertThat(mockedCache.getCoords().equals(parsedCache.getCoords())).isEqualTo(Settings.isGCPremiumMember()); assertThat(parsedCache.isReliableLatLon()).isEqualTo(Settings.isGCPremiumMember()); @@ -338,7 +341,7 @@ public class CgeoApplicationTest extends CGeoTestCase { } /** - * Test {@link ConnectorFactory#searchByViewport(Viewport, String)} + * Test {@link ConnectorFactory#searchByViewport(Viewport, MapTokens)} */ @MediumTest public static void testSearchByViewportNotLoggedIn() { @@ -346,8 +349,8 @@ public class CgeoApplicationTest extends CGeoTestCase { @Override public void run() { - final Strategy strategy = Settings.getLiveMapStrategy(); - final Strategy testStrategy = Strategy.FAST; // FASTEST, FAST or DETAILED for tests + final LivemapStrategy strategy = Settings.getLiveMapStrategy(); + final LivemapStrategy testStrategy = LivemapStrategy.FAST; // FASTEST, FAST or DETAILED for tests Settings.setLiveMapStrategy(testStrategy); final CacheType cacheType = Settings.getCacheType(); @@ -366,11 +369,13 @@ public class CgeoApplicationTest extends CGeoTestCase { assertThat(search.getGeocodes().contains(cache.getGeocode())).isTrue(); // coords differ final Geocache cacheFromViewport = DataStore.loadCache(cache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); + assert cacheFromViewport != null; + assertThat(cacheFromViewport).isNotNull(); Log.d("cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords expected = " + cache.getCoords()); Log.d("cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords actual = " + cacheFromViewport.getCoords()); assertThat(cache.getCoords().distanceTo(cacheFromViewport.getCoords()) <= 1e-3).isFalse(); // depending on the chosen strategy the coords can be reliable or not - assertThat(cacheFromViewport.isReliableLatLon()).isEqualTo(testStrategy == Strategy.DETAILED); + assertThat(cacheFromViewport.isReliableLatLon()).isEqualTo(testStrategy == LivemapStrategy.DETAILED); // premium cache cache = new GC2JVEH(); @@ -395,18 +400,12 @@ public class CgeoApplicationTest extends CGeoTestCase { * Test cache parsing. Esp. useful after a GC.com update */ public static void testSearchByGeocodeBasis() { - for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) { - String oldUser = mockedCache.getMockedDataUser(); + for (final MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) { + final String oldUser = mockedCache.getMockedDataUser(); try { mockedCache.setMockedDataUser(Settings.getUsername()); - Geocache parsedCache = CgeoApplicationTest.testSearchByGeocode(mockedCache.getGeocode()); - if (null != parsedCache) { - // fake found flag for one cache until it will be updated - if (parsedCache.getGeocode().equals("GC3XX5J") && Settings.getUsername().equals("mucek4")) { - parsedCache.setFound(false); - } - Compare.assertCompareCaches(mockedCache, parsedCache, true); - } + final Geocache parsedCache = CgeoApplicationTest.testSearchByGeocode(mockedCache.getGeocode()); + Compare.assertCompareCaches(mockedCache, parsedCache, true); } finally { mockedCache.setMockedDataUser(oldUser); } @@ -425,7 +424,7 @@ public class CgeoApplicationTest extends CGeoTestCase { } /** Remove cache from DB and cache to ensure that the cache is not loaded from the database */ - private static void deleteCacheFromDBAndLogout(String geocode) { + private static void deleteCacheFromDBAndLogout(final String geocode) { deleteCacheFromDB(geocode); GCLogin.getInstance().logout(); |