diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/GeocacheTest.java')
-rw-r--r-- | tests/src/cgeo/geocaching/GeocacheTest.java | 174 |
1 files changed, 110 insertions, 64 deletions
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java index b3ec6be..26c677d 100644 --- a/tests/src/cgeo/geocaching/GeocacheTest.java +++ b/tests/src/cgeo/geocaching/GeocacheTest.java @@ -5,13 +5,14 @@ import static org.assertj.core.api.Assertions.assertThat; import cgeo.CGeoTestCase; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LogType; -import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.StoredList; +import cgeo.geocaching.location.Geopoint; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -66,13 +67,12 @@ public class GeocacheTest extends CGeoTestCase { } private void assertWaypointsParsed(final String note, final int expectedWaypoints) { - recordMapStoreFlags(); try { setMapStoreFlags(false, false); - Geocache cache = new Geocache(); + final Geocache cache = new Geocache(); final String geocode = "Test" + System.nanoTime(); cache.setGeocode(geocode); cache.setWaypoints(new ArrayList<Waypoint>(), false); @@ -86,7 +86,7 @@ public class GeocacheTest extends CGeoTestCase { assertThat(waypoint.getCoords()).isEqualTo(new Geopoint("N51 13.888 E007 03.444")); // assertThat(waypoint.getNote()).isEqualTo("Test"); assertThat(waypoint.getName()).isEqualTo(CgeoApplication.getInstance().getString(R.string.cache_personal_note) + " 1"); - cache.store(StoredList.TEMPORARY_LIST_ID, null); + cache.store(StoredList.TEMPORARY_LIST.id, null); } removeCacheCompletely(geocode); } finally { @@ -94,52 +94,106 @@ public class GeocacheTest extends CGeoTestCase { } } - public static void testMergeDownloadedStored() { + public static void testMergeDownloaded() { + final Geocache previous = new Geocache(); + previous.setGeocode("GC12345"); + previous.setDetailed(true); + previous.setDisabled(true); + previous.setType(CacheType.TRADITIONAL); + previous.setCoords(new Geopoint(40.0, 8.0)); + previous.setDescription("Test1"); + previous.setAttributes(Collections.singletonList("TestAttribute")); + previous.setShortDescription("Short"); + previous.setHint("Hint"); + removeCacheCompletely(previous.getGeocode()); + + final Geocache download = new Geocache(); + download.setGeocode("GC12345"); + download.setDetailed(true); + download.setDisabled(false); + download.setType(CacheType.MULTI); + download.setCoords(new Geopoint(41.0, 9.0)); + download.setDescription("Test2"); - Geocache stored = new Geocache(); + download.gatherMissingFrom(previous); + + assertThat(download.isDetailed()).as("merged detailed").isTrue(); + assertThat(download.isDisabled()).as("merged disabled").isFalse(); + assertThat(download.getType()).as("merged download").isEqualTo(CacheType.MULTI); + assertThat(download.getCoords()).as("merged coordinates").isEqualTo(new Geopoint(41.0, 9.0)); + assertThat(download.getDescription()).as("merged description").isEqualTo("Test2"); + assertThat(download.getShortDescription()).as("merged short description").isEmpty(); + assertThat(download.getAttributes()).as("merged attributes").isEmpty(); + assertThat(download.getHint()).as("merged hint").isEmpty(); + } + + public static void testMergeDownloadedStored() { + final Geocache stored = new Geocache(); stored.setGeocode("GC12345"); stored.setDetailed(true); stored.setDisabled(true); stored.setType(CacheType.TRADITIONAL); stored.setCoords(new Geopoint(40.0, 8.0)); stored.setDescription("Test1"); - ArrayList<String> attributes = new ArrayList<String>(1); - attributes.add("TestAttribute"); - stored.setAttributes(attributes); + stored.setAttributes(Collections.singletonList("TestAttribute")); stored.setShortDescription("Short"); stored.setHint("Hint"); + saveFreshCacheToDB(stored); - Geocache download = new Geocache(); + final Geocache download = new Geocache(); download.setGeocode("GC12345"); download.setDetailed(true); download.setDisabled(false); download.setType(CacheType.MULTI); download.setCoords(new Geopoint(41.0, 9.0)); download.setDescription("Test2"); + download.setAttributes(Collections.<String>emptyList()); download.gatherMissingFrom(stored); assertThat(download.isDetailed()).as("merged detailed").isTrue(); assertThat(download.isDisabled()).as("merged disabled").isFalse(); - assertEquals("Type not merged correctly", CacheType.MULTI, download.getType()); - assertEquals("Longitude not merged correctly", 9.0, download.getCoords().getLongitude(), 0.1); - assertEquals("Latitude not merged correctly", 41.0, download.getCoords().getLatitude(), 0.1); - assertEquals("Description not merged correctly", "Test2", download.getDescription()); - assertEquals("ShortDescription not merged correctly", "", download.getShortDescription()); - assertEquals("Attributes not merged correctly", new ArrayList<String>(0), download.getAttributes()); - assertEquals("Hint not merged correctly", "", download.getHint()); + assertThat(download.getType()).as("merged download").isEqualTo(CacheType.MULTI); + assertThat(download.getCoords()).as("merged coordinates").isEqualTo(new Geopoint(41.0, 9.0)); + assertThat(download.getDescription()).as("merged description").isEqualTo("Test2"); + assertThat(download.getShortDescription()).as("merged short description").isEmpty(); + assertThat(download.getAttributes()).as("merged attributes").isEmpty(); + assertThat(download.getHint()).as("merged hint").isEmpty(); } - public static void testMergeLivemapStored() { + public static void testMergeLivemap() { + final Geocache previous = new Geocache(); + previous.setGeocode("GC12345"); + previous.setDetailed(true); + previous.setDisabled(true); + previous.setType(CacheType.TRADITIONAL); + previous.setCoords(new Geopoint(40.0, 8.0)); + removeCacheCompletely(previous.getGeocode()); + + final Geocache livemap = new Geocache(); + livemap.setGeocode("GC12345"); + livemap.setType(CacheType.MULTI, 12); + livemap.setCoords(new Geopoint(41.0, 9.0), 12); + + livemap.gatherMissingFrom(previous); + + assertThat(livemap.isDetailed()).as("merged detailed").isTrue(); + assertThat(livemap.isDisabled()).as("merged disabled").isTrue(); + assertThat(livemap.getType()).as("merged type").isEqualTo(CacheType.TRADITIONAL); + assertThat(livemap.getCoords()).as("merged coordinates").isEqualToComparingFieldByField(new Geopoint(40.0, 8.0)); + assertThat(livemap.getCoordZoomLevel()).as("merged zoomlevel").isEqualTo(previous.getCoordZoomLevel()); + } - Geocache stored = new Geocache(); + public static void testMergeLivemapStored() { + final Geocache stored = new Geocache(); stored.setGeocode("GC12345"); stored.setDetailed(true); stored.setDisabled(true); stored.setType(CacheType.TRADITIONAL); stored.setCoords(new Geopoint(40.0, 8.0)); + saveFreshCacheToDB(stored); - Geocache livemap = new Geocache(); + final Geocache livemap = new Geocache(); livemap.setGeocode("GC12345"); livemap.setType(CacheType.MULTI, 12); livemap.setCoords(new Geopoint(41.0, 9.0), 12); @@ -148,90 +202,81 @@ public class GeocacheTest extends CGeoTestCase { assertThat(livemap.isDetailed()).as("merged detailed").isTrue(); assertThat(livemap.isDisabled()).as("merged disabled").isTrue(); - assertEquals("Type not merged correctly", CacheType.TRADITIONAL, livemap.getType()); - assertEquals("Longitude not merged correctly", 8.0, livemap.getCoords().getLongitude(), 0.1); - assertEquals("Latitude not merged correctly", 40.0, livemap.getCoords().getLatitude(), 0.1); - assertEquals("Zoomlevel not merged correctly", stored.getCoordZoomLevel(), livemap.getCoordZoomLevel()); + assertThat(livemap.getType()).as("merged type").isEqualTo(CacheType.TRADITIONAL); + assertThat(livemap.getCoords()).as("merged coordinates").isEqualToComparingFieldByField(new Geopoint(40.0, 8.0)); + assertThat(livemap.getCoordZoomLevel()).as("merged zoomlevel").isEqualTo(stored.getCoordZoomLevel()); } public static void testMergeLivemapZoomin() { - - Geocache livemapFirst = new Geocache(); + final Geocache livemapFirst = new Geocache(); livemapFirst.setGeocode("GC12345"); livemapFirst.setType(CacheType.TRADITIONAL); livemapFirst.setCoords(new Geopoint(40.0, 8.0), 11); - Geocache livemapSecond = new Geocache(); + final Geocache livemapSecond = new Geocache(); livemapSecond.setGeocode("GC12345"); livemapSecond.setType(CacheType.MULTI); livemapSecond.setCoords(new Geopoint(41.0, 9.0), 12); livemapSecond.gatherMissingFrom(livemapFirst); - assertEquals("Type not merged correctly", CacheType.MULTI, livemapSecond.getType()); - assertEquals("Longitude not merged correctly", 9.0, livemapSecond.getCoords().getLongitude(), 0.1); - assertEquals("Latitude not merged correctly", 41.0, livemapSecond.getCoords().getLatitude(), 0.1); - assertEquals("Zoomlevel not merged correctly", 12, livemapSecond.getCoordZoomLevel()); + assertThat(livemapSecond.getType()).as("merged type").isEqualTo(CacheType.MULTI); + assertThat(livemapSecond.getCoords()).as("merged coordinates").isEqualTo(new Geopoint(41.0, 9.0)); + assertThat(livemapSecond.getCoordZoomLevel()).as("merged zoomlevel").isEqualTo(12); } public static void testMergeLivemapZoomout() { - - Geocache livemapFirst = new Geocache(); + final Geocache livemapFirst = new Geocache(); livemapFirst.setGeocode("GC12345"); livemapFirst.setType(CacheType.TRADITIONAL, 12); livemapFirst.setCoords(new Geopoint(40.0, 8.0), 12); - Geocache livemapSecond = new Geocache(); + final Geocache livemapSecond = new Geocache(); livemapSecond.setGeocode("GC12345"); livemapSecond.setType(CacheType.MULTI, 11); livemapSecond.setCoords(new Geopoint(41.0, 9.0), 11); livemapSecond.gatherMissingFrom(livemapFirst); - assertEquals("Type not merged correctly", CacheType.TRADITIONAL, livemapSecond.getType()); - assertEquals("Longitude not merged correctly", 8.0, livemapSecond.getCoords().getLongitude(), 0.1); - assertEquals("Latitude not merged correctly", 40.0, livemapSecond.getCoords().getLatitude(), 0.1); - assertEquals("Zoomlevel not merged correctly", 12, livemapSecond.getCoordZoomLevel()); + assertThat(livemapSecond.getType()).as("merged type").isEqualTo(CacheType.TRADITIONAL); + assertThat(livemapSecond.getCoords()).as("merged coordinates").isEqualTo(new Geopoint(40.0, 8.0)); + assertThat(livemapSecond.getCoordZoomLevel()).as("merged zoomlevel").isEqualTo(12); } public static void testMergePopupLivemap() { - - Geocache livemap = new Geocache(); + final Geocache livemap = new Geocache(); livemap.setGeocode("GC12345"); livemap.setCoords(new Geopoint(40.0, 8.0), 12); livemap.setFound(true); - Geocache popup = new Geocache(); + final Geocache popup = new Geocache(); popup.setGeocode("GC12345"); popup.setType(CacheType.MULTI); popup.gatherMissingFrom(livemap); - assertEquals("Type not merged correctly", CacheType.MULTI, popup.getType()); - assertEquals("Longitude not merged correctly", 8.0, popup.getCoords().getLongitude(), 0.1); - assertEquals("Latitude not merged correctly", 40.0, popup.getCoords().getLatitude(), 0.1); - assertThat(popup.isFound()).overridingErrorMessage("Found not merged correctly").isTrue(); - assertEquals("Zoomlevel not merged correctly", 12, popup.getCoordZoomLevel()); + assertThat(popup.getType()).as("merged type").isEqualTo(CacheType.MULTI); + assertThat(popup.getCoords()).as("merged coordinates").isEqualTo(new Geopoint(40.0, 8.0)); + assertThat(popup.isFound()).overridingErrorMessage("merged found").isTrue(); + assertThat(popup.getCoordZoomLevel()).as("merged zoomlevel").isEqualTo(12); } public static void testMergeLivemapBMSearched() { - - Geocache bmsearched = new Geocache(); + final Geocache bmsearched = new Geocache(); bmsearched.setGeocode("GC12345"); - Geocache livemap = new Geocache(); + final Geocache livemap = new Geocache(); livemap.setGeocode("GC12345"); livemap.setCoords(new Geopoint(40.0, 8.0), 12); livemap.gatherMissingFrom(bmsearched); - assertEquals("Longitude not merged correctly", 8.0, livemap.getCoords().getLongitude(), 0.1); - assertEquals("Latitude not merged correctly", 40.0, livemap.getCoords().getLatitude(), 0.1); - assertEquals("Zoomlevel not merged correctly", 12, livemap.getCoordZoomLevel()); + assertThat(livemap.getCoords()).as("merged coordinates").isEqualTo(new Geopoint(40.0, 8.0)); + assertThat(livemap.getCoordZoomLevel()).as("merged zoomlevel").isEqualTo(12); } public static void testNameForSorting() { - Geocache cache = new Geocache(); + final Geocache cache = new Geocache(); cache.setName("GR8 01-01"); assertThat(cache.getNameForSorting()).isEqualTo("GR000008 000001-000001"); } @@ -250,14 +295,15 @@ public class GeocacheTest extends CGeoTestCase { assertTime("<u><em>Uhrzeit:</em></u> 17-20 " + timeHours + "</span></strong>", 17, 00); assertTime("von 11 bis 13 " + timeHours, 11, 00); assertTime("from 11 to 13 " + timeHours, 11, 00); + assertTime("von 19.15 " + timeHours + " bis ca.20.30 " + timeHours + " statt", 19, 15); } public static void testGuessEventTimeShortDescription() { - Geocache cache = new Geocache(); + final Geocache cache = new Geocache(); cache.setType(CacheType.EVENT); cache.setDescription(StringUtils.EMPTY); cache.setShortDescription("text 14:20 text"); - assertThat(cache.guessEventTimeMinutes()).isEqualTo(String.valueOf(14 * 60 + 20)); + assertThat(cache.guessEventTimeMinutes()).isEqualTo(14 * 60 + 20); } private static void assertTime(final String description, final int hours, final int minutes) { @@ -265,24 +311,24 @@ public class GeocacheTest extends CGeoTestCase { cache.setDescription(description); cache.setType(CacheType.EVENT); final int minutesAfterMidnight = hours * 60 + minutes; - assertThat(cache.guessEventTimeMinutes()).isEqualTo(String.valueOf(minutesAfterMidnight)); + assertThat(cache.guessEventTimeMinutes()).isEqualTo(minutesAfterMidnight); } private static void assertNoTime(final String description) { final Geocache cache = new Geocache(); cache.setDescription(description); cache.setType(CacheType.EVENT); - assertThat(cache.guessEventTimeMinutes()).isNull(); + assertThat(cache.guessEventTimeMinutes()).isEqualTo(-1); } public static void testGetPossibleLogTypes() throws Exception { - Geocache gcCache = new Geocache(); + final Geocache gcCache = new Geocache(); gcCache.setGeocode("GC123"); gcCache.setType(CacheType.WEBCAM); assertThat(gcCache.getPossibleLogTypes()).as("possible GC cache log types").contains(LogType.WEBCAM_PHOTO_TAKEN); assertThat(gcCache.getPossibleLogTypes()).as("possible GC cache log types").contains(LogType.NEEDS_MAINTENANCE); - Geocache ocCache = new Geocache(); + final Geocache ocCache = new Geocache(); ocCache.setGeocode("OC1234"); ocCache.setType(CacheType.TRADITIONAL); assertThat(ocCache.getPossibleLogTypes()).as("traditional cache possible log types").doesNotContain(LogType.WEBCAM_PHOTO_TAKEN); @@ -290,24 +336,24 @@ public class GeocacheTest extends CGeoTestCase { } public static void testLogTypeEventPast() throws Exception { - Calendar today = Calendar.getInstance(); + final Calendar today = Calendar.getInstance(); today.add(Calendar.DAY_OF_MONTH, -1); assertThat(createEventCache(today).getDefaultLogType()).isEqualTo(LogType.ATTENDED); } public static void testLogTypeEventToday() throws Exception { - Calendar today = Calendar.getInstance(); + final Calendar today = Calendar.getInstance(); assertThat(createEventCache(today).getDefaultLogType()).isEqualTo(LogType.ATTENDED); } public static void testLogTypeEventFuture() throws Exception { - Calendar today = Calendar.getInstance(); + final Calendar today = Calendar.getInstance(); today.add(Calendar.DAY_OF_MONTH, 1); assertThat(createEventCache(today).getDefaultLogType()).isEqualTo(LogType.WILL_ATTEND); } - private static Geocache createEventCache(Calendar calendar) { - Geocache cache = new Geocache(); + private static Geocache createEventCache(final Calendar calendar) { + final Geocache cache = new Geocache(); cache.setType(CacheType.EVENT); cache.setHidden(calendar.getTime()); return cache; |