aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2015-01-01 22:30:52 +0100
committerBananeweizen <bananeweizen@gmx.de>2015-01-01 22:51:40 +0100
commitf309b4637be11ce7b740e7dc843936fb707ecfb1 (patch)
treeca1fc605c5fdb45cda548c5e2f006903da01c67f
parent2780031fe84315e45059d14071b89954204f8eac (diff)
downloadcgeo-f309b4637be11ce7b740e7dc843936fb707ecfb1.zip
cgeo-f309b4637be11ce7b740e7dc843936fb707ecfb1.tar.gz
cgeo-f309b4637be11ce7b740e7dc843936fb707ecfb1.tar.bz2
use more nullable annotations
* make the DataStore methods use explicit nullable or nonnull return values * remove the null return of getStoredList() * unfortunately many of the test methods need an assert() statement to make Eclipse understand the null logic
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java7
-rw-r--r--main/src/cgeo/geocaching/CacheListActivity.java3
-rw-r--r--main/src/cgeo/geocaching/CompassActivity.java7
-rw-r--r--main/src/cgeo/geocaching/CreateShortcutActivity.java3
-rw-r--r--main/src/cgeo/geocaching/DataStore.java55
-rw-r--r--main/src/cgeo/geocaching/export/FieldnoteExport.java11
-rw-r--r--main/src/cgeo/geocaching/list/StoredList.java4
-rw-r--r--main/src/cgeo/geocaching/location/Viewport.java5
-rw-r--r--tests/src/cgeo/geocaching/CgeoApplicationTest.java6
-rw-r--r--tests/src/cgeo/geocaching/DataStoreTest.java4
-rw-r--r--tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java2
-rw-r--r--tests/src/cgeo/geocaching/files/GPXImporterTest.java14
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java2
13 files changed, 94 insertions, 29 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 68b5c0f..ef3823e 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -1246,12 +1246,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
// update text
final TextView text = ButterKnife.findById(view, R.id.list_text);
final StoredList list = DataStore.getList(cache.getListId());
- if (list != null) {
- text.setText(res.getString(R.string.cache_list_text) + " " + list.title);
- } else {
- // this should not happen
- text.setText(R.string.cache_list_unknown);
- }
+ text.setText(res.getString(R.string.cache_list_text) + " " + list.title);
} else {
// hide box
box.setVisibility(View.GONE);
diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java
index d0e9975..e402289 100644
--- a/main/src/cgeo/geocaching/CacheListActivity.java
+++ b/main/src/cgeo/geocaching/CacheListActivity.java
@@ -1295,9 +1295,6 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA
title = res.getString(R.string.list_all_lists);
} else {
final StoredList list = DataStore.getList(id);
- if (list == null) {
- return;
- }
listId = list.id;
title = list.title;
}
diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java
index 361582c..8b0fc73 100644
--- a/main/src/cgeo/geocaching/CompassActivity.java
+++ b/main/src/cgeo/geocaching/CompassActivity.java
@@ -81,7 +81,10 @@ public class CompassActivity extends AbstractActionBarActivity {
// find the wanted navigation target
if (extras.containsKey(Intents.EXTRA_WAYPOINT_ID)) {
final int waypointId = extras.getInt(Intents.EXTRA_WAYPOINT_ID);
- setTarget(DataStore.loadWaypoint(waypointId));
+ final Waypoint waypoint = DataStore.loadWaypoint(waypointId);
+ if (waypoint != null) {
+ setTarget(waypoint);
+ }
}
else if (extras.containsKey(Intents.EXTRA_COORDS)) {
setTarget(extras.<Geopoint>getParcelable(Intents.EXTRA_COORDS), extras.getString(Intents.EXTRA_DESCRIPTION));
@@ -215,7 +218,7 @@ public class CompassActivity extends AbstractActionBarActivity {
return super.onOptionsItemSelected(item);
}
- private void setTarget(final Geopoint coords, final String newDescription) {
+ private void setTarget(@NonNull final Geopoint coords, final String newDescription) {
setDestCoords(coords);
setTargetDescription(newDescription);
updateDistanceInfo(Sensors.getInstance().currentGeo());
diff --git a/main/src/cgeo/geocaching/CreateShortcutActivity.java b/main/src/cgeo/geocaching/CreateShortcutActivity.java
index 01754e2..70ab900 100644
--- a/main/src/cgeo/geocaching/CreateShortcutActivity.java
+++ b/main/src/cgeo/geocaching/CreateShortcutActivity.java
@@ -99,9 +99,6 @@ public class CreateShortcutActivity extends AbstractActionBarActivity {
protected void createOfflineListShortcut(final int listId) {
final StoredList list = DataStore.getList(listId);
- if (list == null) {
- return;
- }
// target to be executed by the shortcut
final Intent targetIntent = new Intent(this, CacheListActivity.class);
targetIntent.putExtra(Intents.EXTRA_LIST_ID, list.id);
diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java
index bd6e3e5..cf4fde8 100644
--- a/main/src/cgeo/geocaching/DataStore.java
+++ b/main/src/cgeo/geocaching/DataStore.java
@@ -374,6 +374,7 @@ public class DataStore {
database = null;
}
+ @NonNull
public static File getBackupFileInternal() {
return new File(LocalStorage.getStorage(), "cgeo.sqlite");
}
@@ -441,14 +442,17 @@ public class DataStore {
});
}
+ @NonNull
private static File databasePath(final boolean internal) {
return new File(internal ? LocalStorage.getInternalDbDirectory() : LocalStorage.getExternalDbDirectory(), dbName);
}
+ @NonNull
private static File databasePath() {
return databasePath(!Settings.isDbOnSDCard());
}
+ @NonNull
private static File databaseAlternatePath() {
return databasePath(Settings.isDbOnSDCard());
}
@@ -1029,6 +1033,7 @@ public class DataStore {
return false;
}
+ @Nullable
public static String getGeocodeForGuid(final String guid) {
if (StringUtils.isBlank(guid)) {
return null;
@@ -1342,6 +1347,7 @@ public class DataStore {
* index of the longitude column
* @return the coordinates, or null if latitude or longitude is null or the coordinates are invalid
*/
+ @Nullable
private static Geopoint getCoords(final Cursor cursor, final int indexLat, final int indexLon) {
if (cursor.isNull(indexLat) || cursor.isNull(indexLon)) {
return null;
@@ -1519,6 +1525,7 @@ public class DataStore {
}
}
+ @Nullable
public static Viewport getBounds(final Set<String> geocodes) {
if (CollectionUtils.isEmpty(geocodes)) {
return null;
@@ -1535,6 +1542,7 @@ public class DataStore {
* The Geocode GCXXXX
* @return the loaded cache (if found). Can be null
*/
+ @Nullable
public static Geocache loadCache(final String geocode, final EnumSet<LoadFlag> loadFlags) {
if (StringUtils.isBlank(geocode)) {
throw new IllegalArgumentException("geocode must not be empty");
@@ -1550,6 +1558,7 @@ public class DataStore {
* @param geocodes
* @return Set of loaded caches. Never null.
*/
+ @NonNull
public static Set<Geocache> loadCaches(final Collection<String> geocodes, final EnumSet<LoadFlag> loadFlags) {
if (CollectionUtils.isEmpty(geocodes)) {
return new HashSet<>();
@@ -1606,6 +1615,7 @@ public class DataStore {
* @param loadFlags
* @return Set of loaded caches. Never null.
*/
+ @NonNull
private static Set<Geocache> loadCachesFromGeocodes(final Set<String> geocodes, final EnumSet<LoadFlag> loadFlags) {
if (CollectionUtils.isEmpty(geocodes)) {
return Collections.emptySet();
@@ -1697,6 +1707,7 @@ public class DataStore {
* @return
*/
+ @NonNull
private static StringBuilder buildCoordinateWhere(final String dbTable, final Viewport viewport) {
return viewport.resize(1.5).sqlWhere(dbTable);
}
@@ -1707,6 +1718,7 @@ public class DataStore {
* @param cursor
* @return Cache from DB
*/
+ @NonNull
private static Geocache createCacheFromDatabaseContent(final Cursor cursor) {
final Geocache cache = new Geocache();
@@ -1768,6 +1780,7 @@ public class DataStore {
return cache;
}
+ @Nullable
public static List<String> loadAttributes(final String geocode) {
if (StringUtils.isBlank(geocode)) {
return null;
@@ -1785,6 +1798,7 @@ public class DataStore {
GET_STRING_0);
}
+ @Nullable
public static Waypoint loadWaypoint(final int id) {
if (id == 0) {
return null;
@@ -1811,6 +1825,7 @@ public class DataStore {
return waypoint;
}
+ @Nullable
public static List<Waypoint> loadWaypoints(final String geocode) {
if (StringUtils.isBlank(geocode)) {
return null;
@@ -1833,6 +1848,7 @@ public class DataStore {
});
}
+ @NonNull
private static Waypoint createWaypointFromDatabaseContent(final Cursor cursor) {
final String name = cursor.getString(cursor.getColumnIndex("name"));
final WaypointType type = WaypointType.findById(cursor.getString(cursor.getColumnIndex("type")));
@@ -1849,6 +1865,7 @@ public class DataStore {
return waypoint;
}
+ @Nullable
private static List<Image> loadSpoilers(final String geocode) {
if (StringUtils.isBlank(geocode)) {
return null;
@@ -1877,6 +1894,7 @@ public class DataStore {
*
* @return A list of previously entered destinations or an empty list.
*/
+ @NonNull
public static List<Destination> loadHistoryOfSearchedLocations() {
return queryToColl(dbTableSearchDestinationHistory,
new String[]{"_id", "date", "latitude", "longitude"},
@@ -1955,6 +1973,7 @@ public class DataStore {
return Collections.unmodifiableList(logs);
}
+ @Nullable
public static Map<LogType, Integer> loadLogCounts(final String geocode) {
if (StringUtils.isBlank(geocode)) {
return null;
@@ -1983,6 +2002,7 @@ public class DataStore {
return logCounts;
}
+ @Nullable
private static List<Trackable> loadInventory(final String geocode) {
if (StringUtils.isBlank(geocode)) {
return null;
@@ -2036,6 +2056,7 @@ public class DataStore {
return trackable;
}
+ @NonNull
private static Trackable createTrackableFromDatabaseContent(final Cursor cursor) {
final Trackable trackable = new Trackable();
trackable.setGeocode(cursor.getString(cursor.getColumnIndex("tbcode")));
@@ -2115,6 +2136,7 @@ public class DataStore {
return 0;
}
+ @NonNull
private static<T, U extends Collection<? super T>> U queryToColl(@NonNull final String table,
final String[] columns,
final String selection,
@@ -2150,6 +2172,7 @@ public class DataStore {
* @param listId
* @return a non-null set of geocodes
*/
+ @NonNull
private static Set<String> loadBatchOfStoredGeocodes(final Geopoint coords, final CacheType cacheType, final int listId) {
if (cacheType == null) {
throw new IllegalArgumentException("cacheType must not be null");
@@ -2196,6 +2219,7 @@ public class DataStore {
}
}
+ @NonNull
private static Set<String> loadBatchOfHistoricGeocodes(final boolean detailedOnly, final CacheType cacheType) {
final StringBuilder selection = new StringBuilder("visiteddate > 0");
@@ -2227,11 +2251,13 @@ public class DataStore {
}
/** Retrieve all stored caches from DB */
+ @NonNull
public static SearchResult loadCachedInViewport(final Viewport viewport, final CacheType cacheType) {
return loadInViewport(false, viewport, cacheType);
}
/** Retrieve stored caches from DB with listId >= 1 */
+ @NonNull
public static SearchResult loadStoredInViewport(final Viewport viewport, final CacheType cacheType) {
return loadInViewport(true, viewport, cacheType);
}
@@ -2244,6 +2270,7 @@ public class DataStore {
* @param cacheType the cache type
* @return the matching caches
*/
+ @NonNull
private static SearchResult loadInViewport(final boolean stored, final Viewport viewport, final CacheType cacheType) {
final Set<String> geocodes = new HashSet<>();
@@ -2355,7 +2382,8 @@ public class DataStore {
* @param geocodes
* @return
*/
- private static Set<String> exceptCachesWithOfflineLog(final Set<String> geocodes) {
+ @NonNull
+ private static Set<String> exceptCachesWithOfflineLog(@NonNull final Set<String> geocodes) {
if (geocodes.isEmpty()) {
return geocodes;
}
@@ -2464,6 +2492,7 @@ public class DataStore {
return id != -1;
}
+ @Nullable
public static LogEntry loadLogOffline(final String geocode) {
if (StringUtils.isBlank(geocode)) {
return null;
@@ -2582,6 +2611,7 @@ public class DataStore {
return lists;
}
+ @NonNull
private static ArrayList<StoredList> getListsFromCursor(final Cursor cursor) {
final int indexId = cursor.getColumnIndex("_id");
final int indexTitle = cursor.getColumnIndex("title");
@@ -2595,6 +2625,7 @@ public class DataStore {
});
}
+ @NonNull
public static StoredList getList(final int id) {
init();
if (id >= customListIdOffset) {
@@ -2618,11 +2649,7 @@ public class DataStore {
}
// fall back to standard list in case of invalid list id
- if (id == StoredList.STANDARD_LIST_ID || id >= customListIdOffset) {
- return new StoredList(StoredList.STANDARD_LIST_ID, res.getString(R.string.list_inbox), (int) PreparedStatement.COUNT_CACHES_ON_STANDARD_LIST.simpleQueryForLong());
- }
-
- return null;
+ return new StoredList(StoredList.STANDARD_LIST_ID, res.getString(R.string.list_inbox), (int) PreparedStatement.COUNT_CACHES_ON_STANDARD_LIST.simpleQueryForLong());
}
public static int getAllCachesCount() {
@@ -2796,6 +2823,7 @@ public class DataStore {
* @param geocode
* @return
*/
+ @NonNull
public static Geocache loadCacheTexts(final String geocode) {
final Geocache partial = new Geocache();
@@ -2853,6 +2881,7 @@ public class DataStore {
* Creates the WHERE clause for matching multiple geocodes. This automatically converts all given codes to
* UPPERCASE.
*/
+ @NonNull
private static StringBuilder whereGeocodeIn(final Collection<String> geocodes) {
final StringBuilder whereExpr = new StringBuilder("geocode in (");
final Iterator<String> iterator = geocodes.iterator();
@@ -2875,6 +2904,7 @@ public class DataStore {
* @return
*/
+ @NonNull
public static Set<Waypoint> loadWaypoints(final Viewport viewport, final boolean excludeMine, final boolean excludeDisabled, final CacheType type) {
final StringBuilder where = buildCoordinateWhere(dbTableWaypoints, viewport);
if (excludeMine) {
@@ -2971,6 +3001,7 @@ public class DataStore {
moveToList(caches, StoredList.TEMPORARY_LIST.id);
}
+ @Nullable
public static Viewport getBounds(final String geocode) {
if (geocode == null) {
return null;
@@ -2983,11 +3014,13 @@ public class DataStore {
setVisitDate(Arrays.asList(selected), 0);
}
+ @NonNull
public static SearchResult getBatchOfStoredCaches(final Geopoint coords, final CacheType cacheType, final int listId) {
final Set<String> geocodes = DataStore.loadBatchOfStoredGeocodes(coords, cacheType, listId);
return new SearchResult(geocodes, DataStore.getAllStoredCachesCount(cacheType, listId));
}
+ @NonNull
public static SearchResult getHistoryOfCaches(final boolean detailedOnly, final CacheType cacheType) {
final Set<String> geocodes = DataStore.loadBatchOfHistoricGeocodes(detailedOnly, cacheType);
return new SearchResult(geocodes, DataStore.getAllHistoryCachesCount());
@@ -3001,6 +3034,7 @@ public class DataStore {
return false;
}
+ @NonNull
public static Set<String> getCachedMissingFromSearch(final SearchResult searchResult, final Set<Tile> tiles, final IConnector connector, final int maxZoom) {
// get cached CacheListActivity
@@ -3031,6 +3065,7 @@ public class DataStore {
return missingFromSearch;
}
+ @Nullable
public static Cursor findSuggestions(final String searchTerm) {
// require 3 characters, otherwise there are to many results
if (StringUtils.length(searchTerm) < 3) {
@@ -3066,6 +3101,7 @@ public class DataStore {
cursor.close();
}
+ @NonNull
private static String getSuggestionArgument(final String input) {
return "%" + StringUtils.trim(input) + "%";
}
@@ -3093,6 +3129,7 @@ public class DataStore {
cursor.close();
}
+ @NonNull
public static String[] getSuggestions(final String table, final String column, final String input) {
try {
final Cursor cursor = database.rawQuery("SELECT DISTINCT " + column
@@ -3106,22 +3143,27 @@ public class DataStore {
}
}
+ @NonNull
public static String[] getSuggestionsOwnerName(final String input) {
return getSuggestions(dbTableCaches, "owner_real", input);
}
+ @NonNull
public static String[] getSuggestionsTrackableCode(final String input) {
return getSuggestions(dbTableTrackables, "tbcode", input);
}
+ @NonNull
public static String[] getSuggestionsFinderName(final String input) {
return getSuggestions(dbTableLogs, "author", input);
}
+ @NonNull
public static String[] getSuggestionsGeocode(final String input) {
return getSuggestions(dbTableCaches, "geocode", input);
}
+ @NonNull
public static String[] getSuggestionsKeyword(final String input) {
return getSuggestions(dbTableCaches, "name", input);
}
@@ -3130,6 +3172,7 @@ public class DataStore {
*
* @return list of last caches opened in the details view, ordered by most recent first
*/
+ @NonNull
public static ArrayList<Geocache> getLastOpenedCaches() {
final List<String> geocodes = Settings.getLastOpenedCaches();
final Set<Geocache> cachesSet = DataStore.loadCaches(geocodes, LoadFlags.LOAD_CACHE_OR_DB);
diff --git a/main/src/cgeo/geocaching/export/FieldnoteExport.java b/main/src/cgeo/geocaching/export/FieldnoteExport.java
index c03b848..c4a6adc 100644
--- a/main/src/cgeo/geocaching/export/FieldnoteExport.java
+++ b/main/src/cgeo/geocaching/export/FieldnoteExport.java
@@ -59,10 +59,11 @@ public class FieldnoteExport extends AbstractExport {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final Context themedContext;
- if (Settings.isLightSkin() && VERSION.SDK_INT < VERSION_CODES.HONEYCOMB)
+ if (Settings.isLightSkin() && VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) {
themedContext = new ContextThemeWrapper(activity, R.style.dark);
- else
+ } else {
themedContext = activity;
+ }
final View layout = View.inflate(themedContext, R.layout.fieldnote_export_dialog, null);
builder.setView(layout);
@@ -135,8 +136,10 @@ public class FieldnoteExport extends AbstractExport {
for (final Geocache cache : caches) {
if (ConnectorFactory.getConnector(cache).equals(connector) && cache.isLogOffline()) {
final LogEntry log = DataStore.loadLogOffline(cache.getGeocode());
- if (!onlyNew || log.date > Settings.getFieldnoteExportDate()) {
- fieldNotes.add(cache, log);
+ if (log != null) {
+ if (!onlyNew || log.date > Settings.getFieldnoteExportDate()) {
+ fieldNotes.add(cache, log);
+ }
}
}
publishProgress(++i);
diff --git a/main/src/cgeo/geocaching/list/StoredList.java b/main/src/cgeo/geocaching/list/StoredList.java
index 4291a0a..78f98c0 100644
--- a/main/src/cgeo/geocaching/list/StoredList.java
+++ b/main/src/cgeo/geocaching/list/StoredList.java
@@ -108,9 +108,7 @@ public final class StoredList extends AbstractList {
if (exceptListId > StoredList.TEMPORARY_LIST.id) {
final StoredList exceptList = DataStore.getList(exceptListId);
- if (exceptList != null) {
- lists.remove(exceptList);
- }
+ lists.remove(exceptList);
}
if (!onlyConcreteLists) {
diff --git a/main/src/cgeo/geocaching/location/Viewport.java b/main/src/cgeo/geocaching/location/Viewport.java
index e482828..b885336 100644
--- a/main/src/cgeo/geocaching/location/Viewport.java
+++ b/main/src/cgeo/geocaching/location/Viewport.java
@@ -87,7 +87,7 @@ public final class Viewport {
*/
public int count(final @NonNull Collection<? extends ICoordinates> points) {
int total = 0;
- for (ICoordinates point: points) {
+ for (final ICoordinates point: points) {
if (point != null && contains(point)) {
total += 1;
}
@@ -102,7 +102,7 @@ public final class Viewport {
/**
* Check whether another viewport is fully included into the current one.
- *
+ *
* @param vp
* the other viewport
* @return true if the viewport is fully included into this one, false otherwise
@@ -118,6 +118,7 @@ public final class Viewport {
* the database table to use as prefix, or null if no prefix is required
* @return the string without the "where" keyword
*/
+ @NonNull
public StringBuilder sqlWhere(@Nullable final String dbTable) {
final String prefix = dbTable == null ? "" : (dbTable + ".");
return new StringBuilder(prefix).append("latitude >= ").append(getLatitudeMin()).append(" and ")
diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java
index c00f549..beb33cd 100644
--- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java
@@ -312,6 +312,8 @@ public class CgeoApplicationTest extends CGeoTestCase {
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());
@@ -324,6 +326,8 @@ public class CgeoApplicationTest extends CGeoTestCase {
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());
@@ -366,6 +370,8 @@ 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();
diff --git a/tests/src/cgeo/geocaching/DataStoreTest.java b/tests/src/cgeo/geocaching/DataStoreTest.java
index 03713ac..36bfe47 100644
--- a/tests/src/cgeo/geocaching/DataStoreTest.java
+++ b/tests/src/cgeo/geocaching/DataStoreTest.java
@@ -59,6 +59,8 @@ public class DataStoreTest extends CGeoTestCase {
// get list
final StoredList list1 = DataStore.getList(listId1);
+ assert (list1 != null);
+ assertThat(list1).isNotNull();
assertThat(list1.title).isEqualTo("DataStore Test (renamed)");
// move to list (cache1=listId2, cache2=listId2)
@@ -123,6 +125,8 @@ public class DataStoreTest extends CGeoTestCase {
try {
DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB));
final Geocache loadedCache = DataStore.loadCache(GEOCODE_CACHE, LoadFlags.LOAD_ALL_DB_ONLY);
+ assert (loadedCache != null);
+ assertThat(loadedCache).isNotNull();
assertThat(loadedCache).overridingErrorMessage("Cache was not saved.").isNotNull();
assertThat(loadedCache.getInventory()).hasSize(1);
} finally {
diff --git a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
index 20a51b8..7b011f3 100644
--- a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
+++ b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
@@ -19,6 +19,7 @@ public class OkapiClientTest extends CGeoTestCase {
assertThat(cache.isDetailed()).isTrue();
// cache should be stored to DB (to listID 0) when loaded above
cache = DataStore.loadCache(geoCode, LoadFlags.LOAD_ALL_DB_ONLY);
+ assert (cache != null);
assertThat(cache).isNotNull();
assertThat(cache.getGeocode()).isEqualTo(geoCode);
assertThat(cache.getName()).isEqualTo("Oshkosh Municipal Tank");
@@ -41,6 +42,7 @@ public class OkapiClientTest extends CGeoTestCase {
assertThat(cache).as("Cache from OKAPI").isNotNull();
// cache should be stored to DB (to listID 0) when loaded above
cache = DataStore.loadCache(geoCode, LoadFlags.LOAD_ALL_DB_ONLY);
+ assert (cache != null);
assertThat(cache).isNotNull();
assertThat(cache.getWaypoints()).hasSize(3);
diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
index f72cf4a..7b9d9ac 100644
--- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
@@ -78,6 +78,8 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
final SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj;
assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode));
final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ assert (cache != null);
+ assertThat(cache).isNotNull();
assertCacheProperties(cache);
assertThat(cache.getWaypoints().isEmpty()).isTrue();
@@ -101,6 +103,8 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
final SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj;
assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode));
final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ assert (cache != null);
+ assertThat(cache).isNotNull();
assertCacheProperties(cache);
assertThat(cache.getWaypoints()).as("Number of imported waypoints").hasSize(4);
@@ -128,6 +132,8 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
final SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj;
assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList("GC31J2H"));
final Geocache cache = DataStore.loadCache("GC31J2H", LoadFlags.LOAD_CACHE_OR_DB);
+ assert (cache != null);
+ assertThat(cache).isNotNull();
assertCacheProperties(cache);
assertThat(cache.getWaypoints()).hasSize(2);
}
@@ -141,6 +147,8 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED);
final Geocache cache = DataStore.loadCache("AID1", LoadFlags.LOAD_CACHE_OR_DB);
+ assert (cache != null);
+ assertThat(cache).isNotNull();
assertCacheProperties(cache);
assertThat(cache.getName()).isEqualTo("First Aid Station #1");
}
@@ -205,6 +213,8 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
final SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj;
assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode));
final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ assert (cache != null);
+ assertThat(cache).isNotNull();
assertCacheProperties(cache);
assertThat(cache.getWaypoints().isEmpty()).isTrue();
@@ -223,6 +233,8 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
final SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj;
assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode));
final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ assert (cache != null);
+ assertThat(cache).isNotNull();
assertCacheProperties(cache);
assertThat(cache.getWaypoints()).hasSize(1); // this is the original pocket query result without test waypoint
}
@@ -249,6 +261,8 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
final SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj;
assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode));
final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ assert (cache != null);
+ assertThat(cache).isNotNull();
assertCacheProperties(cache);
assertThat(cache.getWaypoints()).hasSize(1); // this is the original pocket query result without test waypoint
}
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 74694bd..43fda22 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -286,6 +286,8 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
DataStore.removeAllFromCache();
// load only the minimum cache, it has several members missing
final Geocache minimalCache = DataStore.loadCache(geocode, EnumSet.of(LoadFlag.DB_MINIMAL));
+ assert (minimalCache != null);
+ assertThat(minimalCache).isNotNull();
// now check that we load lazy members on demand
assertThat(minimalCache.getAttributes()).isNotEmpty();