Fix crash of nearby list when the places list is null

Currently the NearbyController crashes when it is called with a
places list that is null. This is caused by the NearbyMapFragment
not handling this state correctly.
This commit adds tests for an empty list and null, which reproduce
the problem. An early return in the NearbyController can make
the tests pass, but might not be the best solution for this issue.
This commit is contained in:
Tobias Schönberg 2017-05-24 22:15:38 +02:00
parent 67dfa170d2
commit db5dbbfdfd
2 changed files with 67 additions and 4 deletions

View file

@ -84,14 +84,20 @@ public class NearbyController {
*Loads attractions from location for map view, we need to return BaseMarkerOption data type.
* @param curLatLng users current location
* @param placeList list of nearby places in Place data type
* @return BaseMarkerOprions list that holds nearby places
* @return BaseMarkerOptions list that holds nearby places
*/
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
LatLng curLatLng,
List<Place> placeList,
Context context) {
List<NearbyBaseMarker> baseMarkerOptionses = new ArrayList<>();
List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
if (placeList == null) {
return baseMarkerOptions;
}
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
for (Place place: placeList) {
String distance = formatDistanceBetween(curLatLng, place.location);
place.setDistance(distance);
@ -108,8 +114,8 @@ public class NearbyController {
nearbyBaseMarker.place(place);
nearbyBaseMarker.icon(icon);
baseMarkerOptionses.add(nearbyBaseMarker);
baseMarkerOptions.add(nearbyBaseMarker);
}
return baseMarkerOptionses;
return baseMarkerOptions;
}
}