aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/cgData.java6
-rw-r--r--main/src/cgeo/geocaching/cgTrackable.java2
-rw-r--r--tests/src/cgeo/geocaching/cgDataTest.java42
3 files changed, 46 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index 773f08a..b822c2b 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -1915,14 +1915,14 @@ public class cgData {
}
public List<LogEntry> loadLogs(String geocode) {
+ List<LogEntry> logs = new ArrayList<LogEntry>();
+
if (StringUtils.isBlank(geocode)) {
- return null;
+ return logs;
}
init();
- List<LogEntry> logs = new ArrayList<LogEntry>();
-
Cursor cursor = database.rawQuery(
"SELECT cg_logs._id as cg_logs_id, type, author, log, date, found, friend, " + dbTableLogImages + "._id as cg_logImages_id, log_id, title, url FROM "
+ dbTableLogs + " LEFT OUTER JOIN " + dbTableLogImages
diff --git a/main/src/cgeo/geocaching/cgTrackable.java b/main/src/cgeo/geocaching/cgTrackable.java
index c9b5623..7ed3424 100644
--- a/main/src/cgeo/geocaching/cgTrackable.java
+++ b/main/src/cgeo/geocaching/cgTrackable.java
@@ -191,7 +191,7 @@ public class cgTrackable implements ILogable {
}
public void setLogs(List<LogEntry> logs) {
- this.logs = logs;
+ this.logs = logs != null ? logs : new ArrayList<LogEntry>();
}
@Override
diff --git a/tests/src/cgeo/geocaching/cgDataTest.java b/tests/src/cgeo/geocaching/cgDataTest.java
index 0fdb5c6..3cee32f 100644
--- a/tests/src/cgeo/geocaching/cgDataTest.java
+++ b/tests/src/cgeo/geocaching/cgDataTest.java
@@ -3,11 +3,15 @@ package cgeo.geocaching;
import cgeo.CGeoTestCase;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
+import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.EnumSet;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
public class cgDataTest extends CGeoTestCase {
@@ -95,4 +99,42 @@ public class cgDataTest extends CGeoTestCase {
app.getWaypointsInViewport(viewport, true, false, CacheType.TRADITIONAL);
app.getWaypointsInViewport(viewport, true, true, CacheType.TRADITIONAL);
}
+
+ // Check that saving a cache and trackable without logs works (see #2199)
+ public static void testSaveWithoutLogs() {
+
+ cgeoapplication app = cgeoapplication.getInstance();
+
+ final String GEOCODE_CACHE = "TEST";
+
+ // create cache and trackable
+ final cgCache cache = new cgCache();
+ cache.setGeocode(GEOCODE_CACHE);
+ cache.setDetailed(true);
+ final cgTrackable trackable = new cgTrackable();
+ trackable.setLogs(null);
+ final List<cgTrackable> inventory = new ArrayList<cgTrackable>();
+ inventory.add(trackable);
+ cache.setInventory(inventory);
+
+ try {
+ app.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
+ final cgCache loadedCache = app.loadCache(GEOCODE_CACHE, LoadFlags.LOAD_ALL_DB_ONLY);
+ assertNotNull("Cache was not saved!", loadedCache);
+ assertEquals(1, loadedCache.getInventory().size());
+ } finally {
+ app.removeCache(GEOCODE_CACHE, LoadFlags.REMOVE_ALL);
+ }
+ }
+
+ // Loading logs for an empty geocode should return an empty list, not null!
+ public static void testLoadLogsFromEmptyGeocode() {
+
+ cgeoapplication app = cgeoapplication.getInstance();
+
+ List<LogEntry> logs = app.loadLogs("");
+
+ assertNotNull("Logs must not be null", logs);
+ assertEquals("Logs from empty geocode must be empty", 0, logs.size());
+ }
}