diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-10-10 23:51:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-10 23:51:30 +0200 |
commit | e598bbfa7c29ad3a384e157b504c4509f1fcdbb5 (patch) | |
tree | 6dcdb0f9a358c0168b83097a97abb85b5f6aa729 /platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com | |
parent | 5891c7028dbc6ae6decb5a3b059fd48f4e700d44 (diff) | |
download | qtlocation-mapboxgl-e598bbfa7c29ad3a384e157b504c4509f1fcdbb5.tar.gz |
Rotate markerview (#6640)
* [android] - MarkerView rotation bug, limit degrees from 0 to 360 while creating a MarkerView
* update MarkerView#setRotation to limit input from 0 - 360 degrees, calculates difference in angle and animates rotation by a certain amount instead of animating to a value. Exposed new AnimatorUtils#animateRotationTo. Integrated into MarkerViewManager. Cleanup some unused imports. Updated javadoc.
* updated MarkerViewActivity in test application to test for regressions.
* added tests to validate changes to MarkerView#setRotate
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java | 102 |
1 files changed, 101 insertions, 1 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java index e6c30f4aac..6cef1898bd 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerViewTest.java @@ -4,18 +4,36 @@ import android.os.Parcelable; import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.utils.MockParcel; +import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class MarkerViewTest { + @Mock + MapboxMap mapboxMap; + + @Mock + MarkerViewManager markerViewManager; + + @Before + public void beforeTest() { + MockitoAnnotations.initMocks(this); + } + @Test public void testSanity() { MarkerViewOptions markerOptions = new MarkerViewOptions(); @@ -29,7 +47,7 @@ public class MarkerViewTest { } @Test(expected = InvalidMarkerPositionException.class) - public void testInvalidMarker(){ + public void testInvalidMarker() { new MarkerViewOptions().getMarker(); } @@ -111,6 +129,88 @@ public class MarkerViewTest { } @Test + public void testRotationAboveMax() { + MarkerViewOptions markerOptions = new MarkerViewOptions().rotation(390).position(new LatLng()); + MarkerView marker = markerOptions.getMarker(); + assertEquals(marker.getRotation(), 30, 0); + } + + @Test + public void testRotationBelowMin() { + MarkerViewOptions markerOptions = new MarkerViewOptions().rotation(-10).position(new LatLng()); + MarkerView marker = markerOptions.getMarker(); + assertEquals(marker.getRotation(), 350, 0); + } + + @Test + public void testRotationUpdatePositive() { + float startRotation = 45; + float endRotation = 180; + float animationValue = 135; + + // allow calls to our mock + when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); + + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); + MarkerView marker = markerOptions.getMarker(); + marker.setMapboxMap(mapboxMap); + + marker.setRotation(endRotation); + verify(markerViewManager, times(1)).animateRotationBy(marker, animationValue); + } + + @Test + public void testRotationUpdateNegative() { + float startRotation = 10; + float endRotation = 270; + float animationValue = -100; + + // allow calls to our mock + when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); + + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); + MarkerView marker = markerOptions.getMarker(); + marker.setMapboxMap(mapboxMap); + + marker.setRotation(endRotation); + verify(markerViewManager, times(1)).animateRotationBy(marker, animationValue); + } + + @Test + public void testRotationUpdateMax() { + float startRotation = 359; + float endRotation = 0; + float animationValue = 1; + + // allow calls to our mock + when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); + + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); + MarkerView marker = markerOptions.getMarker(); + marker.setMapboxMap(mapboxMap); + + marker.setRotation(endRotation); + verify(markerViewManager, times(1)).animateRotationBy(marker, animationValue); + } + + @Test + public void testRotationUpdateMin() { + float startRotation = 0; + float endRotation = 359; + float animationValue = -1; + + // allow calls to our mock + when(mapboxMap.getMarkerViewManager()).thenReturn(markerViewManager); + + MarkerViewOptions markerOptions = new MarkerViewOptions().position(new LatLng()).rotation(startRotation); + MarkerView marker = markerOptions.getMarker(); + marker.setMapboxMap(mapboxMap); + + marker.setRotation(endRotation); + verify(markerViewManager, times(1)).animateRotationBy(marker, animationValue); + } + + @Test public void testVisible() { boolean visible = false; MarkerViewOptions markerOptions = new MarkerViewOptions().visible(visible).position(new LatLng()); |