From e598bbfa7c29ad3a384e157b504c4509f1fcdbb5 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Mon, 10 Oct 2016 23:51:30 +0200 Subject: 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 --- .../mapboxsdk/annotations/MarkerViewTest.java | 102 ++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox') 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(); } @@ -110,6 +128,88 @@ public class MarkerViewTest { assertEquals("rotation should match ", rotation, marker.getRotation(), 0); } + @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; -- cgit v1.2.1