summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
blob: eeb00355bd7a55cb3e1f4ca4fa11976da7fef9b4 (plain)
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
87
88
89
90
91
92
93
94
95
package com.mapbox.mapboxsdk.maps;

import android.graphics.PointF;

import com.mapbox.mapboxsdk.geometry.LatLng;

import org.junit.Test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class MapTouchListenersTest {

  @Test
  public void onMapClickListenerTest() throws Exception {
    LatLng latLng = new LatLng();
    PointF pointF = new PointF();

    Projection projection = mock(Projection.class);
    when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
    MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
      null, projection, null, null, null, null);

    MapboxMap.OnMapClickListener listener = mock(MapboxMap.OnMapClickListener.class);
    mapGestureDetector.addOnMapClickListener(listener);
    mapGestureDetector.notifyOnMapClickListeners(pointF);
    verify(listener, times(1)).onMapClick(latLng);

    mapGestureDetector.removeOnMapClickListener(listener);
    mapGestureDetector.notifyOnMapClickListeners(pointF);
    verify(listener, times(1)).onMapClick(latLng);
  }

  @Test
  public void onMapLongClickListenerTest() throws Exception {
    LatLng latLng = new LatLng();
    PointF pointF = new PointF();

    Projection projection = mock(Projection.class);
    when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
    MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
      null, projection, null, null, null, null);

    MapboxMap.OnMapLongClickListener listener = mock(MapboxMap.OnMapLongClickListener.class);
    mapGestureDetector.addOnMapLongClickListener(listener);
    mapGestureDetector.notifyOnMapLongClickListeners(pointF);
    verify(listener, times(1)).onMapLongClick(latLng);

    mapGestureDetector.removeOnMapLongClickListener(listener);
    mapGestureDetector.notifyOnMapLongClickListeners(pointF);
    verify(listener, times(1)).onMapLongClick(latLng);
  }

  @Test
  public void onFlingListenerTest() throws Exception {
    LatLng latLng = new LatLng();
    PointF pointF = new PointF();

    Projection projection = mock(Projection.class);
    when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
    MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
      null, projection, null, null, null, null);

    MapboxMap.OnFlingListener listener = mock(MapboxMap.OnFlingListener.class);
    mapGestureDetector.addOnFlingListener(listener);
    mapGestureDetector.notifyOnFlingListeners();
    verify(listener, times(1)).onFling();

    mapGestureDetector.removeOnFlingListener(listener);
    mapGestureDetector.notifyOnFlingListeners();
    verify(listener, times(1)).onFling();
  }

  @Test
  public void onScrollListenerTest() throws Exception {
    LatLng latLng = new LatLng();
    PointF pointF = new PointF();

    Projection projection = mock(Projection.class);
    when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
    MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
      null, projection, null, null, null, null);

    MapboxMap.OnScrollListener listener = mock(MapboxMap.OnScrollListener.class);
    mapGestureDetector.addOnScrollListener(listener);
    mapGestureDetector.notifyOnScrollListeners();
    verify(listener, times(1)).onScroll();

    mapGestureDetector.removeOnScrollListener(listener);
    mapGestureDetector.notifyOnScrollListeners();
    verify(listener, times(1)).onScroll();
  }
}