diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/CgeoApplicationTest.java')
| -rw-r--r-- | tests/src/cgeo/geocaching/CgeoApplicationTest.java | 131 |
1 files changed, 65 insertions, 66 deletions
diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java index 34ca5eb..3e63481 100644 --- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java @@ -1,5 +1,7 @@ package cgeo.geocaching; +import static org.assertj.core.api.Assertions.assertThat; + import cgeo.CGeoTestCase; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.gc.GCLogin; @@ -26,7 +28,6 @@ import cgeo.geocaching.utils.CancellableHandler; import cgeo.geocaching.utils.Log; import cgeo.test.Compare; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import android.test.suitebuilder.annotation.MediumTest; @@ -34,8 +35,6 @@ import android.test.suitebuilder.annotation.SmallTest; import java.util.GregorianCalendar; -import junit.framework.Assert; - /** * The c:geo application test. It can be used for tests that require an * application and/or context. @@ -54,7 +53,7 @@ public class CgeoApplicationTest extends CGeoTestCase { @SuppressWarnings("static-method") @SmallTest public void testPreconditions() { - assertEquals(StatusCode.NO_ERROR, GCLogin.getInstance().login()); + assertEquals("Login to Geocaching.com failed", StatusCode.NO_ERROR, GCLogin.getInstance().login()); } /** @@ -63,7 +62,7 @@ public class CgeoApplicationTest extends CGeoTestCase { @MediumTest public static void testSearchTrackableNotExisting() { final Trackable tb = GCParser.searchTrackable("123456", null, null); - assertNull(tb); + assertThat(tb).isNull(); } /** @@ -72,37 +71,37 @@ public class CgeoApplicationTest extends CGeoTestCase { @MediumTest public static void testSearchTrackable() { final Trackable tb = GCParser.searchTrackable("TB2J1VZ", null, null); - assertNotNull(tb); + assertThat(tb).isNotNull(); assert (tb != null); // eclipse bug // fix data - assertEquals("aefffb86-099f-444f-b132-605436163aa8", tb.getGuid()); - assertEquals("TB2J1VZ", tb.getGeocode()); - assertEquals("http://www.geocaching.com/images/wpttypes/21.gif", tb.getIconUrl()); - assertEquals("blafoo's Children Music CD", tb.getName()); - assertEquals("Travel Bug Dog Tag", tb.getType()); + assertThat(tb.getGuid()).isEqualTo("aefffb86-099f-444f-b132-605436163aa8"); + assertThat(tb.getGeocode()).isEqualTo("TB2J1VZ"); + assertThat(tb.getIconUrl()).isEqualTo("http://www.geocaching.com/images/wpttypes/21.gif"); + assertThat(tb.getName()).isEqualTo("blafoo's Children Music CD"); + assertThat(tb.getType()).isEqualTo("Travel Bug Dog Tag"); assertEquals(new GregorianCalendar(2009, 8 - 1, 24).getTime(), tb.getReleased()); assertEquals("Niedersachsen, Germany", tb.getOrigin()); - assertEquals("blafoo", tb.getOwner()); - assertEquals("0564a940-8311-40ee-8e76-7e91b2cf6284", tb.getOwnerGuid()); - assertEquals("Kinder erfreuen.<br /><br />Make children happy.", tb.getGoal()); - assertTrue(tb.getDetails().startsWith("Auf der CD sind")); - assertEquals("http://imgcdn.geocaching.com/track/display/38382780-87a7-4393-8393-78841678ee8c.jpg", tb.getImage()); + assertThat(tb.getOwner()).isEqualTo("blafoo"); + 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/display/38382780-87a7-4393-8393-78841678ee8c.jpg"); // Following data can change over time - assertTrue(tb.getDistance() >= 10617.8f); - assertTrue(tb.getLogs().size() >= 10); - assertTrue(Trackable.SPOTTED_CACHE == tb.getSpottedType() || Trackable.SPOTTED_USER == tb.getSpottedType() || Trackable.SPOTTED_UNKNOWN == tb.getSpottedType()); - // no assumption possible: assertEquals("faa2d47d-19ea-422f-bec8-318fc82c8063", tb.getSpottedGuid()); - // no assumption possible: assertEquals("Nice place for a break cache", tb.getSpottedName()); + assertThat(tb.getDistance()).isGreaterThanOrEqualTo(10617.8f); + assertThat(tb.getLogs().size()).isGreaterThanOrEqualTo(10); + assertThat(Trackable.SPOTTED_CACHE == tb.getSpottedType() || Trackable.SPOTTED_USER == tb.getSpottedType() || Trackable.SPOTTED_UNKNOWN == tb.getSpottedType()).isTrue(); + // no assumption possible: assertThat(tb.getSpottedGuid()).isEqualTo("faa2d47d-19ea-422f-bec8-318fc82c8063"); + // 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()) { - assertTrue(log.date > 0); - assertTrue(StringUtils.isNotEmpty(log.author)); + assertThat(log.date).isGreaterThan(0); + assertThat(log.author).isNotEmpty(); if (log.type == LogType.PLACED_IT || log.type == LogType.RETRIEVED_IT) { - assertTrue(StringUtils.isNotEmpty(log.cacheName)); - assertTrue(StringUtils.isNotEmpty(log.cacheGuid)); + assertThat(log.cacheName).isNotEmpty(); + assertThat(log.cacheGuid).isNotEmpty(); } else { - assertTrue(log.type != LogType.UNKNOWN); + assertThat(log.type).isNotEqualTo(LogType.UNKNOWN); } } } @@ -113,13 +112,13 @@ public class CgeoApplicationTest extends CGeoTestCase { @MediumTest public static Geocache testSearchByGeocode(final String geocode) { final SearchResult search = Geocache.searchByGeocode(geocode, null, 0, true, null); - assertNotNull(search); + assertThat(search).isNotNull(); if (Settings.isGCPremiumMember() || search.getError() == null) { - assertEquals(1, search.getGeocodes().size()); - assertTrue(search.getGeocodes().contains(geocode)); + assertThat(search.getGeocodes()).hasSize(1); + assertThat(search.getGeocodes()).contains(geocode); return DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); } - assertEquals(0, search.getGeocodes().size()); + assertThat(search.getGeocodes()).isEmpty(); return null; } @@ -129,8 +128,8 @@ public class CgeoApplicationTest extends CGeoTestCase { @MediumTest public static void testSearchByGeocodeNotExisting() { final SearchResult search = Geocache.searchByGeocode("GC123456", null, 0, true, null); - assertNotNull(search); - assertEquals(StatusCode.COMMUNICATION_ERROR, search.getError()); + assertThat(search).isNotNull(); + assertThat(search.getError()).isEqualTo(StatusCode.COMMUNICATION_ERROR); } /** @@ -166,14 +165,14 @@ public class CgeoApplicationTest extends CGeoTestCase { deleteCacheFromDBAndLogout(cache.getGeocode()); SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); - assertNotNull(search); - assertEquals(1, search.getGeocodes().size()); - assertTrue(search.getGeocodes().contains(cache.getGeocode())); + 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 - assertNotNull(searchedCache); + assertThat(searchedCache).isNotNull(); assert (searchedCache != null); // eclipse bug - assertNull(searchedCache.getCoords()); + assertThat(searchedCache.getCoords()).isNull(); // premium cache. Not visible to guests cache = new GC2JVEH(); @@ -181,8 +180,8 @@ public class CgeoApplicationTest extends CGeoTestCase { deleteCacheFromDBAndLogout(cache.getGeocode()); search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); - assertNotNull(search); - assertEquals(0, search.getGeocodes().size()); + assertThat(search).isNotNull(); + assertThat(search.getGeocodes()).isEmpty(); } }); } @@ -201,8 +200,8 @@ public class CgeoApplicationTest extends CGeoTestCase { deleteCacheFromDBAndLogout(cache.getGeocode()); final SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); - assertNotNull(search); - assertEquals(0, search.getGeocodes().size()); + assertThat(search).isNotNull(); + assertThat(search.getGeocodes()).isEmpty(); } }); } @@ -240,9 +239,9 @@ public class CgeoApplicationTest extends CGeoTestCase { @Override public void run() { final SearchResult search = GCParser.searchByCoords(new Geopoint("N 50° 06.654 E 008° 39.777"), CacheType.MYSTERY, false, null); - assertNotNull(search); - assertTrue(20 <= search.getGeocodes().size()); - assertTrue(search.getGeocodes().contains("GC1HBMY")); + assertThat(search).isNotNull(); + assertThat(20 <= search.getGeocodes().size()).isTrue(); + assertThat(search.getGeocodes().contains("GC1HBMY")).isTrue(); } }); } @@ -257,9 +256,9 @@ public class CgeoApplicationTest extends CGeoTestCase { @Override public void run() { final SearchResult search = GCParser.searchByOwner("blafoo", CacheType.MYSTERY, false, null); - assertNotNull(search); - assertEquals(3, search.getGeocodes().size()); - assertTrue(search.getGeocodes().contains("GC36RT6")); + assertThat(search).isNotNull(); + assertThat(search.getGeocodes()).hasSize(3); + assertThat(search.getGeocodes().contains("GC36RT6")).isTrue(); } }); } @@ -274,9 +273,9 @@ public class CgeoApplicationTest extends CGeoTestCase { @Override public void run() { final SearchResult search = GCParser.searchByUsername("blafoo", CacheType.WEBCAM, false, null); - assertNotNull(search); - assertEquals(4, search.getTotalCountGC()); - assertTrue(search.getGeocodes().contains("GCP0A9")); + assertThat(search).isNotNull(); + assertThat(search.getTotalCountGC()).isEqualTo(4); + assertThat(search.getGeocodes().contains("GCP0A9")).isTrue(); } }); } @@ -308,24 +307,24 @@ public class CgeoApplicationTest extends CGeoTestCase { // check coords for DETAILED Settings.setLiveMapStrategy(Strategy.DETAILED); SearchResult search = ConnectorFactory.searchByViewport(viewport, tokens); - assertNotNull(search); - assertTrue(search.getGeocodes().contains(mockedCache.getGeocode())); + assertThat(search).isNotNull(); + assertThat(search.getGeocodes().contains(mockedCache.getGeocode())).isTrue(); Geocache parsedCache = DataStore.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); - assertEquals(Settings.isGCPremiumMember(), mockedCache.getCoords().equals(parsedCache.getCoords())); - assertEquals(Settings.isGCPremiumMember(), parsedCache.isReliableLatLon()); + 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); Tile.cache.removeFromTileCache(mockedCache); search = ConnectorFactory.searchByViewport(viewport, tokens); - assertNotNull(search); - assertTrue(search.getGeocodes().contains(mockedCache.getGeocode())); + assertThat(search).isNotNull(); + assertThat(search.getGeocodes().contains(mockedCache.getGeocode())).isTrue(); parsedCache = DataStore.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); - assertEquals(Settings.isGCPremiumMember(), mockedCache.getCoords().equals(parsedCache.getCoords())); - assertEquals(Settings.isGCPremiumMember(), parsedCache.isReliableLatLon()); + assertThat(mockedCache.getCoords().equals(parsedCache.getCoords())).isEqualTo(Settings.isGCPremiumMember()); + assertThat(parsedCache.isReliableLatLon()).isEqualTo(Settings.isGCPremiumMember()); } finally { // restore user settings @@ -360,15 +359,15 @@ public class CgeoApplicationTest extends CGeoTestCase { Viewport viewport = new Viewport(cache, 0.003, 0.003); SearchResult search = ConnectorFactory.searchByViewport(viewport, INVALID_TOKEN); - assertNotNull(search); - assertTrue(search.getGeocodes().contains(cache.getGeocode())); + assertThat(search).isNotNull(); + assertThat(search.getGeocodes().contains(cache.getGeocode())).isTrue(); // coords differ final Geocache cacheFromViewport = DataStore.loadCache(cache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); Log.d("cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords expected = " + cache.getCoords()); Log.d("cgeoApplicationTest.testSearchByViewportNotLoggedIn: Coords actual = " + cacheFromViewport.getCoords()); - assertFalse(cache.getCoords().distanceTo(cacheFromViewport.getCoords()) <= 1e-3); + assertThat(cache.getCoords().distanceTo(cacheFromViewport.getCoords()) <= 1e-3).isFalse(); // depending on the chosen strategy the coords can be reliable or not - assertEquals(testStrategy == Strategy.DETAILED, cacheFromViewport.isReliableLatLon()); + assertThat(cacheFromViewport.isReliableLatLon()).isEqualTo(testStrategy == Strategy.DETAILED); // premium cache cache = new GC2JVEH(); @@ -377,9 +376,9 @@ public class CgeoApplicationTest extends CGeoTestCase { viewport = new Viewport(cache, 0.003, 0.003); search = ConnectorFactory.searchByViewport(viewport, INVALID_TOKEN); - assertNotNull(search); + assertThat(search).isNotNull(); // In the meantime, premium-member caches are also shown on map when not logged in - assertTrue(search.getGeocodes().contains(cache.getGeocode())); + assertThat(search.getGeocodes().contains(cache.getGeocode())).isTrue(); } finally { Settings.setLiveMapStrategy(strategy); @@ -416,10 +415,10 @@ public class CgeoApplicationTest extends CGeoTestCase { */ public static void testSearchByGeocodeSpecialties() { final Geocache GCV2R9 = CgeoApplicationTest.testSearchByGeocode("GCV2R9"); - Assert.assertEquals("California, United States", GCV2R9.getLocation()); + assertEquals("California, United States", GCV2R9.getLocation()); final Geocache GC1ZXEZ = CgeoApplicationTest.testSearchByGeocode("GC1ZXEZ"); - Assert.assertEquals("Ms.Marple/Mr.Stringer", GC1ZXEZ.getOwnerUserId()); + assertThat(GC1ZXEZ.getOwnerUserId()).isEqualTo("Ms.Marple/Mr.Stringer"); } /** Remove cache from DB and cache to ensure that the cache is not loaded from the database */ |
