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); final Geocache livemap = new Geocache(); livemap.setGeocode("GC12345"); livemap.setType(CacheType.MULTI, 12); livemap.setCoords(new Geopoint(41.0, 9.0), 12); livemap.gatherMissingFrom(stored); 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(stored.getCoordZoomLevel()); }
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()); }
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"); stored.setAttributes(Collections.singletonList("TestAttribute")); stored.setShortDescription("Short"); stored.setHint("Hint"); saveFreshCacheToDB(stored); 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(); 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(); }
@Override protected Void doInBackground(final Void... params) { final Waypoint waypoint = new Waypoint(name, type, own); waypoint.setGeocode(geocode); waypoint.setPrefix(prefix); waypoint.setLookup(lookup); waypoint.setCoords(coordsToSave); waypoint.setNote(noteText); waypoint.setVisited(visited); waypoint.setId(waypointId); final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS); if (cache == null) { finishHandler.sendEmptyMessage(SAVE_ERROR); return null; } final Waypoint oldWaypoint = cache.getWaypointById(waypointId); if (cache.addOrChangeWaypoint(waypoint, true)) { DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB)); if (!StaticMapsProvider.hasAllStaticMapsForWaypoint(geocode, waypoint)) { StaticMapsProvider.removeWpStaticMaps(oldWaypoint, geocode); if (Settings.isStoreOfflineWpMaps()) { StaticMapsProvider.storeWaypointStaticMap(cache, waypoint).subscribe(); } } if (modifyLocal.isChecked() || modifyBoth.isChecked()) { if (!cache.hasUserModifiedCoords()) { final Waypoint origWaypoint = new Waypoint( CgeoApplication.getInstance() .getString(R.string.cache_coordinates_original), WaypointType.ORIGINAL, false); origWaypoint.setCoords(cache.getCoords()); cache.addOrChangeWaypoint(origWaypoint, false); cache.setUserModifiedCoords(true); } cache.setCoords(waypoint.getCoords()); DataStore.saveChangedCache(cache); } if (modifyBoth.isChecked() && waypoint.getCoords() != null) { finishHandler.sendEmptyMessage(UPLOAD_START); if (cache.supportsOwnCoordinates()) { final boolean result = uploadModifiedCoords(cache, waypoint.getCoords()); finishHandler.sendEmptyMessage(result ? SUCCESS : UPLOAD_ERROR); } else { showToast(getString(R.string.waypoint_coordinates_couldnt_be_modified_on_website)); finishHandler.sendEmptyMessage(UPLOAD_NOT_POSSIBLE); } } else { finishHandler.sendEmptyMessage(SUCCESS); } } else { finishHandler.sendEmptyMessage(SAVE_ERROR); } return null; }
public static void testMergeLivemapBMSearched() { final Geocache bmsearched = new Geocache(); bmsearched.setGeocode("GC12345"); final Geocache livemap = new Geocache(); livemap.setGeocode("GC12345"); livemap.setCoords(new Geopoint(40.0, 8.0), 12); livemap.gatherMissingFrom(bmsearched); assertThat(livemap.getCoords()).as("merged coordinates").isEqualTo(new Geopoint(40.0, 8.0)); assertThat(livemap.getCoordZoomLevel()).as("merged zoomlevel").isEqualTo(12); }
public static void testMergePopupLivemap() { final Geocache livemap = new Geocache(); livemap.setGeocode("GC12345"); livemap.setCoords(new Geopoint(40.0, 8.0), 12); livemap.setFound(true); final Geocache popup = new Geocache(); popup.setGeocode("GC12345"); popup.setType(CacheType.MULTI); popup.gatherMissingFrom(livemap); 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 testMergeLivemapZoomout() { final Geocache livemapFirst = new Geocache(); livemapFirst.setGeocode("GC12345"); livemapFirst.setType(CacheType.TRADITIONAL, 12); livemapFirst.setCoords(new Geopoint(40.0, 8.0), 12); 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); 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); }