1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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.position(new LatLng()).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().position(new LatLng()).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().position(new LatLng()).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();
}
}
|