[android] #5631 - add a concrete java exception when creating a marker without the required position field.
[android] #5631 - updated test cases to handle invalid position on a Marker
This commit is contained in:
committed by
Tobrun Van Nuland
parent
5fb0e878b4
commit
fd5ee40506
@@ -32,7 +32,7 @@ public class InfoWindowTest {
|
||||
@Test
|
||||
public void testBoundMarker() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
Marker marker = markerOptions.getMarker();
|
||||
Marker marker = markerOptions.position(new LatLng()).getMarker();
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap).setBoundMarker(marker);
|
||||
assertEquals("marker should match", marker, infoWindow.getBoundMarker());
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class InfoWindowTest {
|
||||
when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0));
|
||||
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
|
||||
infoWindow.open(mMapView, new MarkerOptions().getMarker(), latLng, 0, 0);
|
||||
infoWindow.open(mMapView, new MarkerOptions().position(new LatLng()).getMarker(), latLng, 0, 0);
|
||||
assertEquals("infowindow should not be visible", true, infoWindow.isVisible());
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class InfoWindowTest {
|
||||
when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0));
|
||||
|
||||
InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
|
||||
infoWindow.open(mMapView, new MarkerOptions().getMarker(), latLng, 0, 0);
|
||||
infoWindow.open(mMapView, new MarkerOptions().position(new LatLng()).getMarker(), latLng, 0, 0);
|
||||
infoWindow.close();
|
||||
assertEquals("infowindow should not be visible", false, infoWindow.isVisible());
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.annotations;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
@@ -23,10 +24,15 @@ public class MarkerTest {
|
||||
|
||||
@Test
|
||||
public void testMarker() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
assertNotNull("marker should not be null", markerOptions.getMarker());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidMarkerPositionException.class)
|
||||
public void testInvalidMarker(){
|
||||
new MarkerOptions().getMarker();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPosition() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12));
|
||||
@@ -37,7 +43,7 @@ public class MarkerTest {
|
||||
|
||||
@Test
|
||||
public void testTitle() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().title("Mapbox");
|
||||
MarkerOptions markerOptions = new MarkerOptions().title("Mapbox").position(new LatLng());
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getTitle(), "Mapbox");
|
||||
assertEquals(markerOptions.getTitle(), "Mapbox");
|
||||
@@ -45,7 +51,7 @@ public class MarkerTest {
|
||||
|
||||
@Test
|
||||
public void testSnippet() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().snippet("Mapbox");
|
||||
MarkerOptions markerOptions = new MarkerOptions().snippet("Mapbox").position(new LatLng());
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getSnippet(), "Mapbox");
|
||||
}
|
||||
@@ -62,7 +68,7 @@ public class MarkerTest {
|
||||
public void testIcon() {
|
||||
Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
||||
Icon icon = IconFactory.recreate("test", bitmap);
|
||||
MarkerOptions markerOptions = new MarkerOptions().icon(icon);
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).icon(icon);
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals("Icon should match", icon, marker.getIcon());
|
||||
assertEquals("Icon should match", icon, markerOptions.getIcon());
|
||||
@@ -70,7 +76,7 @@ public class MarkerTest {
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
Marker marker = new MarkerOptions().getMarker();
|
||||
Marker marker = new MarkerOptions().position(new LatLng()).getMarker();
|
||||
assertEquals("hash code should match", marker.hashCode(), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
@@ -23,10 +24,15 @@ public class MarkerViewTest {
|
||||
|
||||
@Test
|
||||
public void testMarker() {
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions();
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng());
|
||||
assertNotNull("marker should not be null", markerOptions.getMarker());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidMarkerPositionException.class)
|
||||
public void testInvalidMarker(){
|
||||
new MarkerViewOptions().getMarker();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPosition() {
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng(10, 12));
|
||||
@@ -37,14 +43,14 @@ public class MarkerViewTest {
|
||||
|
||||
@Test
|
||||
public void testSnippet() {
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().snippet("Mapbox");
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().snippet("Mapbox").position(new LatLng());
|
||||
MarkerView marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getSnippet(), "Mapbox");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitle() {
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().title("Mapbox");
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().title("Mapbox").position(new LatLng());
|
||||
MarkerView marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getTitle(), "Mapbox");
|
||||
assertEquals(markerOptions.getTitle(), "Mapbox");
|
||||
@@ -52,21 +58,21 @@ public class MarkerViewTest {
|
||||
|
||||
@Test
|
||||
public void testFlat() {
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().flat(true);
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().flat(true).position(new LatLng());
|
||||
MarkerView marker = markerOptions.getMarker();
|
||||
assertTrue("flat should be true", marker.isFlat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatDefault() {
|
||||
assertFalse("default value of flat should be false", new MarkerViewOptions().getMarker().isFlat());
|
||||
assertFalse("default value of flat should be false", new MarkerViewOptions().position(new LatLng()).getMarker().isFlat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnchor() {
|
||||
float anchorU = 1;
|
||||
float anchorV = 1;
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().anchor(anchorU, anchorV);
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().anchor(anchorU, anchorV).position(new LatLng());
|
||||
MarkerView marker = markerOptions.getMarker();
|
||||
assertEquals("anchorU should match ", anchorU, marker.getAnchorU(), 0);
|
||||
assertEquals("anchorU should match ", anchorV, marker.getAnchorV(), 0);
|
||||
@@ -74,7 +80,7 @@ public class MarkerViewTest {
|
||||
|
||||
@Test
|
||||
public void testAnchorDefault() {
|
||||
MarkerView marker = new MarkerViewOptions().getMarker();
|
||||
MarkerView marker = new MarkerViewOptions().position(new LatLng()).getMarker();
|
||||
assertEquals("anchorU should match ", 0.5, marker.getAnchorU(), 0);
|
||||
assertEquals("anchorU should match ", 1, marker.getAnchorV(), 0);
|
||||
}
|
||||
@@ -83,7 +89,7 @@ public class MarkerViewTest {
|
||||
public void testInfoWindowAnchor() {
|
||||
float anchorU = 1;
|
||||
float anchorV = 1;
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().infoWindowAnchor(anchorU, anchorV);
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).infoWindowAnchor(anchorU, anchorV);
|
||||
MarkerView marker = markerOptions.getMarker();
|
||||
assertEquals("anchorU should match ", 1, marker.getInfoWindowAnchorU(), 0);
|
||||
assertEquals("anchorU should match ", 1, marker.getInfoWindowAnchorV(), 0);
|
||||
@@ -91,7 +97,7 @@ public class MarkerViewTest {
|
||||
|
||||
@Test
|
||||
public void testInfoWindowAnchorDefault() {
|
||||
MarkerView marker = new MarkerViewOptions().getMarker();
|
||||
MarkerView marker = new MarkerViewOptions().position(new LatLng()).getMarker();
|
||||
assertEquals("anchorU should match ", 0.5, marker.getInfoWindowAnchorU(), 0);
|
||||
assertEquals("anchorU should match ", 0, marker.getInfoWindowAnchorV(), 0);
|
||||
}
|
||||
@@ -99,7 +105,7 @@ public class MarkerViewTest {
|
||||
@Test
|
||||
public void testRotation() {
|
||||
int rotation = 90;
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().rotation(rotation);
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(rotation);
|
||||
MarkerView marker = markerOptions.getMarker();
|
||||
assertEquals("rotation should match ", rotation, marker.getRotation(), 0);
|
||||
}
|
||||
@@ -107,27 +113,26 @@ public class MarkerViewTest {
|
||||
@Test
|
||||
public void testVisible() {
|
||||
boolean visible = false;
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().visible(visible);
|
||||
MarkerViewOptions markerOptions = new MarkerViewOptions().visible(visible).position(new LatLng());
|
||||
MarkerView marker = markerOptions.getMarker();
|
||||
assertEquals("visible should match ", visible, marker.isVisible());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisibleDefault() {
|
||||
assertTrue(new MarkerViewOptions().getMarker().isVisible());
|
||||
assertTrue(new MarkerViewOptions().position(new LatLng()).getMarker().isVisible());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
MarkerView marker = new MarkerViewOptions().title("title").snippet("snippet").position(new LatLng(10, 12)).getMarker();
|
||||
assertEquals(marker.getSnippet(), "snippet");
|
||||
|
||||
assertEquals(marker.getPosition(), new LatLng(10, 12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
MarkerView marker = new MarkerViewOptions().getMarker();
|
||||
MarkerView marker = new MarkerViewOptions().position(new LatLng()).getMarker();
|
||||
assertEquals("hash code should match", marker.hashCode(), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.mapbox.mapboxsdk.annotations.Polyline;
|
||||
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
|
||||
@@ -572,16 +573,21 @@ public class MapboxMapTest {
|
||||
|
||||
@Test
|
||||
public void testAddMarker() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
Marker marker = mMapboxMap.addMarker(markerOptions);
|
||||
assertTrue("Marker should be contained", mMapboxMap.getMarkers().contains(marker));
|
||||
}
|
||||
|
||||
@Test(expected = InvalidMarkerPositionException.class)
|
||||
public void testAddMarkerInvalidPosition(){
|
||||
new MarkerOptions().getMarker();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddMarkers() {
|
||||
List<BaseMarkerOptions> markerList = new ArrayList<>();
|
||||
MarkerOptions markerOptions1 = new MarkerOptions().title("a");
|
||||
MarkerOptions markerOptions2 = new MarkerOptions().title("b");
|
||||
MarkerOptions markerOptions1 = new MarkerOptions().position(new LatLng()).title("a");
|
||||
MarkerOptions markerOptions2 = new MarkerOptions().position(new LatLng()).title("b");
|
||||
markerList.add(markerOptions1);
|
||||
markerList.add(markerOptions2);
|
||||
mMapboxMap.addMarkers(markerList);
|
||||
@@ -600,7 +606,7 @@ public class MapboxMapTest {
|
||||
@Test
|
||||
public void testAddMarkersSingleMarker() {
|
||||
List<BaseMarkerOptions> markerList = new ArrayList<>();
|
||||
MarkerOptions markerOptions = new MarkerOptions().title("a");
|
||||
MarkerOptions markerOptions = new MarkerOptions().title("a").position(new LatLng());
|
||||
markerList.add(markerOptions);
|
||||
mMapboxMap.addMarkers(markerList);
|
||||
assertEquals("Markers size should be 1", 1, mMapboxMap.getMarkers().size());
|
||||
@@ -701,7 +707,7 @@ public class MapboxMapTest {
|
||||
|
||||
@Test
|
||||
public void testRemoveMarker() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
Marker marker = mMapboxMap.addMarker(markerOptions);
|
||||
mMapboxMap.removeMarker(marker);
|
||||
assertTrue("Markers should be empty", mMapboxMap.getMarkers().isEmpty());
|
||||
@@ -725,7 +731,7 @@ public class MapboxMapTest {
|
||||
|
||||
@Test
|
||||
public void testRemoveAnnotation() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
Marker marker = mMapboxMap.addMarker(markerOptions);
|
||||
mMapboxMap.removeAnnotation(marker);
|
||||
assertTrue("Annotations should be empty", mMapboxMap.getAnnotations().isEmpty());
|
||||
@@ -733,7 +739,7 @@ public class MapboxMapTest {
|
||||
|
||||
@Test
|
||||
public void testRemoveAnnotationById() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
mMapboxMap.addMarker(markerOptions);
|
||||
// id will always be 0 in unit tests
|
||||
mMapboxMap.removeAnnotation(0);
|
||||
@@ -743,8 +749,8 @@ public class MapboxMapTest {
|
||||
@Test
|
||||
public void testRemoveAnnotations() {
|
||||
List<BaseMarkerOptions> markerList = new ArrayList<>();
|
||||
MarkerOptions markerOptions1 = new MarkerOptions().title("a");
|
||||
MarkerOptions markerOptions2 = new MarkerOptions().title("b");
|
||||
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
|
||||
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
|
||||
markerList.add(markerOptions1);
|
||||
markerList.add(markerOptions2);
|
||||
mMapboxMap.addMarkers(markerList);
|
||||
@@ -755,8 +761,8 @@ public class MapboxMapTest {
|
||||
@Test
|
||||
public void testClear() {
|
||||
List<BaseMarkerOptions> markerList = new ArrayList<>();
|
||||
MarkerOptions markerOptions1 = new MarkerOptions().title("a");
|
||||
MarkerOptions markerOptions2 = new MarkerOptions().title("b");
|
||||
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
|
||||
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
|
||||
markerList.add(markerOptions1);
|
||||
markerList.add(markerOptions2);
|
||||
mMapboxMap.addMarkers(markerList);
|
||||
@@ -767,12 +773,12 @@ public class MapboxMapTest {
|
||||
@Test
|
||||
public void testRemoveAnnotationsByList() {
|
||||
List<BaseMarkerOptions> markerList = new ArrayList<>();
|
||||
MarkerOptions markerOptions1 = new MarkerOptions().title("a");
|
||||
MarkerOptions markerOptions2 = new MarkerOptions().title("b");
|
||||
MarkerOptions markerOptions1 = new MarkerOptions().title("a").position(new LatLng());
|
||||
MarkerOptions markerOptions2 = new MarkerOptions().title("b").position(new LatLng());
|
||||
markerList.add(markerOptions1);
|
||||
markerList.add(markerOptions2);
|
||||
List<Marker> markers = mMapboxMap.addMarkers(markerList);
|
||||
Marker marker = mMapboxMap.addMarker(new MarkerOptions().title("c"));
|
||||
Marker marker = mMapboxMap.addMarker(new MarkerOptions().position(new LatLng()).title("c"));
|
||||
mMapboxMap.removeAnnotations(markers);
|
||||
assertTrue("Annotations should not be empty", mMapboxMap.getAnnotations().size() == 1);
|
||||
assertTrue("Marker should be contained", mMapboxMap.getAnnotations().contains(marker));
|
||||
@@ -780,7 +786,7 @@ public class MapboxMapTest {
|
||||
|
||||
@Test
|
||||
public void testGetAnnotationById() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
Marker initialMarker = mMapboxMap.addMarker(markerOptions);
|
||||
Marker retrievedMarker = (Marker) mMapboxMap.getAnnotation(0);
|
||||
assertEquals("Markers should match", initialMarker, retrievedMarker);
|
||||
@@ -814,7 +820,7 @@ public class MapboxMapTest {
|
||||
@Test
|
||||
public void testSelectMarker() {
|
||||
mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener);
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
Marker marker = mMapboxMap.addMarker(markerOptions);
|
||||
when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true);
|
||||
mMapboxMap.selectMarker(marker);
|
||||
@@ -824,7 +830,7 @@ public class MapboxMapTest {
|
||||
@Test
|
||||
public void testDeselectMarker() {
|
||||
mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener);
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
Marker marker = mMapboxMap.addMarker(markerOptions);
|
||||
when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true);
|
||||
mMapboxMap.selectMarker(marker);
|
||||
@@ -835,7 +841,7 @@ public class MapboxMapTest {
|
||||
@Test
|
||||
public void testDeselectMarkers() {
|
||||
mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener);
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
Marker marker1 = mMapboxMap.addMarker(markerOptions);
|
||||
Marker marker2 = mMapboxMap.addMarker(markerOptions);
|
||||
when(mOnMarkerClickListener.onMarkerClick(marker1)).thenReturn(true);
|
||||
@@ -853,7 +859,7 @@ public class MapboxMapTest {
|
||||
@Test
|
||||
public void testOnMarkerClick() {
|
||||
mMapboxMap.setOnMarkerClickListener(mOnMarkerClickListener);
|
||||
Marker marker = new MarkerOptions().getMarker();
|
||||
Marker marker = new MarkerOptions().position(new LatLng()).getMarker();
|
||||
when(mOnMarkerClickListener.onMarkerClick(marker)).thenReturn(true);
|
||||
mMapboxMap.selectMarker(marker);
|
||||
verify(mOnMarkerClickListener, times(1)).onMarkerClick(marker);
|
||||
|
||||
Reference in New Issue
Block a user