summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2016-02-18 11:12:50 +0100
committerTobrun <tobrun@mapbox.com>2016-02-18 11:46:48 +0100
commita24d06b9925c302fe4f4c3db754468c7dc9aa3ef (patch)
tree19521e90a09d036875299ae1293afeb7162f67fe /platform/android
parentdaedb3ddb21c34559f2ca53d747849c10916b7c1 (diff)
downloadqtlocation-mapboxgl-a24d06b9925c302fe4f4c3db754468c7dc9aa3ef.tar.gz
[android] #4003 - add unit tests for InfoWindow
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java10
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java86
2 files changed, 93 insertions, 3 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
index f94867fc1a..d8763e321d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java
@@ -192,10 +192,10 @@ public class InfoWindow {
if (mIsVisible) {
mIsVisible = false;
View view = mView.get();
- if (view != null) {
+ if (view != null && view.getParent() != null) {
((ViewGroup) view.getParent()).removeView(view);
- onClose();
}
+ onClose();
}
return this;
}
@@ -223,7 +223,7 @@ public class InfoWindow {
MapboxMap mapboxMap = mMapboxMap.get();
if (mapboxMap != null) {
MapboxMap.OnInfoWindowCloseListener listener = mapboxMap.getOnInfoWindowCloseListener();
- if(listener!=null){
+ if (listener != null) {
listener.onInfoWindowClose(getBoundMarker());
}
mapboxMap.deselectMarker(getBoundMarker());
@@ -254,4 +254,8 @@ public class InfoWindow {
}
}
+ boolean isVisible() {
+ return mIsVisible;
+ }
+
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java
new file mode 100644
index 0000000000..11ab8173fd
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/InfoWindowTest.java
@@ -0,0 +1,86 @@
+package com.mapbox.mapboxsdk.annotations;
+
+import android.graphics.PointF;
+
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.Projection;
+
+import org.junit.Test;
+import org.mockito.InjectMocks;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class InfoWindowTest {
+
+ @InjectMocks
+ MapView mMapView = mock(MapView.class);
+
+ @InjectMocks
+ MapboxMap mMapboxMap = mock(MapboxMap.class);
+
+ @Test
+ public void testSanity() {
+ InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
+ assertNotNull("infoWindow should exist", infoWindow);
+ }
+
+ @Test
+ public void testBoundMarker() {
+ MarkerOptions markerOptions = new MarkerOptions();
+ Marker marker = markerOptions.getMarker();
+ InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap).setBoundMarker(marker);
+ assertEquals("marker should match", marker, infoWindow.getBoundMarker());
+ }
+
+ @Test
+ public void testClose() {
+ InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
+ infoWindow.close();
+ assertEquals("infowindow should not be visible", false, infoWindow.isVisible());
+ }
+
+
+ @Test
+ public void testOpen() {
+ LatLng latLng = new LatLng(0, 0);
+ Projection projection = mock(Projection.class);
+ when(mMapboxMap.getProjection()).thenReturn(projection);
+ when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0));
+
+ InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
+ infoWindow.open(mMapView, new MarkerOptions().getMarker(), latLng, 0, 0);
+ assertEquals("infowindow should not be visible", true, infoWindow.isVisible());
+ }
+
+ @Test
+ public void testOpenClose() {
+ LatLng latLng = new LatLng(0, 0);
+ Projection projection = mock(Projection.class);
+ when(mMapboxMap.getProjection()).thenReturn(projection);
+ 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.close();
+ assertEquals("infowindow should not be visible", false, infoWindow.isVisible());
+ }
+
+
+ @Test
+ public void testUpdate() {
+ LatLng latLng = new LatLng(0, 0);
+ Projection projection = mock(Projection.class);
+ when(mMapboxMap.getProjection()).thenReturn(projection);
+ when(projection.toScreenLocation(latLng)).thenReturn(new PointF(0, 0));
+
+ InfoWindow infoWindow = new InfoWindow(mMapView, mMapboxMap);
+ infoWindow.open(mMapView, new MarkerOptions().position(latLng).getMarker(), latLng, 0, 0);
+ infoWindow.update();
+ }
+
+}