Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #4017 - update unit test for MapboxMap
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Feb 18, 2016
1 parent dd7bbc0 commit e578b60
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attrs)
// Shows the zoom controls
if (!context.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
mMapboxMap.setZoomControlsEnabled(true);
mMapboxMap.getUiSettings().setZoomControlsEnabled(true);
}
mZoomButtonsController = new ZoomButtonsController(this);
mZoomButtonsController.setZoomSpeed(MapboxConstants.ANIMATION_DURATION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.mapbox.mapboxsdk.maps;

import android.Manifest;
import android.content.Context;

import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.LongSparseArray;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -369,11 +366,6 @@ public double getMaxZoom() {
// Manual zoom controls
//

// used by UiSettings
void setZoomControlsEnabled(boolean enabled) {
mMapView.setZoomControlsEnabled(enabled);
}

//
// Debug
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Point;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.View;

import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
Expand Down Expand Up @@ -47,6 +50,39 @@ public class MapboxMapTest {
@Mock
MapboxMap.OnMarkerClickListener mOnMarkerClickListener;

@Mock
MapboxMap.OnCameraChangeListener mOnCameraChangeListener;

@Mock
MapboxMap.InfoWindowAdapter mInfoWindowAdapter;

@Mock
MapboxMap.OnScrollListener mScrollListener;

@Mock
MapboxMap.OnFlingListener mFlingListener;

@Mock
MapboxMap.OnFpsChangedListener mFpsChangedListener;

@Mock
MapboxMap.OnInfoWindowClickListener mWindowClickListener;

@Mock
MapboxMap.OnInfoWindowCloseListener mWindowCloseListener;

@Mock
MapboxMap.OnInfoWindowLongClickListener mWindowLongClickListener;

@Mock
MapboxMap.OnMyLocationChangeListener mLocationChangeListener;

@Mock
MapboxMap.OnMyLocationTrackingModeChangeListener mMyLocationTrackingModeChangeListener;

@Mock
MapboxMap.OnMyBearingTrackingModeChangeListener mMyBearingTrackingModeChangeListener;

@Before
public void beforeTest() {
MockitoAnnotations.initMocks(this);
Expand Down Expand Up @@ -77,6 +113,15 @@ public void testUiSettings() {
assertNotNull("UiSettings should not be null", mMapboxMap.getUiSettings());
}

//
// TrackingSettings
//

@Test
public void testTrackingSettings() {
assertNotNull("TrackingSettings should not be null", mMapboxMap.getTrackingSettings());
}

//
// Projection
//
Expand All @@ -86,7 +131,6 @@ public void testProjection() {
assertNotNull("Projection should not be null", mMapboxMap.getProjection());
}


//
// InfoWindow
//
Expand All @@ -103,6 +147,12 @@ public void testConcurrentInfoWindowDisabled() {
assertFalse("ConcurrentWindows should be false", mMapboxMap.isAllowConcurrentMultipleOpenInfoWindows());
}

@Test
public void testInfoWindowAdapter() {
mMapboxMap.setInfoWindowAdapter(mInfoWindowAdapter);
assertEquals("InfoWindowAdpter should be the same", mInfoWindowAdapter, mMapboxMap.getInfoWindowAdapter());
}

//
// Location
//
Expand All @@ -122,6 +172,76 @@ public void testMyLocationDisabled() {
assertFalse("MyLocationEnabled should be false", mMapboxMap.isMyLocationEnabled());
}

//
// padding
//

@Test
public void testPadding() {
mMapboxMap.setOnCameraChangeListener(mOnCameraChangeListener);
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(position));
mMapboxMap.setPadding(0, 0, 0, 0);
verify(mOnCameraChangeListener, times(2)).onCameraChange(position);
}

//
// setters/getters interfaces
//

@Test
public void testScrollListener() {
mMapboxMap.setOnScrollListener(mScrollListener);
assertEquals("ScrollListener should match", mScrollListener, mMapboxMap.getOnScrollListener());
}

@Test
public void testFlingListener() {
mMapboxMap.setOnFlingListener(mFlingListener);
assertEquals("FlingListener should match", mFlingListener, mMapboxMap.getOnFlingListener());
}

@Test
public void testFpsListener() {
mMapboxMap.setOnFpsChangedListener(mFpsChangedListener);
assertEquals("FpsListener should match", mFpsChangedListener, mMapboxMap.getOnFpsChangedListener());
}

@Test
public void testInfoWindowClickListener() {
mMapboxMap.setOnInfoWindowClickListener(mWindowClickListener);
assertEquals("InfoWidowClickListener should match", mWindowClickListener, mMapboxMap.getOnInfoWindowClickListener());
}

@Test
public void testInfoWindowCloseListener() {
mMapboxMap.setOnInfoWindowCloseListener(mWindowCloseListener);
assertEquals("InfoWindowCloseListener should match", mWindowCloseListener, mMapboxMap.getOnInfoWindowCloseListener());
}

@Test
public void testInfoWindowLongClickListener() {
mMapboxMap.setOnInfoWindowLongClickListener(mWindowLongClickListener);
assertEquals("InfoWindowLongClickListener should match", mWindowLongClickListener, mMapboxMap.getOnInfoWindowLongClickListener());
}

@Test
public void testOnBearingTrackingModeChangeListener(){
mMapboxMap.setOnMyBearingTrackingModeChangeListener(mMyBearingTrackingModeChangeListener);
assertEquals("MyBearingTrackingChangeListerner should match",mMyBearingTrackingModeChangeListener, mMapboxMap.getOnMyBearingTrackingModeChangeListener());
}

@Test
public void testOnLocationTrackingModeChangeListener(){
mMapboxMap.setOnMyLocationTrackingModeChangeListener(mMyLocationTrackingModeChangeListener);
assertEquals("MyLocationTrackigChangeListener should match",mMyLocationTrackingModeChangeListener, mMapboxMap.getOnMyLocationTrackingModeChangeListener());
}

@Test
public void testOnMyLocationChangeListener(){
mMapboxMap.setOnMyLocationChangeListener(mLocationChangeListener);
assertEquals("Location change listener should match",mLocationChangeListener, mMapboxMap.getMapView().get);
}
//
// Style
//
Expand Down Expand Up @@ -199,7 +319,7 @@ public void testNewCameraPositionAnimateCameraWithDurationAndCallbackParameter()
@Test
public void testNewCameraPositionEaseCamera() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position), 1000);
mMapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position));
assertEquals("CameraPosition should be same", position, mMapboxMap.getCameraPosition());
}

Expand Down Expand Up @@ -384,6 +504,18 @@ public void testZoomToEaseCamera() {
assertTrue("Zoomlevel should be same", 12 == mMapboxMap.getCameraPosition().zoom);
}

//
// OnCameraChangeListener
//

@Test
public void testOnCameraChangeListener() {
CameraPosition position = new CameraPosition.Builder().bearing(1).tilt(2).zoom(3).target(new LatLng(4, 5)).build();
mMapboxMap.setOnCameraChangeListener(mOnCameraChangeListener);
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(position));
verify(mOnCameraChangeListener, times(1)).onCameraChange(position);
}

//
// Annotations
//
Expand Down

0 comments on commit e578b60

Please sign in to comment.