Port Android Unit tests to Kotlin (#681)
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class AnnotationTest {
|
||||
|
||||
@InjectMocks
|
||||
private MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
private Annotation annotation;
|
||||
@NonNull
|
||||
private Annotation compare = new Annotation() {
|
||||
@Override
|
||||
public long getId() {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
annotation = new Annotation() {
|
||||
// empty child
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("markerOptions should not be null", annotation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
annotation.setId(1);
|
||||
annotation.setMapboxMap(mapboxMap);
|
||||
annotation.remove();
|
||||
verify(mapboxMap, times(1)).removeAnnotation(annotation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveUnboundMapboxMap() {
|
||||
annotation.setId(1);
|
||||
annotation.remove();
|
||||
verify(mapboxMap, times(0)).removeAnnotation(annotation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareToEqual() {
|
||||
annotation.setId(1);
|
||||
assertEquals("conparable equal", 0, annotation.compareTo(compare));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareToHigher() {
|
||||
annotation.setId(3);
|
||||
assertEquals("conparable higher", -1, annotation.compareTo(compare));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompareTolower() {
|
||||
annotation.setId(0);
|
||||
assertEquals("conparable lower", 1, annotation.compareTo(compare));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Annotation holder = null;
|
||||
assertFalse(annotation.equals(holder));
|
||||
holder = annotation;
|
||||
assertTrue(annotation.equals(holder));
|
||||
assertFalse(annotation.equals(new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
int id = 1;
|
||||
annotation.setId(id);
|
||||
assertSame("hashcode should match", annotation.hashCode(), id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.mapbox.mapboxsdk.annotations
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mockito
|
||||
|
||||
class AnnotationTest {
|
||||
@InjectMocks
|
||||
private val mapboxMap = Mockito.mock(MapboxMap::class.java)
|
||||
private var annotation: Annotation? = null
|
||||
private val compare: Annotation = object : Annotation() {
|
||||
override fun getId(): Long {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
fun beforeTest() {
|
||||
annotation = object : Annotation() { // empty child
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSanity() {
|
||||
Assert.assertNotNull("markerOptions should not be null", annotation)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRemove() {
|
||||
annotation!!.id = 1
|
||||
annotation!!.setMapboxMap(mapboxMap)
|
||||
annotation!!.remove()
|
||||
Mockito.verify(mapboxMap, Mockito.times(1)).removeAnnotation(
|
||||
annotation!!
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRemoveUnboundMapboxMap() {
|
||||
annotation!!.id = 1
|
||||
annotation!!.remove()
|
||||
Mockito.verify(mapboxMap, Mockito.times(0)).removeAnnotation(
|
||||
annotation!!
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompareToEqual() {
|
||||
annotation!!.id = 1
|
||||
Assert.assertEquals("conparable equal", 0, annotation!!.compareTo(compare).toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompareToHigher() {
|
||||
annotation!!.id = 3
|
||||
Assert.assertEquals("conparable higher", -1, annotation!!.compareTo(compare).toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompareTolower() {
|
||||
annotation!!.id = 0
|
||||
Assert.assertEquals("conparable lower", 1, annotation!!.compareTo(compare).toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquals() {
|
||||
var holder: Annotation? = null
|
||||
Assert.assertFalse(annotation == holder)
|
||||
holder = annotation
|
||||
Assert.assertTrue(annotation == holder)
|
||||
Assert.assertFalse(annotation == Any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashcode() {
|
||||
val id = 1
|
||||
annotation!!.id = id.toLong()
|
||||
Assert.assertSame("hashcode should match", annotation.hashCode(), id)
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotSame;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IconTest {
|
||||
|
||||
@Mock
|
||||
Bitmap bitmap;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(bitmap.getConfig()).thenReturn(Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testId() {
|
||||
String id = "test";
|
||||
Icon icon = IconFactory.recreate(id, Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8));
|
||||
assertEquals("id should match", id, icon.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBitmap() {
|
||||
Icon icon = IconFactory.recreate("test", bitmap);
|
||||
assertEquals("bitmap should match", bitmap, icon.getBitmap());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Icon icon1 = IconFactory.recreate("test", bitmap);
|
||||
Icon icon2 = IconFactory.recreate("test", bitmap);
|
||||
assertEquals("icons should not match", icon1, icon2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsObject() {
|
||||
Icon icon = IconFactory.recreate("test", Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8));
|
||||
assertNotSame("icon should not match", new Object(), icon);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
Icon icon = IconFactory.recreate("test", bitmap);
|
||||
long expectedHashcode = 31 * bitmap.hashCode() + "test".hashCode();
|
||||
assertEquals("hashcode should match", expectedHashcode, icon.hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.mapbox.mapboxsdk.annotations
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import junit.framework.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class IconTest {
|
||||
@Mock
|
||||
var bitmap: Bitmap? = null
|
||||
|
||||
@Before
|
||||
fun beforeTest() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
Mockito.`when`(bitmap!!.config).thenReturn(Bitmap.Config.ARGB_8888)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testId() {
|
||||
val id = "test"
|
||||
val icon = IconFactory.recreate(id, Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8))
|
||||
Assert.assertEquals("id should match", id, icon.id)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBitmap() {
|
||||
val icon = IconFactory.recreate("test", bitmap!!)
|
||||
Assert.assertEquals("bitmap should match", bitmap, icon.bitmap)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquals() {
|
||||
val icon1 = IconFactory.recreate("test", bitmap!!)
|
||||
val icon2 = IconFactory.recreate("test", bitmap!!)
|
||||
Assert.assertEquals("icons should not match", icon1, icon2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualsObject() {
|
||||
val icon = IconFactory.recreate("test", Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8))
|
||||
Assert.assertNotSame("icon should not match", Any(), icon)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashcode() {
|
||||
val icon = IconFactory.recreate("test", bitmap!!)
|
||||
val expectedHashcode = (31 * bitmap.hashCode() + "test".hashCode()).toLong()
|
||||
Assert.assertEquals("hashcode should match", expectedHashcode, icon.hashCode().toLong())
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
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.Assert
|
||||
import org.junit.Test
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mockito
|
||||
|
||||
class InfoWindowTest {
|
||||
@InjectMocks
|
||||
var mMapView = Mockito.mock(MapView::class.java)
|
||||
|
||||
@InjectMocks
|
||||
var mMapboxMap = Mockito.mock(MapboxMap::class.java)
|
||||
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val infoWindow = InfoWindow(mMapView, mMapboxMap)
|
||||
Assert.assertNotNull("infoWindow should exist", infoWindow)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBoundMarker() {
|
||||
val markerOptions = MarkerOptions()
|
||||
val marker = markerOptions.position(LatLng()).marker
|
||||
val infoWindow = InfoWindow(mMapView, mMapboxMap).setBoundMarker(marker)
|
||||
Assert.assertEquals("marker should match", marker, infoWindow.boundMarker)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClose() {
|
||||
val infoWindow = InfoWindow(mMapView, mMapboxMap)
|
||||
infoWindow.close()
|
||||
Assert.assertEquals("infowindow should not be visible", false, infoWindow.isVisible)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOpen() {
|
||||
val latLng = LatLng(0.0, 0.0)
|
||||
val projection = Mockito.mock(
|
||||
Projection::class.java
|
||||
)
|
||||
Mockito.`when`(mMapboxMap.projection).thenReturn(projection)
|
||||
Mockito.`when`(projection.toScreenLocation(latLng)).thenReturn(PointF(0f, 0f))
|
||||
val infoWindow = InfoWindow(mMapView, mMapboxMap)
|
||||
infoWindow.open(mMapView, MarkerOptions().position(LatLng()).marker, latLng, 0, 0)
|
||||
Assert.assertEquals("infowindow should not be visible", true, infoWindow.isVisible)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOpenClose() {
|
||||
val latLng = LatLng(0.0, 0.0)
|
||||
val projection = Mockito.mock(
|
||||
Projection::class.java
|
||||
)
|
||||
Mockito.`when`(mMapboxMap.projection).thenReturn(projection)
|
||||
Mockito.`when`(projection.toScreenLocation(latLng)).thenReturn(PointF(0f, 0f))
|
||||
val infoWindow = InfoWindow(mMapView, mMapboxMap)
|
||||
infoWindow.open(mMapView, MarkerOptions().position(LatLng()).marker, latLng, 0, 0)
|
||||
infoWindow.close()
|
||||
Assert.assertEquals("infowindow should not be visible", false, infoWindow.isVisible)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUpdate() {
|
||||
val latLng = LatLng(0.0, 0.0)
|
||||
val projection = Mockito.mock(
|
||||
Projection::class.java
|
||||
)
|
||||
Mockito.`when`(mMapboxMap.projection).thenReturn(projection)
|
||||
Mockito.`when`(projection.toScreenLocation(latLng)).thenReturn(PointF(0f, 0f))
|
||||
val infoWindow = InfoWindow(mMapView, mMapboxMap)
|
||||
infoWindow.open(mMapView, MarkerOptions().position(latLng).marker, latLng, 0, 0)
|
||||
infoWindow.update()
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class MarkerTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
assertNotNull("markerOptions should not be null", markerOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarker() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
|
||||
assertNotNull("marker should not be null", markerOptions.getMarker());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidMarkerPositionException.class)
|
||||
public void testInvalidMarker() {
|
||||
new MarkerOptions().getMarker();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPosition() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12));
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getPosition(), new LatLng(10, 12));
|
||||
assertEquals(markerOptions.getPosition(), new LatLng(10, 12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitle() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().title("Mapbox").position(new LatLng());
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getTitle(), "Mapbox");
|
||||
assertEquals(markerOptions.getTitle(), "Mapbox");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSnippet() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().snippet("Mapbox").position(new LatLng());
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals(marker.getSnippet(), "Mapbox");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
Marker marker = new MarkerOptions().title("title").snippet("snippet").position(new LatLng(10, 12)).getMarker();
|
||||
assertEquals(marker.getSnippet(), "snippet");
|
||||
|
||||
assertEquals(marker.getPosition(), new LatLng(10, 12));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIcon() {
|
||||
Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
|
||||
Icon icon = IconFactory.recreate("test", bitmap);
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).icon(icon);
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals("Icon should match", icon, marker.getIcon());
|
||||
assertEquals("Icon should match", icon, markerOptions.getIcon());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
Marker marker = new MarkerOptions().position(new LatLng()).getMarker();
|
||||
assertEquals("hash code should match", marker.hashCode(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCodeBuilder() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12));
|
||||
assertEquals("hash code should match", markerOptions.hashCode(), 579999617);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
Marker markerOne = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
|
||||
Marker markerTwo = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
|
||||
assertEquals(markerOne, markerTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityDifferentLocation() {
|
||||
MarkerOptions marker = new MarkerOptions().position(new LatLng(0, 0));
|
||||
MarkerOptions other = new MarkerOptions().position(new LatLng(1, 0));
|
||||
assertNotEquals("Should not match", other, marker);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEqualityDifferentSnippet() {
|
||||
MarkerOptions marker = new MarkerOptions().snippet("s");
|
||||
MarkerOptions other = new MarkerOptions();
|
||||
assertNotEquals("Should not match", other, marker);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityDifferentIcon() {
|
||||
MarkerOptions marker = new MarkerOptions().icon(mock(Icon.class));
|
||||
MarkerOptions other = new MarkerOptions();
|
||||
assertNotEquals("Should not match", other, marker);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityDifferentTitle() {
|
||||
MarkerOptions marker = new MarkerOptions().title("t");
|
||||
MarkerOptions other = new MarkerOptions();
|
||||
assertNotEquals("Should not match", other, marker);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsItself() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(0, 0));
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertEquals("Marker should match", marker, marker);
|
||||
assertEquals("MarkerOptions should match", markerOptions, markerOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEquals() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(0, 0));
|
||||
Marker marker = markerOptions.getMarker();
|
||||
assertNotEquals("MarkerOptions should match", markerOptions, new Object());
|
||||
assertNotEquals("Marker should match", marker, new Object());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualityBuilder() {
|
||||
MarkerOptions markerOne = new MarkerOptions().position(new LatLng(0, 0));
|
||||
MarkerOptions markerTwo = new MarkerOptions().position(new LatLng(0, 0));
|
||||
assertEquals(markerOne, markerTwo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
Marker marker = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
|
||||
assertEquals(marker.toString(), "Marker [position[" + "LatLng [latitude=0.0, longitude=0.0, altitude=0.0]" + "]]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).title("t").snippet("s");
|
||||
Parcelable parcelable = MockParcel.obtain(markerOptions);
|
||||
assertEquals("Parcel should match original object", parcelable, markerOptions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.mapbox.mapboxsdk.annotations
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito
|
||||
|
||||
class MarkerTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val markerOptions = MarkerOptions()
|
||||
Assert.assertNotNull("markerOptions should not be null", markerOptions)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMarker() {
|
||||
val markerOptions = MarkerOptions().position(LatLng())
|
||||
Assert.assertNotNull("marker should not be null", markerOptions.marker)
|
||||
}
|
||||
|
||||
@Test(expected = InvalidMarkerPositionException::class)
|
||||
fun testInvalidMarker() {
|
||||
MarkerOptions().marker
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPosition() {
|
||||
val markerOptions = MarkerOptions().position(LatLng(10.0, 12.0))
|
||||
val marker = markerOptions.marker
|
||||
Assert.assertEquals(marker.position, LatLng(10.0, 12.0))
|
||||
Assert.assertEquals(markerOptions.getPosition(), LatLng(10.0, 12.0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTitle() {
|
||||
val markerOptions = MarkerOptions().title("Mapbox").position(LatLng())
|
||||
val marker = markerOptions.marker
|
||||
Assert.assertEquals(marker.title, "Mapbox")
|
||||
Assert.assertEquals(markerOptions.getTitle(), "Mapbox")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSnippet() {
|
||||
val markerOptions = MarkerOptions().snippet("Mapbox").position(LatLng())
|
||||
val marker = markerOptions.marker
|
||||
Assert.assertEquals(marker.snippet, "Mapbox")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBuilder() {
|
||||
val marker =
|
||||
MarkerOptions().title("title").snippet("snippet").position(LatLng(10.0, 12.0)).marker
|
||||
Assert.assertEquals(marker.snippet, "snippet")
|
||||
Assert.assertEquals(marker.position, LatLng(10.0, 12.0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIcon() {
|
||||
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444)
|
||||
val icon = IconFactory.recreate("test", bitmap)
|
||||
val markerOptions = MarkerOptions().position(LatLng()).icon(icon)
|
||||
val marker = markerOptions.marker
|
||||
Assert.assertEquals("Icon should match", icon, marker.icon)
|
||||
Assert.assertEquals("Icon should match", icon, markerOptions.getIcon())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashCode() {
|
||||
val marker = MarkerOptions().position(LatLng()).marker
|
||||
Assert.assertEquals("hash code should match", marker.hashCode().toLong(), 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashCodeBuilder() {
|
||||
val markerOptions = MarkerOptions().position(LatLng(10.0, 12.0))
|
||||
Assert.assertEquals("hash code should match", markerOptions.hashCode().toLong(), 579999617)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquals() {
|
||||
val markerOne = MarkerOptions().position(LatLng(0.0, 0.0)).marker
|
||||
val markerTwo = MarkerOptions().position(LatLng(0.0, 0.0)).marker
|
||||
Assert.assertEquals(markerOne, markerTwo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualityDifferentLocation() {
|
||||
val marker = MarkerOptions().position(LatLng(0.0, 0.0))
|
||||
val other = MarkerOptions().position(LatLng(1.0, 0.0))
|
||||
Assert.assertNotEquals("Should not match", other, marker)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualityDifferentSnippet() {
|
||||
val marker = MarkerOptions().snippet("s")
|
||||
val other = MarkerOptions()
|
||||
Assert.assertNotEquals("Should not match", other, marker)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualityDifferentIcon() {
|
||||
val marker = MarkerOptions().icon(
|
||||
Mockito.mock(
|
||||
Icon::class.java
|
||||
)
|
||||
)
|
||||
val other = MarkerOptions()
|
||||
Assert.assertNotEquals("Should not match", other, marker)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualityDifferentTitle() {
|
||||
val marker = MarkerOptions().title("t")
|
||||
val other = MarkerOptions()
|
||||
Assert.assertNotEquals("Should not match", other, marker)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualsItself() {
|
||||
val markerOptions = MarkerOptions().position(LatLng(0.0, 0.0))
|
||||
val marker = markerOptions.marker
|
||||
Assert.assertEquals("Marker should match", marker, marker)
|
||||
Assert.assertEquals("MarkerOptions should match", markerOptions, markerOptions)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNotEquals() {
|
||||
val markerOptions = MarkerOptions().position(LatLng(0.0, 0.0))
|
||||
val marker = markerOptions.marker
|
||||
Assert.assertNotEquals("MarkerOptions should match", markerOptions, Any())
|
||||
Assert.assertNotEquals("Marker should match", marker, Any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualityBuilder() {
|
||||
val markerOne = MarkerOptions().position(LatLng(0.0, 0.0))
|
||||
val markerTwo = MarkerOptions().position(LatLng(0.0, 0.0))
|
||||
Assert.assertEquals(markerOne, markerTwo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToString() {
|
||||
val marker = MarkerOptions().position(LatLng(0.0, 0.0)).marker
|
||||
Assert.assertEquals(
|
||||
marker.toString(),
|
||||
"Marker [position[" + "LatLng [latitude=0.0, longitude=0.0, altitude=0.0]" + "]]"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParcelable() {
|
||||
val markerOptions = MarkerOptions().position(LatLng()).title("t").snippet("s")
|
||||
val parcelable = MockParcel.obtain(markerOptions)
|
||||
Assert.assertEquals("Parcel should match original object", parcelable, markerOptions)
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class PolygonTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
PolygonOptions polygonOptions = new PolygonOptions();
|
||||
assertNotNull("polygonOptions should not be null", polygonOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolygon() {
|
||||
Polygon polygon = new PolygonOptions().getPolygon();
|
||||
assertNotNull("polyline should not be null", polygon);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlpha() {
|
||||
Polygon polygon = new PolygonOptions().alpha(0.5f).getPolygon();
|
||||
assertEquals(0.5f, polygon.getAlpha(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrokeColor() {
|
||||
Polygon polygon = new PolygonOptions().strokeColor(1).getPolygon();
|
||||
assertEquals(1, polygon.getStrokeColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFillColor() {
|
||||
Polygon polygon = new PolygonOptions().fillColor(1).getPolygon();
|
||||
assertEquals(1, polygon.getFillColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatLng() {
|
||||
Polygon polygon = new PolygonOptions().add(new LatLng(0, 0)).getPolygon();
|
||||
assertNotNull("points should not be null", polygon.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polygon.getPoints().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAllLatLng() {
|
||||
List<LatLng> coordinates = new ArrayList<>();
|
||||
coordinates.add(new LatLng(0, 0));
|
||||
Polygon polygon = new PolygonOptions().addAll(coordinates).getPolygon();
|
||||
assertNotNull(polygon.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polygon.getPoints().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
PolylineOptions polylineOptions = new PolylineOptions();
|
||||
polylineOptions.width(1.0f);
|
||||
polylineOptions.color(2);
|
||||
polylineOptions.add(new LatLng(0, 0));
|
||||
|
||||
Polyline polyline = polylineOptions.getPolyline();
|
||||
assertEquals(1.0f, polyline.getWidth(), 0);
|
||||
assertEquals(2, polyline.getColor());
|
||||
assertNotNull("Points should not be null", polyline.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polyline.getPoints().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mapbox.mapboxsdk.annotations
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class PolygonTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val polygonOptions = PolygonOptions()
|
||||
Assert.assertNotNull("polygonOptions should not be null", polygonOptions)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPolygon() {
|
||||
val polygon = PolygonOptions().polygon
|
||||
Assert.assertNotNull("polyline should not be null", polygon)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAlpha() {
|
||||
val polygon = PolygonOptions().alpha(0.5f).polygon
|
||||
Assert.assertEquals(0.5f, polygon.alpha, 0.0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStrokeColor() {
|
||||
val polygon = PolygonOptions().strokeColor(1).polygon
|
||||
Assert.assertEquals(1, polygon.strokeColor.toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFillColor() {
|
||||
val polygon = PolygonOptions().fillColor(1).polygon
|
||||
Assert.assertEquals(1, polygon.fillColor.toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatLng() {
|
||||
val polygon = PolygonOptions().add(LatLng(0.0, 0.0)).polygon
|
||||
Assert.assertNotNull("points should not be null", polygon.points)
|
||||
Assert.assertEquals(LatLng(0.0, 0.0), polygon.points[0])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddAllLatLng() {
|
||||
val coordinates: MutableList<LatLng> = ArrayList()
|
||||
coordinates.add(LatLng(0.0, 0.0))
|
||||
val polygon = PolygonOptions().addAll(coordinates).polygon
|
||||
Assert.assertNotNull(polygon.points)
|
||||
Assert.assertEquals(LatLng(0.0, 0.0), polygon.points[0])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBuilder() {
|
||||
val polylineOptions = PolylineOptions()
|
||||
polylineOptions.width(1.0f)
|
||||
polylineOptions.color(2)
|
||||
polylineOptions.add(LatLng(0.0, 0.0))
|
||||
val polyline = polylineOptions.polyline
|
||||
Assert.assertEquals(1.0f, polyline.width, 0f)
|
||||
Assert.assertEquals(2, polyline.color.toLong())
|
||||
Assert.assertNotNull("Points should not be null", polyline.points)
|
||||
Assert.assertEquals(LatLng(0.0, 0.0), polyline.points[0])
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.annotations;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class PolylineTest {
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
PolylineOptions polylineOptions = new PolylineOptions();
|
||||
assertNotNull("polylineOptions should not be null", polylineOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPolyline() {
|
||||
Polyline polyline = new PolylineOptions().getPolyline();
|
||||
assertNotNull("polyline should not be null", polyline);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlpha() {
|
||||
Polyline polyline = new PolylineOptions().alpha(0.2f).getPolyline();
|
||||
assertEquals(0.2f, polyline.getAlpha(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWidth() {
|
||||
Polyline polyline = new PolylineOptions().width(1).getPolyline();
|
||||
assertEquals(1.0f, polyline.getWidth(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColor() {
|
||||
Polyline polyline = new PolylineOptions().color(1).getPolyline();
|
||||
assertEquals(1, polyline.getColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddLatLng() {
|
||||
Polyline polyline = new PolylineOptions().add(new LatLng(0, 0)).getPolyline();
|
||||
assertNotNull("Points should not be null", polyline.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polyline.getPoints().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAllLatLng() {
|
||||
List<LatLng> coordinates = new ArrayList<>();
|
||||
coordinates.add(new LatLng(0, 0));
|
||||
Polyline polyline = new PolylineOptions().addAll(coordinates).getPolyline();
|
||||
assertNotNull(polyline.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polyline.getPoints().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
PolylineOptions polylineOptions = new PolylineOptions();
|
||||
polylineOptions.width(1.0f);
|
||||
polylineOptions.color(2);
|
||||
polylineOptions.add(new LatLng(0, 0));
|
||||
|
||||
Polyline polyline = polylineOptions.getPolyline();
|
||||
assertEquals(1.0f, polyline.getWidth(), 0);
|
||||
assertEquals(2, polyline.getColor());
|
||||
assertNotNull("Points should not be null", polyline.getPoints());
|
||||
assertEquals(new LatLng(0, 0), polyline.getPoints().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mapbox.mapboxsdk.annotations
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class PolylineTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val polylineOptions = PolylineOptions()
|
||||
Assert.assertNotNull("polylineOptions should not be null", polylineOptions)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPolyline() {
|
||||
val polyline = PolylineOptions().polyline
|
||||
Assert.assertNotNull("polyline should not be null", polyline)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAlpha() {
|
||||
val polyline = PolylineOptions().alpha(0.2f).polyline
|
||||
Assert.assertEquals(0.2f, polyline.alpha, 0.0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWidth() {
|
||||
val polyline = PolylineOptions().width(1f).polyline
|
||||
Assert.assertEquals(1.0f, polyline.width, 0f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testColor() {
|
||||
val polyline = PolylineOptions().color(1).polyline
|
||||
Assert.assertEquals(1, polyline.color.toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddLatLng() {
|
||||
val polyline = PolylineOptions().add(LatLng(0.0, 0.0)).polyline
|
||||
Assert.assertNotNull("Points should not be null", polyline.points)
|
||||
Assert.assertEquals(LatLng(0.0, 0.0), polyline.points[0])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddAllLatLng() {
|
||||
val coordinates: MutableList<LatLng> = ArrayList()
|
||||
coordinates.add(LatLng(0.0, 0.0))
|
||||
val polyline = PolylineOptions().addAll(coordinates).polyline
|
||||
Assert.assertNotNull(polyline.points)
|
||||
Assert.assertEquals(LatLng(0.0, 0.0), polyline.points[0])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBuilder() {
|
||||
val polylineOptions = PolylineOptions()
|
||||
polylineOptions.width(1.0f)
|
||||
polylineOptions.color(2)
|
||||
polylineOptions.add(LatLng(0.0, 0.0))
|
||||
val polyline = polylineOptions.polyline
|
||||
Assert.assertEquals(1.0f, polyline.width, 0f)
|
||||
Assert.assertEquals(2, polyline.color.toLong())
|
||||
Assert.assertNotNull("Points should not be null", polyline.points)
|
||||
Assert.assertEquals(LatLng(0.0, 0.0), polyline.points[0])
|
||||
}
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.attribution;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AttributionParseTest {
|
||||
|
||||
private static final String STREETS_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">© Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">© OpenStreetMap</a> \n";
|
||||
private static final String SATELLITE_ATTRIBUTION = "<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">© Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">© OpenStreetMap</a> <a href=\"https://www.digitalglobe.com/\" target=\"_blank\">© DigitalGlobe</a>\n";
|
||||
|
||||
@Test
|
||||
public void testParseAttributionStringSatellite() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(SATELLITE_ATTRIBUTION)
|
||||
.build();
|
||||
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 3, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
|
||||
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAttributionStringStreets() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.build();
|
||||
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 2, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAttributionWithoutMapbox() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 1, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAttributionArrayString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(new String[] {STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION})
|
||||
.build();
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 3, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
|
||||
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHideImproveThisMapAttributionArrayString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(SATELLITE_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.build();
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 3, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "© Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "© OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
|
||||
assertEquals("Title digital globe should match", "© DigitalGlobe", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseHideCopyrightAttributionArrayString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.build();
|
||||
Set<Attribution> attributionList = attributionParser.getAttributions();
|
||||
assertEquals("Size of list should match", 3, attributionList.size());
|
||||
|
||||
int counter = 0;
|
||||
for (Attribution attribution : attributionList) {
|
||||
switch (counter) {
|
||||
case 0:
|
||||
assertEquals("URL mapbox should match", "https://www.mapbox.com/about/maps/", attribution.getUrl());
|
||||
assertEquals("Title mapbox should match", "Mapbox", attribution.getTitle());
|
||||
break;
|
||||
case 1:
|
||||
assertEquals("URL openstreetmap should match", "http://www.openstreetmap.org/about/", attribution.getUrl());
|
||||
assertEquals("Title openstreetmap should match", "OpenStreetMap", attribution.getTitle());
|
||||
break;
|
||||
case 2:
|
||||
assertEquals("URL digital globe should match", "https://www.digitalglobe.com/", attribution.getUrl());
|
||||
assertEquals("Title digital globe should match", "DigitalGlobe", attribution.getTitle());
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputWithoutCopyRightString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.withImproveMap(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOutputWithCopyRightString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / © OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputWithoutCopyRightWithoutMapboxString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.withImproveMap(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputWithCopyRightWithoutMapboxString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputSatelliteString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap / DigitalGlobe",
|
||||
attributionParser.createAttributionString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortOpenStreetMapString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OSM / DigitalGlobe",
|
||||
attributionParser.createAttributionString(true)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShortOpenStreetMapWithoutCopyrightString() throws Exception {
|
||||
AttributionParser attributionParser = new AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.build();
|
||||
|
||||
assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / OSM / DigitalGlobe",
|
||||
attributionParser.createAttributionString(true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,383 @@
|
||||
package com.mapbox.mapboxsdk.attribution
|
||||
|
||||
import junit.framework.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class AttributionParseTest {
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testParseAttributionStringSatellite() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(SATELLITE_ATTRIBUTION)
|
||||
.build()
|
||||
val attributionList = attributionParser.attributions
|
||||
Assert.assertEquals("Size of list should match", 3, attributionList.size)
|
||||
var counter = 0
|
||||
for (attribution in attributionList) {
|
||||
when (counter) {
|
||||
0 -> {
|
||||
Assert.assertEquals(
|
||||
"URL mapbox should match",
|
||||
"https://www.mapbox.com/about/maps/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals("Title mapbox should match", "© Mapbox", attribution.title)
|
||||
}
|
||||
1 -> {
|
||||
Assert.assertEquals(
|
||||
"URL openstreetmap should match",
|
||||
"http://www.openstreetmap.org/about/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title openstreetmap should match",
|
||||
"© OpenStreetMap",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
2 -> {
|
||||
Assert.assertEquals(
|
||||
"URL digital globe should match",
|
||||
"https://www.digitalglobe.com/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title digital globe should match",
|
||||
"© DigitalGlobe",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
}
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testParseAttributionStringStreets() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.build()
|
||||
val attributionList = attributionParser.attributions
|
||||
Assert.assertEquals("Size of list should match", 2, attributionList.size)
|
||||
var counter = 0
|
||||
for (attribution in attributionList) {
|
||||
when (counter) {
|
||||
0 -> {
|
||||
Assert.assertEquals(
|
||||
"URL mapbox should match",
|
||||
"https://www.mapbox.com/about/maps/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals("Title mapbox should match", "© Mapbox", attribution.title)
|
||||
}
|
||||
1 -> {
|
||||
Assert.assertEquals(
|
||||
"URL openstreetmap should match",
|
||||
"http://www.openstreetmap.org/about/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title openstreetmap should match",
|
||||
"© OpenStreetMap",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
}
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testParseAttributionWithoutMapbox() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withMapboxAttribution(false)
|
||||
.build()
|
||||
val attributionList = attributionParser.attributions
|
||||
Assert.assertEquals("Size of list should match", 1, attributionList.size)
|
||||
var counter = 0
|
||||
for (attribution in attributionList) {
|
||||
when (counter) {
|
||||
0 -> {
|
||||
Assert.assertEquals(
|
||||
"URL openstreetmap should match",
|
||||
"http://www.openstreetmap.org/about/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title openstreetmap should match",
|
||||
"© OpenStreetMap",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
}
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testParseAttributionArrayString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(*arrayOf(STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION))
|
||||
.build()
|
||||
val attributionList = attributionParser.attributions
|
||||
Assert.assertEquals("Size of list should match", 3, attributionList.size)
|
||||
var counter = 0
|
||||
for (attribution in attributionList) {
|
||||
when (counter) {
|
||||
0 -> {
|
||||
Assert.assertEquals(
|
||||
"URL mapbox should match",
|
||||
"https://www.mapbox.com/about/maps/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals("Title mapbox should match", "© Mapbox", attribution.title)
|
||||
}
|
||||
1 -> {
|
||||
Assert.assertEquals(
|
||||
"URL openstreetmap should match",
|
||||
"http://www.openstreetmap.org/about/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title openstreetmap should match",
|
||||
"© OpenStreetMap",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
2 -> {
|
||||
Assert.assertEquals(
|
||||
"URL digital globe should match",
|
||||
"https://www.digitalglobe.com/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title digital globe should match",
|
||||
"© DigitalGlobe",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
}
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testHideImproveThisMapAttributionArrayString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(SATELLITE_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.build()
|
||||
val attributionList = attributionParser.attributions
|
||||
Assert.assertEquals("Size of list should match", 3, attributionList.size)
|
||||
var counter = 0
|
||||
for (attribution in attributionList) {
|
||||
when (counter) {
|
||||
0 -> {
|
||||
Assert.assertEquals(
|
||||
"URL mapbox should match",
|
||||
"https://www.mapbox.com/about/maps/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals("Title mapbox should match", "© Mapbox", attribution.title)
|
||||
}
|
||||
1 -> {
|
||||
Assert.assertEquals(
|
||||
"URL openstreetmap should match",
|
||||
"http://www.openstreetmap.org/about/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title openstreetmap should match",
|
||||
"© OpenStreetMap",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
2 -> {
|
||||
Assert.assertEquals(
|
||||
"URL digital globe should match",
|
||||
"https://www.digitalglobe.com/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title digital globe should match",
|
||||
"© DigitalGlobe",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
}
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testParseHideCopyrightAttributionArrayString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, "", SATELLITE_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.build()
|
||||
val attributionList = attributionParser.attributions
|
||||
Assert.assertEquals("Size of list should match", 3, attributionList.size)
|
||||
var counter = 0
|
||||
for (attribution in attributionList) {
|
||||
when (counter) {
|
||||
0 -> {
|
||||
Assert.assertEquals(
|
||||
"URL mapbox should match",
|
||||
"https://www.mapbox.com/about/maps/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals("Title mapbox should match", "Mapbox", attribution.title)
|
||||
}
|
||||
1 -> {
|
||||
Assert.assertEquals(
|
||||
"URL openstreetmap should match",
|
||||
"http://www.openstreetmap.org/about/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title openstreetmap should match",
|
||||
"OpenStreetMap",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
2 -> {
|
||||
Assert.assertEquals(
|
||||
"URL digital globe should match",
|
||||
"https://www.digitalglobe.com/",
|
||||
attribution.url
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Title digital globe should match",
|
||||
"DigitalGlobe",
|
||||
attribution.title
|
||||
)
|
||||
}
|
||||
}
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOutputWithoutCopyRightString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.withImproveMap(false)
|
||||
.build()
|
||||
Assert.assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOutputWithCopyRightString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.build()
|
||||
Assert.assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / © OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOutputWithoutCopyRightWithoutMapboxString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withCopyrightSign(false)
|
||||
.withImproveMap(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build()
|
||||
Assert.assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOutputWithCopyRightWithoutMapboxString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION)
|
||||
.withImproveMap(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build()
|
||||
Assert.assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap",
|
||||
attributionParser.createAttributionString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOutputSatelliteString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build()
|
||||
Assert.assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OpenStreetMap / DigitalGlobe",
|
||||
attributionParser.createAttributionString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShortOpenStreetMapString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.withMapboxAttribution(false)
|
||||
.build()
|
||||
Assert.assertEquals(
|
||||
"Attribution string should match",
|
||||
"© OSM / DigitalGlobe",
|
||||
attributionParser.createAttributionString(true)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShortOpenStreetMapWithoutCopyrightString() {
|
||||
val attributionParser = AttributionParser.Options(RuntimeEnvironment.application)
|
||||
.withAttributionData(STREETS_ATTRIBUTION, SATELLITE_ATTRIBUTION, "blabla", "")
|
||||
.withImproveMap(false)
|
||||
.withCopyrightSign(false)
|
||||
.build()
|
||||
Assert.assertEquals(
|
||||
"Attribution string should match",
|
||||
"© Mapbox / OSM / DigitalGlobe",
|
||||
attributionParser.createAttributionString(true)
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val STREETS_ATTRIBUTION =
|
||||
"<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">© Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">© OpenStreetMap</a> \n"
|
||||
private const val SATELLITE_ATTRIBUTION =
|
||||
"<a href=\"https://www.mapbox.com/about/maps/\" target=\"_blank\">© Mapbox</a> <a href=\"http://www.openstreetmap.org/about/\" target=\"_blank\">© OpenStreetMap</a> <a href=\"https://www.digitalglobe.com/\" target=\"_blank\">© DigitalGlobe</a>\n"
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.camera;
|
||||
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Parcel;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CameraPositionTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertNotNull("cameraPosition should not be null", cameraPosition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultTypedArrayBuilder() {
|
||||
TypedArray typedArray = null;
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
|
||||
assertEquals("bearing should match", -1, cameraPosition.bearing, DELTA);
|
||||
assertNull("latlng should be null", cameraPosition.target);
|
||||
assertEquals("tilt should match", -1, cameraPosition.tilt, DELTA);
|
||||
assertEquals("zoom should match", -1, cameraPosition.zoom, DELTA);
|
||||
assertNull("padding should be null", cameraPosition.padding);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypedArrayBuilder() {
|
||||
float bearing = 180;
|
||||
float zoom = 12;
|
||||
float latitude = 10;
|
||||
float longitude = 11;
|
||||
float tilt = 44;
|
||||
|
||||
TypedArray typedArray = mock(TypedArray.class);
|
||||
when(typedArray.getFloat(R.styleable.maplibre_MapView_maplibre_cameraBearing, 0.0f)).thenReturn(bearing);
|
||||
when(typedArray.getFloat(R.styleable.maplibre_MapView_maplibre_cameraTargetLat, 0.0f)).thenReturn(latitude);
|
||||
when(typedArray.getFloat(R.styleable.maplibre_MapView_maplibre_cameraTargetLng, 0.0f)).thenReturn(longitude);
|
||||
when(typedArray.getFloat(R.styleable.maplibre_MapView_maplibre_cameraZoom, 0.0f)).thenReturn(zoom);
|
||||
when(typedArray.getFloat(R.styleable.maplibre_MapView_maplibre_cameraTilt, 0.0f)).thenReturn(tilt);
|
||||
doNothing().when(typedArray).recycle();
|
||||
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder(typedArray).build();
|
||||
assertEquals("bearing should match", bearing, cameraPosition.bearing, DELTA);
|
||||
assertEquals("latlng should match", new LatLng(latitude, longitude), cameraPosition.target);
|
||||
assertEquals("tilt should match", tilt, cameraPosition.tilt, DELTA);
|
||||
assertEquals("zoom should match", zoom, cameraPosition.zoom, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertEquals("toString should match", "Target: LatLng [latitude=1.0, longitude=2.0, altitude=0.0], Zoom:3.0, "
|
||||
+ "Bearing:5.0, Tilt:4.0, Padding:[0.0, 500.0, 0.0, 0.0]", cameraPosition.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
assertEquals("hashCode should match", -420915327, cameraPosition.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomUpdateBuilder() {
|
||||
float zoomLevel = 5;
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder(
|
||||
(CameraUpdateFactory.ZoomUpdate) CameraUpdateFactory.zoomTo(zoomLevel));
|
||||
assertEquals("zoom should match", zoomLevel, builder.build().zoom, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
CameraPosition cameraPosition = new CameraPosition(latLng, 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionBearing = new CameraPosition(latLng, 3, 4, 9, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionTilt = new CameraPosition(latLng, 3, 9, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionZoom = new CameraPosition(latLng, 9, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionTarget = new CameraPosition(new LatLng(), 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
CameraPosition cameraPositionPadding = new CameraPosition(new LatLng(), 3, 4, 5, new double[] {0, 501, 0, 0});
|
||||
|
||||
assertEquals("cameraPosition should match itself", cameraPosition, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match null", null, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match object", new Object(), cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for bearing", cameraPositionBearing, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for tilt", cameraPositionTilt, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for zoom", cameraPositionZoom, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for target", cameraPositionTarget, cameraPosition);
|
||||
assertNotEquals("cameraPosition should not match for padding", cameraPositionPadding, cameraPosition);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
CameraPosition cameraPosition1 = new CameraPosition(new LatLng(1, 2), 3, 4, 5, new double[] {0, 500, 0, 0});
|
||||
Parcel parcel = Parcel.obtain();
|
||||
cameraPosition1.writeToParcel(parcel, 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
CameraPosition cameraPosition2 = CameraPosition.CREATOR.createFromParcel(parcel);
|
||||
assertEquals("Parcel should match original object", cameraPosition1, cameraPosition2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelableNulls() {
|
||||
CameraPosition cameraPosition1 = new CameraPosition(null, 3, 4, 5, null);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
cameraPosition1.writeToParcel(parcel, 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
CameraPosition cameraPosition2 = CameraPosition.CREATOR.createFromParcel(parcel);
|
||||
assertEquals("Parcel should match original object", cameraPosition1, cameraPosition2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.mapbox.mapboxsdk.camera
|
||||
|
||||
import android.content.res.TypedArray
|
||||
import android.os.Parcel
|
||||
import com.mapbox.mapboxsdk.R
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory.ZoomUpdate
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory.zoomTo
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class CameraPositionTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val latLng = LatLng(1.0, 2.0)
|
||||
val cameraPosition =
|
||||
CameraPosition(latLng, 3.0, 4.0, 5.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
Assert.assertNotNull("cameraPosition should not be null", cameraPosition)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDefaultTypedArrayBuilder() {
|
||||
val typedArray: TypedArray? = null
|
||||
val cameraPosition = CameraPosition.Builder(typedArray).build()
|
||||
Assert.assertEquals("bearing should match", -1.0, cameraPosition.bearing, DELTA)
|
||||
Assert.assertNull("latlng should be null", cameraPosition.target)
|
||||
Assert.assertEquals("tilt should match", -1.0, cameraPosition.tilt, DELTA)
|
||||
Assert.assertEquals("zoom should match", -1.0, cameraPosition.zoom, DELTA)
|
||||
Assert.assertNull("padding should be null", cameraPosition.padding)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTypedArrayBuilder() {
|
||||
val bearing = 180f
|
||||
val zoom = 12f
|
||||
val latitude = 10f
|
||||
val longitude = 11f
|
||||
val tilt = 44f
|
||||
val typedArray = Mockito.mock(TypedArray::class.java)
|
||||
Mockito.`when`(
|
||||
typedArray.getFloat(
|
||||
R.styleable.maplibre_MapView_maplibre_cameraBearing,
|
||||
0.0f
|
||||
)
|
||||
).thenReturn(bearing)
|
||||
Mockito.`when`(
|
||||
typedArray.getFloat(
|
||||
R.styleable.maplibre_MapView_maplibre_cameraTargetLat,
|
||||
0.0f
|
||||
)
|
||||
).thenReturn(latitude)
|
||||
Mockito.`when`(
|
||||
typedArray.getFloat(
|
||||
R.styleable.maplibre_MapView_maplibre_cameraTargetLng,
|
||||
0.0f
|
||||
)
|
||||
).thenReturn(longitude)
|
||||
Mockito.`when`(typedArray.getFloat(R.styleable.maplibre_MapView_maplibre_cameraZoom, 0.0f))
|
||||
.thenReturn(zoom)
|
||||
Mockito.`when`(typedArray.getFloat(R.styleable.maplibre_MapView_maplibre_cameraTilt, 0.0f))
|
||||
.thenReturn(tilt)
|
||||
Mockito.doNothing().`when`(typedArray).recycle()
|
||||
val cameraPosition = CameraPosition.Builder(typedArray).build()
|
||||
Assert.assertEquals(
|
||||
"bearing should match",
|
||||
bearing.toDouble(),
|
||||
cameraPosition.bearing,
|
||||
DELTA
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"latlng should match",
|
||||
LatLng(latitude.toDouble(), longitude.toDouble()),
|
||||
cameraPosition.target
|
||||
)
|
||||
Assert.assertEquals("tilt should match", tilt.toDouble(), cameraPosition.tilt, DELTA)
|
||||
Assert.assertEquals("zoom should match", zoom.toDouble(), cameraPosition.zoom, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToString() {
|
||||
val latLng = LatLng(1.0, 2.0)
|
||||
val cameraPosition =
|
||||
CameraPosition(latLng, 3.0, 4.0, 5.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
Assert.assertEquals(
|
||||
"toString should match",
|
||||
"Target: LatLng [latitude=1.0, longitude=2.0, altitude=0.0], Zoom:3.0, " +
|
||||
"Bearing:5.0, Tilt:4.0, Padding:[0.0, 500.0, 0.0, 0.0]",
|
||||
cameraPosition.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashcode() {
|
||||
val latLng = LatLng(1.0, 2.0)
|
||||
val cameraPosition =
|
||||
CameraPosition(latLng, 3.0, 4.0, 5.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
Assert.assertEquals("hashCode should match", -420915327, cameraPosition.hashCode().toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testZoomUpdateBuilder() {
|
||||
val zoomLevel = 5f
|
||||
val builder = CameraPosition.Builder(
|
||||
zoomTo(zoomLevel.toDouble()) as ZoomUpdate
|
||||
)
|
||||
Assert.assertEquals("zoom should match", zoomLevel.toDouble(), builder.build().zoom, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquals() {
|
||||
val latLng = LatLng(1.0, 2.0)
|
||||
val cameraPosition =
|
||||
CameraPosition(latLng, 3.0, 4.0, 5.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
val cameraPositionBearing =
|
||||
CameraPosition(latLng, 3.0, 4.0, 9.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
val cameraPositionTilt =
|
||||
CameraPosition(latLng, 3.0, 9.0, 5.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
val cameraPositionZoom =
|
||||
CameraPosition(latLng, 9.0, 4.0, 5.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
val cameraPositionTarget =
|
||||
CameraPosition(LatLng(), 3.0, 4.0, 5.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
val cameraPositionPadding =
|
||||
CameraPosition(LatLng(), 3.0, 4.0, 5.0, doubleArrayOf(0.0, 501.0, 0.0, 0.0))
|
||||
Assert.assertEquals("cameraPosition should match itself", cameraPosition, cameraPosition)
|
||||
Assert.assertNotEquals("cameraPosition should not match null", null, cameraPosition)
|
||||
Assert.assertNotEquals("cameraPosition should not match object", Any(), cameraPosition)
|
||||
Assert.assertNotEquals(
|
||||
"cameraPosition should not match for bearing",
|
||||
cameraPositionBearing,
|
||||
cameraPosition
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
"cameraPosition should not match for tilt",
|
||||
cameraPositionTilt,
|
||||
cameraPosition
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
"cameraPosition should not match for zoom",
|
||||
cameraPositionZoom,
|
||||
cameraPosition
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
"cameraPosition should not match for target",
|
||||
cameraPositionTarget,
|
||||
cameraPosition
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
"cameraPosition should not match for padding",
|
||||
cameraPositionPadding,
|
||||
cameraPosition
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParcelable() {
|
||||
val cameraPosition1 =
|
||||
CameraPosition(LatLng(1.0, 2.0), 3.0, 4.0, 5.0, doubleArrayOf(0.0, 500.0, 0.0, 0.0))
|
||||
val parcel = Parcel.obtain()
|
||||
cameraPosition1.writeToParcel(parcel, 0)
|
||||
parcel.setDataPosition(0)
|
||||
val cameraPosition2 = CameraPosition.CREATOR.createFromParcel(parcel)
|
||||
Assert.assertEquals("Parcel should match original object", cameraPosition1, cameraPosition2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParcelableNulls() {
|
||||
val cameraPosition1 = CameraPosition(null, 3.0, 4.0, 5.0, null)
|
||||
val parcel = Parcel.obtain()
|
||||
cameraPosition1.writeToParcel(parcel, 0)
|
||||
parcel.setDataPosition(0)
|
||||
val cameraPosition2 = CameraPosition.CREATOR.createFromParcel(parcel)
|
||||
Assert.assertEquals("Parcel should match original object", cameraPosition1, cameraPosition2)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DELTA = 1e-15
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.constants;
|
||||
|
||||
public class AppConstant {
|
||||
|
||||
public static final int STYLE_VERSION = 9;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.mapbox.mapboxsdk.constants
|
||||
|
||||
object AppConstant {
|
||||
const val STYLE_VERSION = 9
|
||||
}
|
||||
@@ -1,815 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.GeometryConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class LatLngBoundsTest {
|
||||
|
||||
private static final double DELTA = 1e-13;
|
||||
|
||||
private LatLngBounds latLngBounds;
|
||||
private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0);
|
||||
private static final LatLng LAT_LNG_NOT_NULL_ISLAND = new LatLng(2, 2);
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLngBounds.Builder latLngBoundsBuilder = new LatLngBounds.Builder();
|
||||
latLngBoundsBuilder.include(LAT_LNG_NULL_ISLAND).include(LAT_LNG_NOT_NULL_ISLAND);
|
||||
assertNotNull("latLng should not be null", latLngBoundsBuilder.build());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidLatLngBoundsException.class)
|
||||
public void noLatLngs() {
|
||||
new LatLngBounds.Builder().build();
|
||||
}
|
||||
|
||||
@Test(expected = InvalidLatLngBoundsException.class)
|
||||
public void oneLatLngs() {
|
||||
new LatLngBounds.Builder().include(LAT_LNG_NULL_ISLAND).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void latitiudeSpan() {
|
||||
assertEquals("Span should be the same", 2, latLngBounds.getLatitudeSpan(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longitudeSpan() {
|
||||
assertEquals("Span should be the same", 2, latLngBounds.getLongitudeSpan(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void coordinateSpan() {
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(2, 2), latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateLineSpanBuilder1() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -170))
|
||||
.include(new LatLng(-10, 170))
|
||||
.build();
|
||||
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateLineSpanBuilder2() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(-10, -170))
|
||||
.include(new LatLng(10, 170))
|
||||
.build();
|
||||
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateLineSpanFrom1() {
|
||||
latLngBounds = LatLngBounds.from(10, -170, -10, -190);
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 20),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dateLineSpanFrom2() {
|
||||
latLngBounds = LatLngBounds.from(10, 170, -10, -170);
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same", new LatLngSpan(20, 340),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroLongitudeSpan() {
|
||||
latLngBounds = LatLngBounds.from(10, 10, -10, 10);
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be shortest distance", new LatLngSpan(20, 0),
|
||||
latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter1() {
|
||||
latLngBounds = LatLngBounds.from(10, -175, -10, -195);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, -185), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter2() {
|
||||
latLngBounds = LatLngBounds.from(10, 195, -10, 175);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, 185), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter3() {
|
||||
latLngBounds = LatLngBounds.from(10, -170, -10, -190);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, -180), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter4() {
|
||||
latLngBounds = LatLngBounds.from(10, 180, -10, 0);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, 90), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearDateLineCenter5() {
|
||||
latLngBounds = LatLngBounds.from(10, 180, -10, 0);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, 90), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void centerForBoundsWithSameLongitude() {
|
||||
latLngBounds = LatLngBounds.from(10, 10, -10, 10);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(0, 10), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void centerForBoundsWithSameLatitude() {
|
||||
latLngBounds = LatLngBounds.from(10, 10, 10, -10);
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(10, 0), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void center() {
|
||||
LatLng center = latLngBounds.getCenter();
|
||||
assertEquals("Center should match", new LatLng(1, 1), center);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEmptySpan() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
assertFalse("Should not be empty", latLngBounds.isEmptySpan());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includeSameLatLngs() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
assertEquals(latLngBounds.getNorthEast(), LAT_LNG_NOT_NULL_ISLAND);
|
||||
assertEquals(latLngBounds.getSouthWest(), LAT_LNG_NULL_ISLAND);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toLatLngs() {
|
||||
latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
|
||||
assertArrayEquals("LatLngs should match",
|
||||
new LatLng[] {LAT_LNG_NOT_NULL_ISLAND, LAT_LNG_NULL_ISLAND},
|
||||
latLngBounds.toLatLngs());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void include() {
|
||||
assertTrue("LatLng should be included", latLngBounds.contains(new LatLng(1, 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includes() {
|
||||
List<LatLng> points = new ArrayList<>();
|
||||
points.add(LAT_LNG_NULL_ISLAND);
|
||||
points.add(LAT_LNG_NOT_NULL_ISLAND);
|
||||
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.includes(points)
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build();
|
||||
|
||||
assertEquals("LatLngBounds should match", latLngBounds1, latLngBounds2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesOrderDoesNotMatter() {
|
||||
LatLngBounds sameLongitudeFirst = new LatLngBounds.Builder()
|
||||
.include(new LatLng(50, 10)) // southWest
|
||||
.include(new LatLng(60, 10))
|
||||
.include(new LatLng(60, 20)) // northEast
|
||||
.include(new LatLng(50, 20))
|
||||
.include(new LatLng(50, 10)) // southWest again
|
||||
.build();
|
||||
|
||||
LatLngBounds sameLatitudeFirst = new LatLngBounds.Builder()
|
||||
.include(new LatLng(50, 20))
|
||||
.include(new LatLng(50, 10)) // southWest
|
||||
.include(new LatLng(60, 10))
|
||||
.include(new LatLng(60, 20)) // northEast
|
||||
.include(new LatLng(50, 20))
|
||||
.build();
|
||||
|
||||
assertEquals(sameLatitudeFirst, sameLongitudeFirst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesOverDateline1() {
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -170))
|
||||
.include(new LatLng(-10, -175))
|
||||
.include(new LatLng(0, -190))
|
||||
.build();
|
||||
|
||||
LatLngSpan latLngSpan = latLngBounds.getSpan();
|
||||
assertEquals("LatLngSpan should be the same",
|
||||
new LatLngSpan(20, 20), latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesOverDateline2() {
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 170))
|
||||
.include(new LatLng(-10, 175))
|
||||
.include(new LatLng(0, 190))
|
||||
.build();
|
||||
|
||||
assertEquals("LatLngSpan should be the same",
|
||||
new LatLngSpan(20, 20), latLngBounds.getSpan());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includesOverDateline3() {
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -190))
|
||||
.include(new LatLng(-10, -170))
|
||||
.include(new LatLng(0, -180))
|
||||
.include(new LatLng(5, -180))
|
||||
.build();
|
||||
|
||||
assertEquals("LatLngSpan should be the same",
|
||||
new LatLngSpan(20, 20), latLngBounds.getSpan());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsNot() {
|
||||
assertFalse("LatLng should not be included",
|
||||
latLngBounds.contains(new LatLng(3, 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsBoundsInWorld() {
|
||||
assertTrue("LatLngBounds should be contained in the world",
|
||||
LatLngBounds.world().contains(latLngBounds));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void worldSpan() {
|
||||
assertEquals("LatLngBounds world span should be 180, 360",
|
||||
GeometryConstants.LATITUDE_SPAN, LatLngBounds.world().getLatitudeSpan(), DELTA);
|
||||
assertEquals("LatLngBounds world span should be 180, 360",
|
||||
GeometryConstants.LONGITUDE_SPAN, LatLngBounds.world().getLongitudeSpan(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptySpan() {
|
||||
LatLngBounds latLngBounds = LatLngBounds.from(
|
||||
GeometryConstants.MIN_LATITUDE, GeometryConstants.MAX_LONGITUDE,
|
||||
GeometryConstants.MIN_LATITUDE, GeometryConstants.MAX_LONGITUDE);
|
||||
assertTrue("LatLngBounds empty span", latLngBounds.isEmptySpan());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsBounds() {
|
||||
LatLngBounds inner = new LatLngBounds.Builder()
|
||||
.include(new LatLng(-5, -5))
|
||||
.include(new LatLng(5, 5))
|
||||
.build();
|
||||
LatLngBounds outer = new LatLngBounds.Builder()
|
||||
.include(new LatLng(-10, -10))
|
||||
.include(new LatLng(10, 10))
|
||||
.build();
|
||||
assertTrue(outer.contains(inner));
|
||||
assertFalse(inner.contains(outer));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
assertEquals(2147483647, latLngBounds.hashCode(), -1946419200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equality() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build();
|
||||
assertEquals("equality should match", this.latLngBounds, latLngBounds);
|
||||
assertEquals("not equal to a different object type",
|
||||
this.latLngBounds.equals(LAT_LNG_NOT_NULL_ISLAND), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals(latLngBounds.toString(), "N:2.0; E:2.0; S:0.0; W:0.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersect() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(1, 1))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
assertEquals("intersect should match", latLngBounds,
|
||||
latLngBounds.intersect(this.latLngBounds.getLatNorth(),
|
||||
this.latLngBounds.getLonEast(),
|
||||
this.latLngBounds.getLatSouth(),
|
||||
this.latLngBounds.getLonWest()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectNot() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 10))
|
||||
.include(new LatLng(9, 8))
|
||||
.build();
|
||||
assertNull(latLngBounds.intersect(this.latLngBounds));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectNorthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds intersectLatLngBounds =
|
||||
LatLngBounds.from(10, 10, 0, 0)
|
||||
.intersect(200, 200, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectSouthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds intersectLatLngBounds =
|
||||
LatLngBounds.from(0, 0, -10, -10)
|
||||
.intersect(0, 0, -200, -200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectSouthLessThanNorthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latNorth cannot be less than latSouth");
|
||||
LatLngBounds intersectLatLngBounds =
|
||||
LatLngBounds.from(10, 10, 0, 0)
|
||||
.intersect(0, 200, 20, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectEastLessThanWestCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("lonEast cannot be less than lonWest");
|
||||
LatLngBounds intersectLatLngBounds =
|
||||
LatLngBounds.from(10, -10, 0, 0)
|
||||
.intersect(0, 200, 20, 0);
|
||||
}
|
||||
|
||||
public void intersectEastDoesNotWrapCheck() {
|
||||
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(10, 210, 0, 0);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(90, 200, 0, 0);
|
||||
|
||||
LatLngBounds intersectLatLngBounds = LatLngBounds.from(10, 200, 0, 0);
|
||||
|
||||
assertEquals(latLngBounds1.intersect(latLngBounds2), intersectLatLngBounds);
|
||||
assertEquals(latLngBounds2.intersect(latLngBounds1), intersectLatLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intersectDoesNotWestWrapCheck() {
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(0, 0, -10, -210);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(0, 0, -90, -200);
|
||||
|
||||
LatLngBounds intersectLatLngBounds = LatLngBounds.from(0, 0, -10, -200);
|
||||
|
||||
assertEquals(latLngBounds1.intersect(latLngBounds2), intersectLatLngBounds);
|
||||
assertEquals(latLngBounds2.intersect(latLngBounds1), intersectLatLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void innerUnion() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(1, 1))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build();
|
||||
assertEquals("union should match", latLngBounds, latLngBounds.intersect(this.latLngBounds));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outerUnion() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 10))
|
||||
.include(new LatLng(9, 8))
|
||||
.build();
|
||||
assertEquals("outer union should match",
|
||||
latLngBounds.union(this.latLngBounds),
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 10))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 170))
|
||||
.include(new LatLng(0, 160))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, 190))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 160))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine2() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 170))
|
||||
.include(new LatLng(0, 160))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, 165))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 160))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine3() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 195))
|
||||
.include(new LatLng(0, 160))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, 190))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 160))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine4() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -160))
|
||||
.include(new LatLng(0, -200))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, -170))
|
||||
.include(new LatLng(-10, -175))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, -200))
|
||||
.include(new LatLng(-10, -160))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLine5() {
|
||||
LatLngBounds latLngBounds1 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 200))
|
||||
.include(new LatLng(0, 160))
|
||||
.build();
|
||||
|
||||
LatLngBounds latLngBounds2 = new LatLngBounds.Builder()
|
||||
.include(new LatLng(0, 170))
|
||||
.include(new LatLng(-10, 175))
|
||||
.build();
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1,
|
||||
new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 160))
|
||||
.include(new LatLng(-10, 200))
|
||||
.build());
|
||||
|
||||
assertEquals(union1, union2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionOverDateLineReturnLongerThanWorldLonSpan() {
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(10, 200, -10, -10);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(10, 10, -10, -200);
|
||||
|
||||
LatLngBounds union1 = latLngBounds1.union(latLngBounds2);
|
||||
LatLngBounds union2 = latLngBounds2.union(latLngBounds1);
|
||||
|
||||
assertEquals(union1, union2);
|
||||
assertEquals(union1, LatLngBounds.from(10, 200, -10, -200));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionNorthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds unionLatLngBounds =
|
||||
LatLngBounds.from(10, 10, 0, 0)
|
||||
.union(200, 200, 0, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionSouthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds unionLatLngBounds =
|
||||
LatLngBounds.from(0, 0, -10, -10)
|
||||
.union(0, 0, -200, -200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionSouthLessThanNorthCheck() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latNorth cannot be less than latSouth");
|
||||
|
||||
LatLngBounds unionLatLngBounds =
|
||||
LatLngBounds.from(10, 10, 0, 0)
|
||||
.union(0, 200, 20, 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void unionEastDoesNotWrapCheck() {
|
||||
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(10, 10, 0, 0);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(90, 200, 0, 0);
|
||||
LatLngBounds unionLatLngBounds = LatLngBounds.from(90, 200, 0, 0);
|
||||
|
||||
assertEquals(latLngBounds1.union(latLngBounds2), unionLatLngBounds);
|
||||
assertEquals(latLngBounds2.union(latLngBounds1), unionLatLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unionWestDoesNotWrapCheck() {
|
||||
LatLngBounds latLngBounds1 = LatLngBounds.from(0, 0, -10, -10);
|
||||
LatLngBounds latLngBounds2 = LatLngBounds.from(0, 0, -90, -200);
|
||||
|
||||
LatLngBounds unionLatLngBounds = LatLngBounds.from(0, 0, -90, -200);
|
||||
|
||||
assertEquals(latLngBounds1.union(latLngBounds2), unionLatLngBounds);
|
||||
assertEquals(latLngBounds2.union(latLngBounds1), unionLatLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void northWest() {
|
||||
double minLat = 5;
|
||||
double minLon = 6;
|
||||
double maxLat = 20;
|
||||
double maxLon = 21;
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(minLat, minLon))
|
||||
.include(new LatLng(maxLat, maxLon))
|
||||
.build();
|
||||
|
||||
assertEquals("NorthWest should match", latLngBounds.getNorthWest(), new LatLng(maxLat, minLon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void southWest() {
|
||||
double minLat = 5;
|
||||
double minLon = 6;
|
||||
double maxLat = 20;
|
||||
double maxLon = 21;
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(minLat, minLon))
|
||||
.include(new LatLng(maxLat, maxLon))
|
||||
.build();
|
||||
|
||||
assertEquals("SouthWest should match", latLngBounds.getSouthWest(), new LatLng(minLat, minLon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void northEast() {
|
||||
double minLat = 5;
|
||||
double minLon = 6;
|
||||
double maxLat = 20;
|
||||
double maxLon = 21;
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(minLat, minLon))
|
||||
.include(new LatLng(maxLat, maxLon))
|
||||
.build();
|
||||
|
||||
assertEquals("NorthEast should match", latLngBounds.getNorthEast(), new LatLng(maxLat, maxLon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void southEast() {
|
||||
double minLat = 5;
|
||||
double minLon = 6;
|
||||
double maxLat = 20;
|
||||
double maxLon = 21;
|
||||
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(minLat, minLon))
|
||||
.include(new LatLng(maxLat, maxLon))
|
||||
.build();
|
||||
|
||||
assertEquals("SouthEast should match", latLngBounds.getSouthEast(), new LatLng(minLat, maxLon));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
||||
.include(new LatLng(10, 10))
|
||||
.include(new LatLng(9, 8))
|
||||
.build();
|
||||
Parcelable parcel = MockParcel.obtain(latLngBounds);
|
||||
assertEquals("Parcel should match original object", parcel, latLngBounds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromTileID() {
|
||||
LatLngBounds bounds = LatLngBounds.from(0, 0, 0);
|
||||
assertEquals(GeometryConstants.MIN_WRAP_LONGITUDE, bounds.getLonWest(), DELTA);
|
||||
assertEquals(GeometryConstants.MIN_MERCATOR_LATITUDE, bounds.getLatSouth(), DELTA);
|
||||
assertEquals(GeometryConstants.MAX_WRAP_LONGITUDE, bounds.getLonEast(), DELTA);
|
||||
assertEquals(GeometryConstants.MAX_MERCATOR_LATITUDE, bounds.getLatNorth(), DELTA);
|
||||
|
||||
bounds = LatLngBounds.from(10, 288, 385);
|
||||
assertEquals(-78.75, bounds.getLonWest(), DELTA);
|
||||
assertEquals(40.446947059600497, bounds.getLatSouth(), DELTA);
|
||||
assertEquals(-78.3984375, bounds.getLonEast(), DELTA);
|
||||
assertEquals(40.713955826286039, bounds.getLatNorth(), DELTA);
|
||||
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksNorthLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must not be NaN");
|
||||
LatLngBounds.from(Double.NaN, 0, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksEastLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be NaN");
|
||||
LatLngBounds.from(0, Double.NaN, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksNorthLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds.from(95, 0, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksNorthLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds.from(-95, 0, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksEastLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be infinite");
|
||||
LatLngBounds.from(0, Double.POSITIVE_INFINITY, -20, -20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksSouthLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must not be NaN");
|
||||
LatLngBounds.from(20, 20, Double.NaN, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksWesttLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be NaN");
|
||||
LatLngBounds.from(20, 20, 0, Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksSouthLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds.from(20, 20, 95, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksSouthLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
LatLngBounds.from(20, 20, -95, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksWestLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be infinite");
|
||||
LatLngBounds.from(20, 20, 0, Double.POSITIVE_INFINITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorCheckLatSouthGreaterLatNorth() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latNorth cannot be less than latSouth");
|
||||
LatLngBounds.from(0, 20, 20, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorCheckLonWestGreaterLonEast() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("lonEast cannot be less than lonWest");
|
||||
LatLngBounds.from(20, 0, 0, 20);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,858 @@
|
||||
package com.mapbox.mapboxsdk.geometry
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.GeometryConstants
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds.Companion.from
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds.Companion.world
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel
|
||||
import junit.framework.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
|
||||
class LatLngBoundsTest {
|
||||
private var latLngBounds: LatLngBounds? = null
|
||||
|
||||
@Before
|
||||
fun beforeTest() {
|
||||
latLngBounds = LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val latLngBoundsBuilder = LatLngBounds.Builder()
|
||||
latLngBoundsBuilder.include(LAT_LNG_NULL_ISLAND).include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
Assert.assertNotNull("latLng should not be null", latLngBoundsBuilder.build())
|
||||
}
|
||||
|
||||
@Test(expected = InvalidLatLngBoundsException::class)
|
||||
fun noLatLngs() {
|
||||
LatLngBounds.Builder().build()
|
||||
}
|
||||
|
||||
@Test(expected = InvalidLatLngBoundsException::class)
|
||||
fun oneLatLngs() {
|
||||
LatLngBounds.Builder().include(LAT_LNG_NULL_ISLAND).build()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun latitiudeSpan() {
|
||||
org.junit.Assert.assertEquals(
|
||||
"Span should be the same",
|
||||
2.0,
|
||||
latLngBounds!!.latitudeSpan,
|
||||
DELTA
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun longitudeSpan() {
|
||||
org.junit.Assert.assertEquals(
|
||||
"Span should be the same",
|
||||
2.0,
|
||||
latLngBounds!!.longitudeSpan,
|
||||
DELTA
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun coordinateSpan() {
|
||||
val latLngSpan = latLngBounds!!.span
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be the same",
|
||||
LatLngSpan(2.0, 2.0),
|
||||
latLngSpan
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dateLineSpanBuilder1() {
|
||||
latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, -170.0))
|
||||
.include(LatLng(-10.0, 170.0))
|
||||
.build()
|
||||
val latLngSpan = latLngBounds!!.span
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be the same",
|
||||
LatLngSpan(20.0, 340.0),
|
||||
latLngSpan
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dateLineSpanBuilder2() {
|
||||
latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(-10.0, -170.0))
|
||||
.include(LatLng(10.0, 170.0))
|
||||
.build()
|
||||
val latLngSpan = latLngBounds!!.span
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be the same",
|
||||
LatLngSpan(20.0, 340.0),
|
||||
latLngSpan
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dateLineSpanFrom1() {
|
||||
latLngBounds = from(10.0, -170.0, -10.0, -190.0)
|
||||
val latLngSpan = latLngBounds!!.span
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be the same",
|
||||
LatLngSpan(20.0, 20.0),
|
||||
latLngSpan
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dateLineSpanFrom2() {
|
||||
latLngBounds = from(10.0, 170.0, -10.0, -170.0)
|
||||
val latLngSpan = latLngBounds!!.span
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be the same",
|
||||
LatLngSpan(20.0, 340.0),
|
||||
latLngSpan
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun zeroLongitudeSpan() {
|
||||
latLngBounds = from(10.0, 10.0, -10.0, 10.0)
|
||||
val latLngSpan = latLngBounds!!.span
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be shortest distance",
|
||||
LatLngSpan(20.0, 0.0),
|
||||
latLngSpan
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nearDateLineCenter1() {
|
||||
latLngBounds = from(10.0, -175.0, -10.0, -195.0)
|
||||
val center = latLngBounds!!.center
|
||||
org.junit.Assert.assertEquals("Center should match", LatLng(0.0, -185.0), center)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nearDateLineCenter2() {
|
||||
latLngBounds = from(10.0, 195.0, -10.0, 175.0)
|
||||
val center = latLngBounds!!.center
|
||||
org.junit.Assert.assertEquals("Center should match", LatLng(0.0, 185.0), center)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nearDateLineCenter3() {
|
||||
latLngBounds = from(10.0, -170.0, -10.0, -190.0)
|
||||
val center = latLngBounds!!.center
|
||||
org.junit.Assert.assertEquals("Center should match", LatLng(0.0, -180.0), center)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nearDateLineCenter4() {
|
||||
latLngBounds = from(10.0, 180.0, -10.0, 0.0)
|
||||
val center = latLngBounds!!.center
|
||||
org.junit.Assert.assertEquals("Center should match", LatLng(0.0, 90.0), center)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nearDateLineCenter5() {
|
||||
latLngBounds = from(10.0, 180.0, -10.0, 0.0)
|
||||
val center = latLngBounds!!.center
|
||||
org.junit.Assert.assertEquals("Center should match", LatLng(0.0, 90.0), center)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun centerForBoundsWithSameLongitude() {
|
||||
latLngBounds = from(10.0, 10.0, -10.0, 10.0)
|
||||
val center = latLngBounds!!.center
|
||||
org.junit.Assert.assertEquals("Center should match", LatLng(0.0, 10.0), center)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun centerForBoundsWithSameLatitude() {
|
||||
latLngBounds = from(10.0, 10.0, 10.0, -10.0)
|
||||
val center = latLngBounds!!.center
|
||||
org.junit.Assert.assertEquals("Center should match", LatLng(10.0, 0.0), center)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun center() {
|
||||
val center = latLngBounds!!.center
|
||||
org.junit.Assert.assertEquals("Center should match", LatLng(1.0, 1.0), center)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun notEmptySpan() {
|
||||
latLngBounds = LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build()
|
||||
org.junit.Assert.assertFalse("Should not be empty", latLngBounds!!.isEmptySpan)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun includeSameLatLngs() {
|
||||
latLngBounds = LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(latLngBounds!!.northEast, LAT_LNG_NOT_NULL_ISLAND)
|
||||
org.junit.Assert.assertEquals(latLngBounds!!.southWest, LAT_LNG_NULL_ISLAND)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun toLatLngs() {
|
||||
latLngBounds = LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build()
|
||||
org.junit.Assert.assertArrayEquals(
|
||||
"LatLngs should match",
|
||||
arrayOf(LAT_LNG_NOT_NULL_ISLAND, LAT_LNG_NULL_ISLAND),
|
||||
latLngBounds!!.toLatLngs()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun include() {
|
||||
org.junit.Assert.assertTrue(
|
||||
"LatLng should be included",
|
||||
latLngBounds!!.contains(LatLng(1.0, 1.0))
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun includes() {
|
||||
val points: MutableList<LatLng> = ArrayList()
|
||||
points.add(LAT_LNG_NULL_ISLAND)
|
||||
points.add(LAT_LNG_NOT_NULL_ISLAND)
|
||||
val latLngBounds1 = LatLngBounds.Builder()
|
||||
.includes(points)
|
||||
.build()
|
||||
val latLngBounds2 = LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build()
|
||||
org.junit.Assert.assertEquals("LatLngBounds should match", latLngBounds1, latLngBounds2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun includesOrderDoesNotMatter() {
|
||||
val sameLongitudeFirst = LatLngBounds.Builder()
|
||||
.include(LatLng(50.0, 10.0)) // southWest
|
||||
.include(LatLng(60.0, 10.0))
|
||||
.include(LatLng(60.0, 20.0)) // northEast
|
||||
.include(LatLng(50.0, 20.0))
|
||||
.include(LatLng(50.0, 10.0)) // southWest again
|
||||
.build()
|
||||
val sameLatitudeFirst = LatLngBounds.Builder()
|
||||
.include(LatLng(50.0, 20.0))
|
||||
.include(LatLng(50.0, 10.0)) // southWest
|
||||
.include(LatLng(60.0, 10.0))
|
||||
.include(LatLng(60.0, 20.0)) // northEast
|
||||
.include(LatLng(50.0, 20.0))
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(sameLatitudeFirst, sameLongitudeFirst)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun includesOverDateline1() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, -170.0))
|
||||
.include(LatLng(-10.0, -175.0))
|
||||
.include(LatLng(0.0, -190.0))
|
||||
.build()
|
||||
val latLngSpan = latLngBounds.span
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be the same",
|
||||
LatLngSpan(20.0, 20.0),
|
||||
latLngSpan
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun includesOverDateline2() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 170.0))
|
||||
.include(LatLng(-10.0, 175.0))
|
||||
.include(LatLng(0.0, 190.0))
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be the same",
|
||||
LatLngSpan(20.0, 20.0),
|
||||
latLngBounds.span
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun includesOverDateline3() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, -190.0))
|
||||
.include(LatLng(-10.0, -170.0))
|
||||
.include(LatLng(0.0, -180.0))
|
||||
.include(LatLng(5.0, -180.0))
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngSpan should be the same",
|
||||
LatLngSpan(20.0, 20.0),
|
||||
latLngBounds.span
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun containsNot() {
|
||||
org.junit.Assert.assertFalse(
|
||||
"LatLng should not be included",
|
||||
latLngBounds!!.contains(LatLng(3.0, 1.0))
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun containsBoundsInWorld() {
|
||||
org.junit.Assert.assertTrue(
|
||||
"LatLngBounds should be contained in the world",
|
||||
world().contains(latLngBounds!!)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun worldSpan() {
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngBounds world span should be 180, 360",
|
||||
GeometryConstants.LATITUDE_SPAN,
|
||||
world().latitudeSpan,
|
||||
DELTA
|
||||
)
|
||||
org.junit.Assert.assertEquals(
|
||||
"LatLngBounds world span should be 180, 360",
|
||||
GeometryConstants.LONGITUDE_SPAN,
|
||||
world().longitudeSpan,
|
||||
DELTA
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun emptySpan() {
|
||||
val latLngBounds = from(
|
||||
GeometryConstants.MIN_LATITUDE,
|
||||
GeometryConstants.MAX_LONGITUDE,
|
||||
GeometryConstants.MIN_LATITUDE,
|
||||
GeometryConstants.MAX_LONGITUDE
|
||||
)
|
||||
org.junit.Assert.assertTrue("LatLngBounds empty span", latLngBounds.isEmptySpan)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun containsBounds() {
|
||||
val inner = LatLngBounds.Builder()
|
||||
.include(LatLng(-5.0, -5.0))
|
||||
.include(LatLng(5.0, 5.0))
|
||||
.build()
|
||||
val outer = LatLngBounds.Builder()
|
||||
.include(LatLng(-10.0, -10.0))
|
||||
.include(LatLng(10.0, 10.0))
|
||||
.build()
|
||||
org.junit.Assert.assertTrue(outer.contains(inner))
|
||||
org.junit.Assert.assertFalse(inner.contains(outer))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashCode() {
|
||||
org.junit.Assert.assertEquals(2147483647f, latLngBounds.hashCode().toFloat(), -1946419200f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun equality() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.include(LAT_LNG_NOT_NULL_ISLAND)
|
||||
.build()
|
||||
org.junit.Assert.assertEquals("equality should match", this.latLngBounds, latLngBounds)
|
||||
org.junit.Assert.assertEquals(
|
||||
"not equal to a different object type",
|
||||
this.latLngBounds!!.equals(LAT_LNG_NOT_NULL_ISLAND),
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToString() {
|
||||
org.junit.Assert.assertEquals(latLngBounds.toString(), "N:2.0; E:2.0; S:0.0; W:0.0")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun intersect() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(1.0, 1.0))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"intersect should match",
|
||||
latLngBounds,
|
||||
latLngBounds.intersect(
|
||||
this.latLngBounds!!.getLatNorth(),
|
||||
this.latLngBounds!!.getLonEast(),
|
||||
this.latLngBounds!!.getLatSouth(),
|
||||
this.latLngBounds!!.getLonWest()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun intersectNot() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 10.0))
|
||||
.include(LatLng(9.0, 8.0))
|
||||
.build()
|
||||
org.junit.Assert.assertNull(latLngBounds.intersect(this.latLngBounds!!))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun intersectNorthCheck() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
val intersectLatLngBounds = from(10.0, 10.0, 0.0, 0.0)
|
||||
.intersect(200.0, 200.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun intersectSouthCheck() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
val intersectLatLngBounds = from(0.0, 0.0, -10.0, -10.0)
|
||||
.intersect(0.0, 0.0, -200.0, -200.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun intersectSouthLessThanNorthCheck() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latNorth cannot be less than latSouth")
|
||||
val intersectLatLngBounds = from(10.0, 10.0, 0.0, 0.0)
|
||||
.intersect(0.0, 200.0, 20.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun intersectEastLessThanWestCheck() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("lonEast cannot be less than lonWest")
|
||||
val intersectLatLngBounds = from(10.0, -10.0, 0.0, 0.0)
|
||||
.intersect(0.0, 200.0, 20.0, 0.0)
|
||||
}
|
||||
|
||||
fun intersectEastDoesNotWrapCheck() {
|
||||
val latLngBounds1 = from(10.0, 210.0, 0.0, 0.0)
|
||||
val latLngBounds2 = from(90.0, 200.0, 0.0, 0.0)
|
||||
val intersectLatLngBounds = from(10.0, 200.0, 0.0, 0.0)
|
||||
org.junit.Assert.assertEquals(latLngBounds1.intersect(latLngBounds2), intersectLatLngBounds)
|
||||
org.junit.Assert.assertEquals(latLngBounds2.intersect(latLngBounds1), intersectLatLngBounds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun intersectDoesNotWestWrapCheck() {
|
||||
val latLngBounds1 = from(0.0, 0.0, -10.0, -210.0)
|
||||
val latLngBounds2 = from(0.0, 0.0, -90.0, -200.0)
|
||||
val intersectLatLngBounds = from(0.0, 0.0, -10.0, -200.0)
|
||||
org.junit.Assert.assertEquals(latLngBounds1.intersect(latLngBounds2), intersectLatLngBounds)
|
||||
org.junit.Assert.assertEquals(latLngBounds2.intersect(latLngBounds1), intersectLatLngBounds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun innerUnion() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(1.0, 1.0))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"union should match",
|
||||
latLngBounds,
|
||||
latLngBounds.intersect(
|
||||
this.latLngBounds!!
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun outerUnion() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 10.0))
|
||||
.include(LatLng(9.0, 8.0))
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"outer union should match",
|
||||
latLngBounds.union(this.latLngBounds!!),
|
||||
LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 10.0))
|
||||
.include(LAT_LNG_NULL_ISLAND)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionOverDateLine() {
|
||||
val latLngBounds1 = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 170.0))
|
||||
.include(LatLng(0.0, 160.0))
|
||||
.build()
|
||||
val latLngBounds2 = LatLngBounds.Builder()
|
||||
.include(LatLng(0.0, 190.0))
|
||||
.include(LatLng(-10.0, 200.0))
|
||||
.build()
|
||||
val union1 = latLngBounds1.union(latLngBounds2)
|
||||
val union2 = latLngBounds2.union(latLngBounds1)
|
||||
org.junit.Assert.assertEquals(
|
||||
union1,
|
||||
LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 160.0))
|
||||
.include(LatLng(-10.0, 200.0))
|
||||
.build()
|
||||
)
|
||||
org.junit.Assert.assertEquals(union1, union2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionOverDateLine2() {
|
||||
val latLngBounds1 = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 170.0))
|
||||
.include(LatLng(0.0, 160.0))
|
||||
.build()
|
||||
val latLngBounds2 = LatLngBounds.Builder()
|
||||
.include(LatLng(0.0, 165.0))
|
||||
.include(LatLng(-10.0, 200.0))
|
||||
.build()
|
||||
val union1 = latLngBounds1.union(latLngBounds2)
|
||||
val union2 = latLngBounds2.union(latLngBounds1)
|
||||
org.junit.Assert.assertEquals(
|
||||
union1,
|
||||
LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 160.0))
|
||||
.include(LatLng(-10.0, 200.0))
|
||||
.build()
|
||||
)
|
||||
org.junit.Assert.assertEquals(union1, union2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionOverDateLine3() {
|
||||
val latLngBounds1 = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 195.0))
|
||||
.include(LatLng(0.0, 160.0))
|
||||
.build()
|
||||
val latLngBounds2 = LatLngBounds.Builder()
|
||||
.include(LatLng(0.0, 190.0))
|
||||
.include(LatLng(-10.0, 200.0))
|
||||
.build()
|
||||
val union1 = latLngBounds1.union(latLngBounds2)
|
||||
val union2 = latLngBounds2.union(latLngBounds1)
|
||||
org.junit.Assert.assertEquals(
|
||||
union1,
|
||||
LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 160.0))
|
||||
.include(LatLng(-10.0, 200.0))
|
||||
.build()
|
||||
)
|
||||
org.junit.Assert.assertEquals(union1, union2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionOverDateLine4() {
|
||||
val latLngBounds1 = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, -160.0))
|
||||
.include(LatLng(0.0, -200.0))
|
||||
.build()
|
||||
val latLngBounds2 = LatLngBounds.Builder()
|
||||
.include(LatLng(0.0, -170.0))
|
||||
.include(LatLng(-10.0, -175.0))
|
||||
.build()
|
||||
val union1 = latLngBounds1.union(latLngBounds2)
|
||||
val union2 = latLngBounds2.union(latLngBounds1)
|
||||
org.junit.Assert.assertEquals(
|
||||
union1,
|
||||
LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, -200.0))
|
||||
.include(LatLng(-10.0, -160.0))
|
||||
.build()
|
||||
)
|
||||
org.junit.Assert.assertEquals(union1, union2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionOverDateLine5() {
|
||||
val latLngBounds1 = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 200.0))
|
||||
.include(LatLng(0.0, 160.0))
|
||||
.build()
|
||||
val latLngBounds2 = LatLngBounds.Builder()
|
||||
.include(LatLng(0.0, 170.0))
|
||||
.include(LatLng(-10.0, 175.0))
|
||||
.build()
|
||||
val union1 = latLngBounds1.union(latLngBounds2)
|
||||
val union2 = latLngBounds2.union(latLngBounds1)
|
||||
org.junit.Assert.assertEquals(
|
||||
union1,
|
||||
LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 160.0))
|
||||
.include(LatLng(-10.0, 200.0))
|
||||
.build()
|
||||
)
|
||||
org.junit.Assert.assertEquals(union1, union2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionOverDateLineReturnLongerThanWorldLonSpan() {
|
||||
val latLngBounds1 = from(10.0, 200.0, -10.0, -10.0)
|
||||
val latLngBounds2 = from(10.0, 10.0, -10.0, -200.0)
|
||||
val union1 = latLngBounds1.union(latLngBounds2)
|
||||
val union2 = latLngBounds2.union(latLngBounds1)
|
||||
org.junit.Assert.assertEquals(union1, union2)
|
||||
org.junit.Assert.assertEquals(union1, from(10.0, 200.0, -10.0, -200.0))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionNorthCheck() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
val unionLatLngBounds = from(10.0, 10.0, 0.0, 0.0)
|
||||
.union(200.0, 200.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionSouthCheck() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
val unionLatLngBounds = from(0.0, 0.0, -10.0, -10.0)
|
||||
.union(0.0, 0.0, -200.0, -200.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionSouthLessThanNorthCheck() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latNorth cannot be less than latSouth")
|
||||
val unionLatLngBounds = from(10.0, 10.0, 0.0, 0.0)
|
||||
.union(0.0, 200.0, 20.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionEastDoesNotWrapCheck() {
|
||||
val latLngBounds1 = from(10.0, 10.0, 0.0, 0.0)
|
||||
val latLngBounds2 = from(90.0, 200.0, 0.0, 0.0)
|
||||
val unionLatLngBounds = from(90.0, 200.0, 0.0, 0.0)
|
||||
org.junit.Assert.assertEquals(latLngBounds1.union(latLngBounds2), unionLatLngBounds)
|
||||
org.junit.Assert.assertEquals(latLngBounds2.union(latLngBounds1), unionLatLngBounds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun unionWestDoesNotWrapCheck() {
|
||||
val latLngBounds1 = from(0.0, 0.0, -10.0, -10.0)
|
||||
val latLngBounds2 = from(0.0, 0.0, -90.0, -200.0)
|
||||
val unionLatLngBounds = from(0.0, 0.0, -90.0, -200.0)
|
||||
org.junit.Assert.assertEquals(latLngBounds1.union(latLngBounds2), unionLatLngBounds)
|
||||
org.junit.Assert.assertEquals(latLngBounds2.union(latLngBounds1), unionLatLngBounds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun northWest() {
|
||||
val minLat = 5.0
|
||||
val minLon = 6.0
|
||||
val maxLat = 20.0
|
||||
val maxLon = 21.0
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(minLat, minLon))
|
||||
.include(LatLng(maxLat, maxLon))
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"NorthWest should match",
|
||||
latLngBounds.northWest,
|
||||
LatLng(maxLat, minLon)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun southWest() {
|
||||
val minLat = 5.0
|
||||
val minLon = 6.0
|
||||
val maxLat = 20.0
|
||||
val maxLon = 21.0
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(minLat, minLon))
|
||||
.include(LatLng(maxLat, maxLon))
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"SouthWest should match",
|
||||
latLngBounds.southWest,
|
||||
LatLng(minLat, minLon)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun northEast() {
|
||||
val minLat = 5.0
|
||||
val minLon = 6.0
|
||||
val maxLat = 20.0
|
||||
val maxLon = 21.0
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(minLat, minLon))
|
||||
.include(LatLng(maxLat, maxLon))
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"NorthEast should match",
|
||||
latLngBounds.northEast,
|
||||
LatLng(maxLat, maxLon)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun southEast() {
|
||||
val minLat = 5.0
|
||||
val minLon = 6.0
|
||||
val maxLat = 20.0
|
||||
val maxLon = 21.0
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(minLat, minLon))
|
||||
.include(LatLng(maxLat, maxLon))
|
||||
.build()
|
||||
org.junit.Assert.assertEquals(
|
||||
"SouthEast should match",
|
||||
latLngBounds.southEast,
|
||||
LatLng(minLat, maxLon)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParcelable() {
|
||||
val latLngBounds = LatLngBounds.Builder()
|
||||
.include(LatLng(10.0, 10.0))
|
||||
.include(LatLng(9.0, 8.0))
|
||||
.build()
|
||||
val parcel = MockParcel.obtain(latLngBounds)
|
||||
org.junit.Assert.assertEquals("Parcel should match original object", parcel, latLngBounds)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromTileID() {
|
||||
var bounds = from(0, 0, 0)
|
||||
org.junit.Assert.assertEquals(
|
||||
GeometryConstants.MIN_WRAP_LONGITUDE,
|
||||
bounds.getLonWest(),
|
||||
DELTA
|
||||
)
|
||||
org.junit.Assert.assertEquals(
|
||||
GeometryConstants.MIN_MERCATOR_LATITUDE,
|
||||
bounds.getLatSouth(),
|
||||
DELTA
|
||||
)
|
||||
org.junit.Assert.assertEquals(
|
||||
GeometryConstants.MAX_WRAP_LONGITUDE,
|
||||
bounds.getLonEast(),
|
||||
DELTA
|
||||
)
|
||||
org.junit.Assert.assertEquals(
|
||||
GeometryConstants.MAX_MERCATOR_LATITUDE,
|
||||
bounds.getLatNorth(),
|
||||
DELTA
|
||||
)
|
||||
bounds = from(10, 288, 385)
|
||||
org.junit.Assert.assertEquals(-78.75, bounds.getLonWest(), DELTA)
|
||||
org.junit.Assert.assertEquals(40.446947059600497, bounds.getLatSouth(), DELTA)
|
||||
org.junit.Assert.assertEquals(-78.3984375, bounds.getLonEast(), DELTA)
|
||||
org.junit.Assert.assertEquals(40.713955826286039, bounds.getLatNorth(), DELTA)
|
||||
}
|
||||
|
||||
@Rule @JvmField
|
||||
val exception = ExpectedException.none()
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksNorthLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must not be NaN")
|
||||
from(Double.NaN, 0.0, -20.0, -20.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksEastLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("longitude must not be NaN")
|
||||
from(0.0, Double.NaN, -20.0, -20.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksNorthLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
from(95.0, 0.0, -20.0, -20.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksNorthLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
from(-95.0, 0.0, -20.0, -20.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksEastLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("longitude must not be infinite")
|
||||
from(0.0, Double.POSITIVE_INFINITY, -20.0, -20.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksSouthLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must not be NaN")
|
||||
from(20.0, 20.0, Double.NaN, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksWesttLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("longitude must not be NaN")
|
||||
from(20.0, 20.0, 0.0, Double.NaN)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksSouthLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
from(20.0, 20.0, 95.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksSouthLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
from(20.0, 20.0, -95.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksWestLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("longitude must not be infinite")
|
||||
from(20.0, 20.0, 0.0, Double.POSITIVE_INFINITY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorCheckLatSouthGreaterLatNorth() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latNorth cannot be less than latSouth")
|
||||
from(0.0, 20.0, 20.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorCheckLonWestGreaterLonEast() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("lonEast cannot be less than lonWest")
|
||||
from(20.0, 0.0, 0.0, 20.0)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DELTA = 1e-13
|
||||
private val LAT_LNG_NULL_ISLAND = LatLng(0.0, 0.0)
|
||||
private val LAT_LNG_NOT_NULL_ISLAND = LatLng(2.0, 2.0)
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class LatLngSpanTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0);
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
assertNotNull("latLngSpan should not be null", latLngSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
assertEquals("latLngSpan is not equal to a LatLng", latLngSpan.equals(LAT_LNG_NULL_ISLAND), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(latitude, 0.0);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, longitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeMethod() {
|
||||
double latitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
latLngSpan.setLatitudeSpan(latitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLatitudeSpan(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeMethod() {
|
||||
double longitude = 1.23;
|
||||
LatLngSpan latLngSpan = new LatLngSpan(0.0, 0.0);
|
||||
latLngSpan.setLongitudeSpan(longitude);
|
||||
assertEquals("latitude in constructor", latLngSpan.getLongitudeSpan(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
LatLngSpan object = new LatLngSpan(1, 2);
|
||||
Parcelable parcel = MockParcel.obtain(object);
|
||||
assertEquals("parcel should match initial object", object, parcel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mapbox.mapboxsdk.geometry
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class LatLngSpanTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val latLngSpan = LatLngSpan(0.0, 0.0)
|
||||
Assert.assertNotNull("latLngSpan should not be null", latLngSpan)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquality() {
|
||||
val latLngSpan = LatLngSpan(0.0, 0.0)
|
||||
Assert.assertEquals(
|
||||
"latLngSpan is not equal to a LatLng",
|
||||
latLngSpan.equals(
|
||||
LAT_LNG_NULL_ISLAND
|
||||
),
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatitudeConstructor() {
|
||||
val latitude = 1.23
|
||||
val latLngSpan = LatLngSpan(latitude, 0.0)
|
||||
Assert.assertEquals("latitude in constructor", latLngSpan.latitudeSpan, latitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongitudeConstructor() {
|
||||
val longitude = 1.23
|
||||
val latLngSpan = LatLngSpan(0.0, longitude)
|
||||
Assert.assertEquals("latitude in constructor", latLngSpan.longitudeSpan, longitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatitudeMethod() {
|
||||
val latitude = 1.23
|
||||
val latLngSpan = LatLngSpan(0.0, 0.0)
|
||||
latLngSpan.latitudeSpan = latitude
|
||||
Assert.assertEquals("latitude in constructor", latLngSpan.latitudeSpan, latitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongitudeMethod() {
|
||||
val longitude = 1.23
|
||||
val latLngSpan = LatLngSpan(0.0, 0.0)
|
||||
latLngSpan.longitudeSpan = longitude
|
||||
Assert.assertEquals("latitude in constructor", latLngSpan.longitudeSpan, longitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParcelable() {
|
||||
val `object` = LatLngSpan(1.0, 2.0)
|
||||
val parcel = MockParcel.obtain(`object`)
|
||||
Assert.assertEquals("parcel should match initial object", `object`, parcel)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DELTA = 1e-15
|
||||
private val LAT_LNG_NULL_ISLAND = LatLng(0.0, 0.0)
|
||||
}
|
||||
}
|
||||
@@ -1,286 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.location.Location;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class LatLngTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
LatLng latLng = new LatLng(0.0, 0.0);
|
||||
assertNotNull("latLng should not be null", latLng);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeEmptyConstructor() {
|
||||
LatLng latLng = new LatLng();
|
||||
assertEquals("latitude default value", latLng.getLatitude(), 0, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeEmptyConstructor() {
|
||||
LatLng latLng = new LatLng();
|
||||
assertEquals("longitude default value", latLng.getLongitude(), 0, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltitudeEmptyConstructor() {
|
||||
LatLng latLng1 = new LatLng();
|
||||
assertEquals("altitude default value", latLng1.getAltitude(), 0.0, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeConstructor() {
|
||||
double latitude = 1.2;
|
||||
LatLng latLng = new LatLng(latitude, 3.4);
|
||||
assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeConstructor() {
|
||||
double longitude = 3.4;
|
||||
LatLng latLng = new LatLng(1.2, longitude);
|
||||
assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltitudeConstructor() {
|
||||
LatLng latLng1 = new LatLng(1.2, 3.4);
|
||||
assertEquals("altitude default value", latLng1.getAltitude(), 0.0, DELTA);
|
||||
|
||||
double altitude = 5.6;
|
||||
LatLng latLng2 = new LatLng(1.2, 3.4, altitude);
|
||||
assertEquals("altitude default value", latLng2.getAltitude(), altitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSetter() {
|
||||
LatLng latLng = new LatLng(1.2, 3.4);
|
||||
latLng.setLatitude(3);
|
||||
assertEquals("latitude should match", 3, latLng.getLatitude(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeSetter() {
|
||||
LatLng latLng = new LatLng(1.2, 3.4);
|
||||
latLng.setLongitude(3);
|
||||
assertEquals("longitude should match", 3, latLng.getLongitude(), DELTA);
|
||||
}
|
||||
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must not be NaN");
|
||||
new LatLng(Double.NaN, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be NaN");
|
||||
new LatLng(0, Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
new LatLng(95, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
new LatLng(-95, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorChecksLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be infinite");
|
||||
new LatLng(0, Double.POSITIVE_INFINITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSetterChecksNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must not be NaN");
|
||||
new LatLng().setLatitude(Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeSetterChecksNaN() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be NaN");
|
||||
new LatLng().setLongitude(Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSetterChecksGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
new LatLng().setLatitude(95);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatitudeSetterChecksLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("latitude must be between -90 and 90");
|
||||
new LatLng().setLatitude(-95);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongitudeSetterChecksInfinity() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
exception.expectMessage("longitude must not be infinite");
|
||||
new LatLng().setLongitude(Double.NEGATIVE_INFINITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAltitudeSetter() {
|
||||
LatLng latLng = new LatLng(1.2, 3.4);
|
||||
latLng.setAltitude(3);
|
||||
assertEquals("altitude should match", 3, latLng.getAltitude(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatLngConstructor() {
|
||||
LatLng latLng1 = new LatLng(1.2, 3.4);
|
||||
LatLng latLng2 = new LatLng(latLng1);
|
||||
assertEquals("latLng should match", latLng1, latLng2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistanceTo() {
|
||||
LatLng latLng1 = new LatLng(0.0, 0.0);
|
||||
LatLng latLng2 = new LatLng(1.0, 1.0);
|
||||
assertEquals("distances should match",
|
||||
latLng1.distanceTo(latLng2),
|
||||
157298.7453847275, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistanceToSamePoint() {
|
||||
LatLng latLng1 = new LatLng(40.71199035644531, -74.0081);
|
||||
LatLng latLng2 = new LatLng(40.71199035644531, -74.0081);
|
||||
double distance = latLng1.distanceTo(latLng2);
|
||||
assertEquals("distance should match", 0.0, distance, DELTA);
|
||||
}
|
||||
|
||||
// Regression test for #14216
|
||||
@Test
|
||||
public void testDistanceToClosePointNotNaN() {
|
||||
LatLng latLng = new LatLng(40.00599, -105.29261);
|
||||
LatLng other = new LatLng(40.005990000000025, -105.29260999999997);
|
||||
double distance = latLng.distanceTo(other);
|
||||
assertNotEquals(distance, Double.NaN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocationProvider() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
|
||||
// Mock the location class
|
||||
Location locationMocked = mock(Location.class);
|
||||
when(locationMocked.getLatitude()).thenReturn(latitude);
|
||||
when(locationMocked.getLongitude()).thenReturn(longitude);
|
||||
when(locationMocked.getAltitude()).thenReturn(altitude);
|
||||
|
||||
// Test the constructor
|
||||
LatLng latLng = new LatLng(locationMocked);
|
||||
assertEquals("latitude should match", latLng.getLatitude(), latitude, DELTA);
|
||||
assertEquals("longitude should match", latLng.getLongitude(), longitude, DELTA);
|
||||
assertEquals("altitude should match", latLng.getAltitude(), altitude, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
LatLng latLng = new LatLng(latitude, longitude, altitude);
|
||||
assertEquals("hash code should match", latLng.hashCode(), -151519232);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
LatLng latLng = new LatLng(latitude, longitude, altitude);
|
||||
assertEquals("string should match",
|
||||
latLng.toString(),
|
||||
"LatLng [latitude=1.2, longitude=3.4, altitude=5.6]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsOther() {
|
||||
double latitude = 1.2;
|
||||
double longitude = 3.4;
|
||||
double altitude = 5.6;
|
||||
LatLng latLng1 = new LatLng(latitude, longitude, altitude);
|
||||
LatLng latLng2 = new LatLng(latitude, longitude, altitude);
|
||||
assertEquals("LatLng should match", latLng1, latLng2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsItself() {
|
||||
LatLng latLng = new LatLng(1, 2, 3);
|
||||
assertEquals("LatLng should match", latLng, latLng);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotEquals() {
|
||||
LatLng latLng = new LatLng(1, 2);
|
||||
assertNotEquals("LatLng should match", latLng, new Object());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
LatLng latLng = new LatLng(45.0, -185.0);
|
||||
Parcelable parcel = MockParcel.obtain(latLng);
|
||||
assertEquals("parcel should match initial object", latLng, parcel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapped() {
|
||||
LatLng originalLatLng = new LatLng(45.0, -185.0);
|
||||
LatLng newLatlng = originalLatLng.wrap();
|
||||
assertNotSame(" new wrapped LatLng is created", originalLatLng, newLatlng);
|
||||
assertEquals("longitude wrapped value", originalLatLng.getLongitude(), -185.0, DELTA);
|
||||
assertEquals("longitude wrapped value", newLatlng.getLongitude(), 175.0, DELTA);
|
||||
|
||||
newLatlng = new LatLng(45.0, 180.0).wrap();
|
||||
assertEquals("longitude wrapped max value", newLatlng.getLongitude(), 180.0, DELTA);
|
||||
|
||||
newLatlng = new LatLng(45.0, -180.0).wrap();
|
||||
assertEquals("longitude wrapped min value", newLatlng.getLongitude(), -180.0, DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnnecessaryWrapped() {
|
||||
LatLng latLng = new LatLng(45.0, 50.0).wrap();
|
||||
assertEquals("longitude wrapped value", latLng.getLongitude(), 50.0, DELTA);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
package com.mapbox.mapboxsdk.geometry
|
||||
|
||||
import android.location.Location
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.mockito.Mockito
|
||||
|
||||
class LatLngTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val latLng = LatLng(0.0, 0.0)
|
||||
Assert.assertNotNull("latLng should not be null", latLng)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatitudeEmptyConstructor() {
|
||||
val latLng = LatLng()
|
||||
Assert.assertEquals("latitude default value", latLng.latitude, 0.0, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongitudeEmptyConstructor() {
|
||||
val latLng = LatLng()
|
||||
Assert.assertEquals("longitude default value", latLng.longitude, 0.0, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAltitudeEmptyConstructor() {
|
||||
val latLng1 = LatLng()
|
||||
Assert.assertEquals("altitude default value", latLng1.altitude, 0.0, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatitudeConstructor() {
|
||||
val latitude = 1.2
|
||||
val latLng = LatLng(latitude, 3.4)
|
||||
Assert.assertEquals("latitude should match", latLng.latitude, latitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongitudeConstructor() {
|
||||
val longitude = 3.4
|
||||
val latLng = LatLng(1.2, longitude)
|
||||
Assert.assertEquals("longitude should match", latLng.longitude, longitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAltitudeConstructor() {
|
||||
val latLng1 = LatLng(1.2, 3.4)
|
||||
Assert.assertEquals("altitude default value", latLng1.altitude, 0.0, DELTA)
|
||||
val altitude = 5.6
|
||||
val latLng2 = LatLng(1.2, 3.4, altitude)
|
||||
Assert.assertEquals("altitude default value", latLng2.altitude, altitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatitudeSetter() {
|
||||
val latLng = LatLng(1.2, 3.4)
|
||||
latLng.setLatitude(3.0)
|
||||
Assert.assertEquals("latitude should match", 3.0, latLng.latitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongitudeSetter() {
|
||||
val latLng = LatLng(1.2, 3.4)
|
||||
latLng.setLongitude(3.0)
|
||||
Assert.assertEquals("longitude should match", 3.0, latLng.longitude, DELTA)
|
||||
}
|
||||
|
||||
@Rule @JvmField
|
||||
val exception = ExpectedException.none()
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksLatitudeNaN() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must not be NaN")
|
||||
LatLng(Double.NaN, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksLongitudeNaN() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("longitude must not be NaN")
|
||||
LatLng(0.0, Double.NaN)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksLatitudeGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
LatLng(95.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksLatitudeLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
LatLng(-95.0, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorChecksLongitudeInfinity() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("longitude must not be infinite")
|
||||
LatLng(0.0, Double.POSITIVE_INFINITY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatitudeSetterChecksNaN() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must not be NaN")
|
||||
LatLng().setLatitude(Double.NaN)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongitudeSetterChecksNaN() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("longitude must not be NaN")
|
||||
LatLng().setLongitude(Double.NaN)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatitudeSetterChecksGreaterThan90() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
LatLng().setLatitude(95.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatitudeSetterChecksLessThanThanNegative90() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("latitude must be between -90 and 90")
|
||||
LatLng().setLatitude(-95.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongitudeSetterChecksInfinity() {
|
||||
exception.expect(IllegalArgumentException::class.java)
|
||||
exception.expectMessage("longitude must not be infinite")
|
||||
LatLng().setLongitude(Double.NEGATIVE_INFINITY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAltitudeSetter() {
|
||||
val latLng = LatLng(1.2, 3.4)
|
||||
latLng.altitude = 3.0
|
||||
Assert.assertEquals("altitude should match", 3.0, latLng.altitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatLngConstructor() {
|
||||
val latLng1 = LatLng(1.2, 3.4)
|
||||
val latLng2 = LatLng(latLng1)
|
||||
Assert.assertEquals("latLng should match", latLng1, latLng2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDistanceTo() {
|
||||
val latLng1 = LatLng(0.0, 0.0)
|
||||
val latLng2 = LatLng(1.0, 1.0)
|
||||
Assert.assertEquals(
|
||||
"distances should match",
|
||||
latLng1.distanceTo(latLng2),
|
||||
157298.7453847275,
|
||||
DELTA
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDistanceToSamePoint() {
|
||||
val latLng1 = LatLng(40.71199035644531, -74.0081)
|
||||
val latLng2 = LatLng(40.71199035644531, -74.0081)
|
||||
val distance = latLng1.distanceTo(latLng2)
|
||||
Assert.assertEquals("distance should match", 0.0, distance, DELTA)
|
||||
}
|
||||
|
||||
// Regression test for #14216
|
||||
@Test
|
||||
fun testDistanceToClosePointNotNaN() {
|
||||
val latLng = LatLng(40.00599, -105.29261)
|
||||
val other = LatLng(40.005990000000025, -105.29260999999997)
|
||||
val distance = latLng.distanceTo(other)
|
||||
Assert.assertNotEquals(distance, Double.NaN)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLocationProvider() {
|
||||
val latitude = 1.2
|
||||
val longitude = 3.4
|
||||
val altitude = 5.6
|
||||
|
||||
// Mock the location class
|
||||
val locationMocked = Mockito.mock(
|
||||
Location::class.java
|
||||
)
|
||||
Mockito.`when`(locationMocked.latitude).thenReturn(latitude)
|
||||
Mockito.`when`(locationMocked.longitude).thenReturn(longitude)
|
||||
Mockito.`when`(locationMocked.altitude).thenReturn(altitude)
|
||||
|
||||
// Test the constructor
|
||||
val latLng = LatLng(locationMocked)
|
||||
Assert.assertEquals("latitude should match", latLng.latitude, latitude, DELTA)
|
||||
Assert.assertEquals("longitude should match", latLng.longitude, longitude, DELTA)
|
||||
Assert.assertEquals("altitude should match", latLng.altitude, altitude, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashCode() {
|
||||
val latitude = 1.2
|
||||
val longitude = 3.4
|
||||
val altitude = 5.6
|
||||
val latLng = LatLng(latitude, longitude, altitude)
|
||||
Assert.assertEquals("hash code should match", latLng.hashCode().toLong(), -151519232)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToString() {
|
||||
val latitude = 1.2
|
||||
val longitude = 3.4
|
||||
val altitude = 5.6
|
||||
val latLng = LatLng(latitude, longitude, altitude)
|
||||
Assert.assertEquals(
|
||||
"string should match",
|
||||
latLng.toString(),
|
||||
"LatLng [latitude=1.2, longitude=3.4, altitude=5.6]"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualsOther() {
|
||||
val latitude = 1.2
|
||||
val longitude = 3.4
|
||||
val altitude = 5.6
|
||||
val latLng1 = LatLng(latitude, longitude, altitude)
|
||||
val latLng2 = LatLng(latitude, longitude, altitude)
|
||||
Assert.assertEquals("LatLng should match", latLng1, latLng2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEqualsItself() {
|
||||
val latLng = LatLng(1.0, 2.0, 3.0)
|
||||
Assert.assertEquals("LatLng should match", latLng, latLng)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNotEquals() {
|
||||
val latLng = LatLng(1.0, 2.0)
|
||||
Assert.assertNotEquals("LatLng should match", latLng, Any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParcelable() {
|
||||
val latLng = LatLng(45.0, -185.0)
|
||||
val parcel = MockParcel.obtain(latLng)
|
||||
Assert.assertEquals("parcel should match initial object", latLng, parcel)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testWrapped() {
|
||||
val originalLatLng = LatLng(45.0, -185.0)
|
||||
var newLatlng = originalLatLng.wrap()
|
||||
Assert.assertNotSame(" new wrapped LatLng is created", originalLatLng, newLatlng)
|
||||
Assert.assertEquals("longitude wrapped value", originalLatLng.longitude, -185.0, DELTA)
|
||||
Assert.assertEquals("longitude wrapped value", newLatlng.longitude, 175.0, DELTA)
|
||||
newLatlng = LatLng(45.0, 180.0).wrap()
|
||||
Assert.assertEquals("longitude wrapped max value", newLatlng.longitude, 180.0, DELTA)
|
||||
newLatlng = LatLng(45.0, -180.0).wrap()
|
||||
Assert.assertEquals("longitude wrapped min value", newLatlng.longitude, -180.0, DELTA)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUnnecessaryWrapped() {
|
||||
val latLng = LatLng(45.0, 50.0).wrap()
|
||||
Assert.assertEquals("longitude wrapped value", latLng.longitude, 50.0, DELTA)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DELTA = 1e-15
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class ProjectedMetersTest {
|
||||
|
||||
private static final LatLng LAT_LNG_NULL_ISLAND = new LatLng(0, 0);
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0);
|
||||
assertNotNull("projectedMeters should not be null", projectedMeters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 0.0);
|
||||
assertEquals("projectedMeters is not equal to a LatLng", projectedMeters.equals(LAT_LNG_NULL_ISLAND), false);
|
||||
assertEquals("projectedMeters is equal to itself", projectedMeters.equals(projectedMeters), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNorthing() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(1.0, 0.0);
|
||||
assertEquals("northing should be 1", 1, projectedMeters.getNorthing(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEasting() {
|
||||
ProjectedMeters projectedMeters = new ProjectedMeters(0.0, 1.0);
|
||||
assertEquals("easting should be 1", 1, projectedMeters.getEasting(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
ProjectedMeters projectedMeters1 = new ProjectedMeters(1, 2);
|
||||
ProjectedMeters projectedMeters2 = new ProjectedMeters(projectedMeters1);
|
||||
assertEquals("projectedmeters should match", projectedMeters1, projectedMeters2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
ProjectedMeters meters = new ProjectedMeters(1, 2);
|
||||
assertEquals("hashcode should match", -1048576, meters.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
ProjectedMeters meters = new ProjectedMeters(1, 1);
|
||||
assertEquals("toString should match", "ProjectedMeters [northing=1.0, easting=1.0]", meters.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
ProjectedMeters meters = new ProjectedMeters(1, 1);
|
||||
Parcelable parcel = MockParcel.obtain(meters);
|
||||
assertEquals("parcel should match initial object", meters, parcel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mapbox.mapboxsdk.geometry
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class ProjectedMetersTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val projectedMeters = ProjectedMeters(0.0, 0.0)
|
||||
Assert.assertNotNull("projectedMeters should not be null", projectedMeters)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquality() {
|
||||
val projectedMeters = ProjectedMeters(0.0, 0.0)
|
||||
Assert.assertEquals(
|
||||
"projectedMeters is not equal to a LatLng",
|
||||
projectedMeters.equals(
|
||||
LAT_LNG_NULL_ISLAND
|
||||
),
|
||||
false
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"projectedMeters is equal to itself",
|
||||
projectedMeters.equals(projectedMeters),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNorthing() {
|
||||
val projectedMeters = ProjectedMeters(1.0, 0.0)
|
||||
Assert.assertEquals("northing should be 1", 1.0, projectedMeters.northing, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEasting() {
|
||||
val projectedMeters = ProjectedMeters(0.0, 1.0)
|
||||
Assert.assertEquals("easting should be 1", 1.0, projectedMeters.easting, 0.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructor() {
|
||||
val projectedMeters1 = ProjectedMeters(1.0, 2.0)
|
||||
val projectedMeters2 = ProjectedMeters(projectedMeters1)
|
||||
Assert.assertEquals("projectedmeters should match", projectedMeters1, projectedMeters2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashcode() {
|
||||
val meters = ProjectedMeters(1.0, 2.0)
|
||||
Assert.assertEquals("hashcode should match", -1048576, meters.hashCode().toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToString() {
|
||||
val meters = ProjectedMeters(1.0, 1.0)
|
||||
Assert.assertEquals(
|
||||
"toString should match",
|
||||
"ProjectedMeters [northing=1.0, easting=1.0]",
|
||||
meters.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParcelable() {
|
||||
val meters = ProjectedMeters(1.0, 1.0)
|
||||
val parcel = MockParcel.obtain(meters)
|
||||
Assert.assertEquals("parcel should match initial object", meters, parcel)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LAT_LNG_NULL_ISLAND = LatLng(0.0, 0.0)
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.geometry;
|
||||
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class VisibleRegionTest {
|
||||
|
||||
private static final LatLng FAR_LEFT = new LatLng(52, -12);
|
||||
private static final LatLng NEAR_LEFT = new LatLng(34, -12);
|
||||
private static final LatLng FAR_RIGHT = new LatLng(52, 26);
|
||||
private static final LatLng NEAR_RIGHT = new LatLng(34, 26);
|
||||
private static final LatLngBounds BOUNDS =
|
||||
new LatLngBounds.Builder().include(FAR_LEFT).include(FAR_RIGHT).include(NEAR_LEFT).include(NEAR_RIGHT).build();
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertNotNull("region should not be null", region);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("visibleRegion is not equal to a LatLng", region.equals(FAR_LEFT), false);
|
||||
assertEquals("visibleRegion is equal to itself", region.equals(region), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFarLeftConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.farLeft, FAR_LEFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNearLeftConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.nearLeft, NEAR_LEFT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFarRightConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.farRight, FAR_RIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNearRightConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLng should match", region.nearRight, NEAR_RIGHT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatLngBoundsConstructor() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("LatLngBounds should match", region.latLngBounds, BOUNDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
VisibleRegion regionLeft = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
VisibleRegion regionRight = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("VisibleRegions should match", regionLeft, regionRight);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcode() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("hashcode should match", -923534102, region.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
assertEquals("string should match",
|
||||
"[farLeft [LatLng [latitude=52.0, longitude=-12.0, altitude=0.0]], "
|
||||
+ "farRight [LatLng [latitude=52.0, longitude=26.0, altitude=0.0]], "
|
||||
+ "nearLeft [LatLng [latitude=34.0, longitude=-12.0, altitude=0.0]], "
|
||||
+ "nearRight [LatLng [latitude=34.0, longitude=26.0, altitude=0.0]], "
|
||||
+ "latLngBounds [N:52.0; E:26.0; S:34.0; W:-12.0]]",
|
||||
region.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParcelable() {
|
||||
VisibleRegion region = new VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS);
|
||||
Parcelable parcel = MockParcel.obtain(region);
|
||||
assertEquals("parcel should match initial object", region, parcel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.mapbox.mapboxsdk.geometry
|
||||
|
||||
import com.mapbox.mapboxsdk.utils.MockParcel
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class VisibleRegionTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertNotNull("region should not be null", region)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquality() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals(
|
||||
"visibleRegion is not equal to a LatLng",
|
||||
region.equals(FAR_LEFT),
|
||||
false
|
||||
)
|
||||
Assert.assertEquals("visibleRegion is equal to itself", region.equals(region), true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFarLeftConstructor() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals("LatLng should match", region.farLeft, FAR_LEFT)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNearLeftConstructor() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals("LatLng should match", region.nearLeft, NEAR_LEFT)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFarRightConstructor() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals("LatLng should match", region.farRight, FAR_RIGHT)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNearRightConstructor() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals("LatLng should match", region.nearRight, NEAR_RIGHT)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLatLngBoundsConstructor() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals("LatLngBounds should match", region.latLngBounds, BOUNDS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquals() {
|
||||
val regionLeft = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
val regionRight = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals("VisibleRegions should match", regionLeft, regionRight)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHashcode() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals("hashcode should match", -923534102, region.hashCode().toLong())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToString() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
Assert.assertEquals(
|
||||
"string should match",
|
||||
"[farLeft [LatLng [latitude=52.0, longitude=-12.0, altitude=0.0]], " +
|
||||
"farRight [LatLng [latitude=52.0, longitude=26.0, altitude=0.0]], " +
|
||||
"nearLeft [LatLng [latitude=34.0, longitude=-12.0, altitude=0.0]], " +
|
||||
"nearRight [LatLng [latitude=34.0, longitude=26.0, altitude=0.0]], " +
|
||||
"latLngBounds [N:52.0; E:26.0; S:34.0; W:-12.0]]",
|
||||
region.toString()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParcelable() {
|
||||
val region = VisibleRegion(FAR_LEFT, FAR_RIGHT, NEAR_LEFT, NEAR_RIGHT, BOUNDS)
|
||||
val parcel = MockParcel.obtain(region)
|
||||
Assert.assertEquals("parcel should match initial object", region, parcel)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val FAR_LEFT = LatLng(52.0, -12.0)
|
||||
private val NEAR_LEFT = LatLng(34.0, -12.0)
|
||||
private val FAR_RIGHT = LatLng(52.0, 26.0)
|
||||
private val NEAR_RIGHT = LatLng(34.0, 26.0)
|
||||
private val BOUNDS = LatLngBounds.Builder().include(FAR_LEFT).include(FAR_RIGHT).include(
|
||||
NEAR_LEFT
|
||||
).include(NEAR_RIGHT).build()
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentCompassEngine.SENSOR_DELAY_MICROS;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CompassEngineTest {
|
||||
|
||||
private LocationComponentCompassEngine compassEngine;
|
||||
|
||||
@Mock
|
||||
private WindowManager windowManager;
|
||||
|
||||
@Mock
|
||||
private SensorManager sensorManager;
|
||||
|
||||
@Mock
|
||||
private Sensor compassSensor;
|
||||
|
||||
@Mock
|
||||
private CompassListener compassListener;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)).thenReturn(compassSensor);
|
||||
compassEngine = new LocationComponentCompassEngine(windowManager, sensorManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastKnownCompassBearingAccuracyDefault() {
|
||||
assertEquals("Last accuracy should match", compassEngine.getLastAccuracySensorStatus(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lastKnownCompassAccuracyStatusValue() {
|
||||
Sensor sensor = mock(Sensor.class);
|
||||
compassEngine.onAccuracyChanged(sensor, 2);
|
||||
assertEquals("Last accuracy should match", compassEngine.getLastAccuracySensorStatus(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGyroscopeIsNull_fallbackToGravity() {
|
||||
SensorManager sensorManager = mock(SensorManager.class);
|
||||
new LocationComponentCompassEngine(windowManager, sensorManager);
|
||||
|
||||
verify(sensorManager, times(1)).getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGyroscopeIsNull_fallbackToMagneticField() {
|
||||
SensorManager sensorManager = mock(SensorManager.class);
|
||||
new LocationComponentCompassEngine(windowManager, sensorManager);
|
||||
|
||||
verify(sensorManager, times(1)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listener_registerOnAdd() {
|
||||
compassEngine.addCompassListener(compassListener);
|
||||
verify(sensorManager)
|
||||
.registerListener(any(SensorEventListener.class), eq(compassSensor), eq(SENSOR_DELAY_MICROS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listener_unregisterOnRemove() {
|
||||
compassEngine.addCompassListener(compassListener);
|
||||
compassEngine.removeCompassListener(compassListener);
|
||||
verify(sensorManager).unregisterListener(any(SensorEventListener.class), eq(compassSensor));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.mapbox.mapboxsdk.location
|
||||
|
||||
import android.hardware.Sensor
|
||||
import android.hardware.SensorEventListener
|
||||
import android.hardware.SensorManager
|
||||
import android.view.WindowManager
|
||||
import junit.framework.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class CompassEngineTest {
|
||||
private var compassEngine: LocationComponentCompassEngine? = null
|
||||
|
||||
@Mock
|
||||
private val windowManager: WindowManager? = null
|
||||
|
||||
@Mock
|
||||
private val sensorManager: SensorManager? = null
|
||||
|
||||
@Mock
|
||||
private val compassSensor: Sensor? = null
|
||||
|
||||
@Mock
|
||||
private val compassListener: CompassListener? = null
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
Mockito.`when`(sensorManager!!.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR))
|
||||
.thenReturn(compassSensor)
|
||||
compassEngine = LocationComponentCompassEngine(windowManager!!, sensorManager)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lastKnownCompassBearingAccuracyDefault() {
|
||||
Assert.assertEquals(
|
||||
"Last accuracy should match",
|
||||
compassEngine!!.lastAccuracySensorStatus,
|
||||
0
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lastKnownCompassAccuracyStatusValue() {
|
||||
val sensor = Mockito.mock(
|
||||
Sensor::class.java
|
||||
)
|
||||
compassEngine!!.onAccuracyChanged(sensor, 2)
|
||||
Assert.assertEquals(
|
||||
"Last accuracy should match",
|
||||
compassEngine!!.lastAccuracySensorStatus,
|
||||
2
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGyroscopeIsNull_fallbackToGravity() {
|
||||
val sensorManager = Mockito.mock(SensorManager::class.java)
|
||||
LocationComponentCompassEngine(windowManager!!, sensorManager)
|
||||
Mockito.verify(sensorManager, Mockito.times(1)).getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGyroscopeIsNull_fallbackToMagneticField() {
|
||||
val sensorManager = Mockito.mock(SensorManager::class.java)
|
||||
LocationComponentCompassEngine(windowManager!!, sensorManager)
|
||||
Mockito.verify(sensorManager, Mockito.times(1)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listener_registerOnAdd() {
|
||||
compassEngine!!.addCompassListener(compassListener!!)
|
||||
Mockito.verify(sensorManager)
|
||||
?.registerListener(
|
||||
ArgumentMatchers.any(SensorEventListener::class.java),
|
||||
ArgumentMatchers.eq(compassSensor),
|
||||
ArgumentMatchers.eq(LocationComponentCompassEngine.SENSOR_DELAY_MICROS)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun listener_unregisterOnRemove() {
|
||||
compassEngine!!.addCompassListener(compassListener!!)
|
||||
compassEngine!!.removeCompassListener(compassListener)
|
||||
Mockito.verify(sensorManager)?.unregisterListener(
|
||||
ArgumentMatchers.any(
|
||||
SensorEventListener::class.java
|
||||
),
|
||||
ArgumentMatchers.eq(compassSensor)
|
||||
)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,160 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LocationComponentActivationOptionsTest {
|
||||
|
||||
@Mock
|
||||
private Context context;
|
||||
@Mock
|
||||
private TypedArray array;
|
||||
@Mock
|
||||
private Resources resources;
|
||||
@Mock
|
||||
private Style style;
|
||||
|
||||
@Rule
|
||||
public MockitoRule mockitoRule = MockitoJUnit.rule();
|
||||
|
||||
@NonNull
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(context.obtainStyledAttributes(R.style.maplibre_LocationComponent, R.styleable.maplibre_LocationComponent))
|
||||
.thenReturn(array);
|
||||
when(array.getResourceId(R.styleable.maplibre_LocationComponent_maplibre_foregroundDrawable, -1))
|
||||
.thenReturn(R.drawable.maplibre_user_icon);
|
||||
when(context.getResources()).thenReturn(resources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanity() throws Exception {
|
||||
when(style.isFullyLoaded()).thenReturn(true);
|
||||
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build();
|
||||
assertNotNull(locationComponentOptions);
|
||||
|
||||
LocationComponentActivationOptions locationComponentActivationOptions =
|
||||
LocationComponentActivationOptions.builder(context, style)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build();
|
||||
assertNotNull(locationComponentActivationOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanityWithDefaultPulsingCircle() throws Exception {
|
||||
when(style.isFullyLoaded()).thenReturn(true);
|
||||
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(0.5f)
|
||||
.pulseEnabled(true)
|
||||
.build();
|
||||
assertNotNull(locationComponentOptions);
|
||||
|
||||
LocationComponentActivationOptions locationComponentActivationOptions =
|
||||
LocationComponentActivationOptions.builder(context, style)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build();
|
||||
assertNotNull(locationComponentActivationOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanityWithCustomizedPulsingCircle() throws Exception {
|
||||
when(style.isFullyLoaded()).thenReturn(true);
|
||||
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(0.5f)
|
||||
.pulseEnabled(true)
|
||||
.pulseColor(Color.RED)
|
||||
.pulseInterpolator(new LinearInterpolator())
|
||||
.build();
|
||||
assertNotNull(locationComponentOptions);
|
||||
|
||||
LocationComponentActivationOptions locationComponentActivationOptions =
|
||||
LocationComponentActivationOptions.builder(context, style)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build();
|
||||
assertNotNull(locationComponentActivationOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void includingBothStyleResAndComponentOptions_causesExceptionToBeThrown() throws Exception {
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("You've provided both a style resource and a LocationComponentOptions"
|
||||
+ " object to the LocationComponentActivationOptions builder. You can't use both and "
|
||||
+ "you must choose one of the two to style the LocationComponent.");
|
||||
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build();
|
||||
|
||||
LocationComponentActivationOptions.builder(context, style)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.styleRes(R.style.maplibre_LocationComponent)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullContext_causesExceptionToBeThrown() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("Context in LocationComponentActivationOptions is null.");
|
||||
|
||||
LocationComponentActivationOptions.builder(null, style)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullStyle_causesExceptionToBeThrown() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("Style in LocationComponentActivationOptions is null. Make sure the Style object isn't null."
|
||||
+ " Wait for the map to fully load before passing the Style object to LocationComponentActivationOptions.");
|
||||
|
||||
LocationComponentActivationOptions.builder(context, null)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locationComponent_exceptionThrownWithDefaultLocationEngineButNotFullyLoadedStyle() throws Exception {
|
||||
|
||||
when(style.isFullyLoaded()).thenReturn(false);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Style in LocationComponentActivationOptions isn't fully loaded. Wait for the "
|
||||
+ "map to fully load before passing the Style object to "
|
||||
+ "LocationComponentActivationOptions.");
|
||||
|
||||
LocationComponentActivationOptions.builder(context, style)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.mapbox.mapboxsdk.location
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.content.res.TypedArray
|
||||
import android.graphics.Color
|
||||
import android.view.animation.LinearInterpolator
|
||||
import com.mapbox.mapboxsdk.R
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.MockitoJUnit
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class LocationComponentActivationOptionsTest {
|
||||
@Mock
|
||||
private val context: Context? = null
|
||||
|
||||
@Mock
|
||||
private val array: TypedArray? = null
|
||||
|
||||
@Mock
|
||||
private val resources: Resources? = null
|
||||
|
||||
@Mock
|
||||
private val style: Style? = null
|
||||
|
||||
@Rule @JvmField
|
||||
var mockitoRule = MockitoJUnit.rule()
|
||||
|
||||
@Rule @JvmField
|
||||
var thrown = ExpectedException.none()
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
Mockito.`when`(
|
||||
context!!.obtainStyledAttributes(
|
||||
R.style.maplibre_LocationComponent,
|
||||
R.styleable.maplibre_LocationComponent
|
||||
)
|
||||
)
|
||||
.thenReturn(array)
|
||||
Mockito.`when`(
|
||||
array!!.getResourceId(
|
||||
R.styleable.maplibre_LocationComponent_maplibre_foregroundDrawable,
|
||||
-1
|
||||
)
|
||||
)
|
||||
.thenReturn(R.drawable.maplibre_user_icon)
|
||||
Mockito.`when`(context.resources).thenReturn(resources)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun sanity() {
|
||||
Mockito.`when`(style!!.isFullyLoaded).thenReturn(true)
|
||||
val locationComponentOptions = LocationComponentOptions.builder(
|
||||
context!!
|
||||
)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build()
|
||||
Assert.assertNotNull(locationComponentOptions)
|
||||
val locationComponentActivationOptions = LocationComponentActivationOptions.builder(
|
||||
context,
|
||||
style
|
||||
)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build()
|
||||
Assert.assertNotNull(locationComponentActivationOptions)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun sanityWithDefaultPulsingCircle() {
|
||||
Mockito.`when`(style!!.isFullyLoaded).thenReturn(true)
|
||||
val locationComponentOptions = LocationComponentOptions.builder(
|
||||
context!!
|
||||
)
|
||||
.accuracyAlpha(0.5f)
|
||||
.pulseEnabled(true)
|
||||
.build()
|
||||
Assert.assertNotNull(locationComponentOptions)
|
||||
val locationComponentActivationOptions = LocationComponentActivationOptions.builder(
|
||||
context,
|
||||
style
|
||||
)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build()
|
||||
Assert.assertNotNull(locationComponentActivationOptions)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun sanityWithCustomizedPulsingCircle() {
|
||||
Mockito.`when`(style!!.isFullyLoaded).thenReturn(true)
|
||||
val locationComponentOptions = LocationComponentOptions.builder(
|
||||
context!!
|
||||
)
|
||||
.accuracyAlpha(0.5f)
|
||||
.pulseEnabled(true)
|
||||
.pulseColor(Color.RED)
|
||||
.pulseInterpolator(LinearInterpolator())
|
||||
.build()
|
||||
Assert.assertNotNull(locationComponentOptions)
|
||||
val locationComponentActivationOptions = LocationComponentActivationOptions.builder(
|
||||
context,
|
||||
style
|
||||
)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build()
|
||||
Assert.assertNotNull(locationComponentActivationOptions)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun includingBothStyleResAndComponentOptions_causesExceptionToBeThrown() {
|
||||
thrown.expect(IllegalArgumentException::class.java)
|
||||
thrown.expectMessage(
|
||||
"You've provided both a style resource and a LocationComponentOptions" +
|
||||
" object to the LocationComponentActivationOptions builder. You can't use both and " +
|
||||
"you must choose one of the two to style the LocationComponent."
|
||||
)
|
||||
val locationComponentOptions = LocationComponentOptions.builder(
|
||||
context!!
|
||||
)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build()
|
||||
LocationComponentActivationOptions.builder(context, style!!)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.styleRes(R.style.maplibre_LocationComponent)
|
||||
.build()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun locationComponent_exceptionThrownWithDefaultLocationEngineButNotFullyLoadedStyle() {
|
||||
Mockito.`when`(style!!.isFullyLoaded).thenReturn(false)
|
||||
thrown.expect(IllegalArgumentException::class.java)
|
||||
thrown.expectMessage(
|
||||
"Style in LocationComponentActivationOptions isn't fully loaded. Wait for the " +
|
||||
"map to fully load before passing the Style object to " +
|
||||
"LocationComponentActivationOptions."
|
||||
)
|
||||
LocationComponentActivationOptions.builder(context!!, style)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LocationComponentOptionsTest {
|
||||
|
||||
@Mock
|
||||
private Context context;
|
||||
@Mock
|
||||
private TypedArray array;
|
||||
@Mock
|
||||
private Resources resources;
|
||||
|
||||
@NonNull
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(context.obtainStyledAttributes(R.style.maplibre_LocationComponent, R.styleable.maplibre_LocationComponent))
|
||||
.thenReturn(array);
|
||||
when(array.getResourceId(R.styleable.maplibre_LocationComponent_maplibre_foregroundDrawable, -1))
|
||||
.thenReturn(R.drawable.maplibre_user_icon);
|
||||
when(context.getResources()).thenReturn(resources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sanity() throws Exception {
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build();
|
||||
assertNotNull(locationComponentOptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passingOutOfRangeAccuracyAlpha_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Accuracy alpha value must be between 0.0 and "
|
||||
+ "1.0.");
|
||||
LocationComponentOptions.builder(context)
|
||||
.accuracyAlpha(2f)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeElevation_causesExceptionToBeThrown() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid shadow size -500.0. Must be >= 0");
|
||||
LocationComponentOptions.builder(context)
|
||||
.elevation(-500)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void passingBothLayerPositionOptions_throwsException() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("You cannot set both layerAbove and layerBelow options."
|
||||
+ " Choose one or the other.");
|
||||
LocationComponentOptions.builder(context)
|
||||
.layerAbove("above")
|
||||
.layerBelow("below")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.mapbox.mapboxsdk.location
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.content.res.TypedArray
|
||||
import com.mapbox.mapboxsdk.R
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class LocationComponentOptionsTest {
|
||||
@Mock
|
||||
private val context: Context? = null
|
||||
|
||||
@Mock
|
||||
private val array: TypedArray? = null
|
||||
|
||||
@Mock
|
||||
private val resources: Resources? = null
|
||||
|
||||
@Rule @JvmField
|
||||
var thrown = ExpectedException.none()
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
Mockito.`when`(
|
||||
context!!.obtainStyledAttributes(
|
||||
R.style.maplibre_LocationComponent,
|
||||
R.styleable.maplibre_LocationComponent
|
||||
)
|
||||
)
|
||||
.thenReturn(array)
|
||||
Mockito.`when`(
|
||||
array!!.getResourceId(
|
||||
R.styleable.maplibre_LocationComponent_maplibre_foregroundDrawable,
|
||||
-1
|
||||
)
|
||||
)
|
||||
.thenReturn(R.drawable.maplibre_user_icon)
|
||||
Mockito.`when`(context.resources).thenReturn(resources)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun sanity() {
|
||||
val locationComponentOptions = LocationComponentOptions.builder(
|
||||
context!!
|
||||
)
|
||||
.accuracyAlpha(0.5f)
|
||||
.build()
|
||||
Assert.assertNotNull(locationComponentOptions)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun passingOutOfRangeAccuracyAlpha_throwsException() {
|
||||
thrown.expect(IllegalArgumentException::class.java)
|
||||
thrown.expectMessage(
|
||||
"Accuracy alpha value must be between 0.0 and " +
|
||||
"1.0."
|
||||
)
|
||||
LocationComponentOptions.builder(context!!)
|
||||
.accuracyAlpha(2f)
|
||||
.build()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun negativeElevation_causesExceptionToBeThrown() {
|
||||
thrown.expect(IllegalArgumentException::class.java)
|
||||
thrown.expectMessage("Invalid shadow size -500.0. Must be >= 0")
|
||||
LocationComponentOptions.builder(context!!)
|
||||
.elevation(-500f)
|
||||
.build()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun passingBothLayerPositionOptions_throwsException() {
|
||||
thrown.expect(IllegalArgumentException::class.java)
|
||||
thrown.expectMessage(
|
||||
"You cannot set both layerAbove and layerBelow options." +
|
||||
" Choose one or the other."
|
||||
)
|
||||
LocationComponentOptions.builder(context!!)
|
||||
.layerAbove("above")
|
||||
.layerBelow("below")
|
||||
.build()
|
||||
}
|
||||
}
|
||||
@@ -1,764 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.ACCURACY_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_STALE_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BEARING_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.FOREGROUND_STALE_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.LOCATION_SOURCE;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_ACCURACY_RADIUS;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_COMPASS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_FOREGROUND_ICON_OFFSET;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_GPS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_SHADOW_ICON_OFFSET;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PULSING_CIRCLE_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_ACCURACY;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_COMPASS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_GPS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_LATLNG;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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 LocationLayerControllerTest {
|
||||
|
||||
private MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
private Style style = mock(Style.class);
|
||||
private LocationLayerRenderer indicatorRenderer = mock(LocationLayerRenderer.class);
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
when(mapboxMap.getStyle()).thenReturn(style);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_locationSourceIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addSource(locationSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_shadowLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer shadowLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(shadowLayer);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addLayerBelow(shadowLayer, BACKGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_backgroundLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer backgroundLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(backgroundLayer);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addLayerBelow(backgroundLayer, FOREGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_foregroundLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer foregroundLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(foregroundLayer);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addLayerBelow(foregroundLayer, BEARING_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_bearingLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer bearingLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
String layerBelow = "layer-below";
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addLayerBelow(bearingLayer, layerBelow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_accuracyLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer accuracyLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addLayerBelow(accuracyLayer, BACKGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_pulsingCircleLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer pulsingCircleLayer = mock(Layer.class);
|
||||
when(sourceProvider.generatePulsingCircleLayer()).thenReturn(pulsingCircleLayer);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addLayerBelow(pulsingCircleLayer, ACCURACY_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_numberOfCachedLayerIdsIsConstant() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
Set<String> layerSet = new HashSet<>();
|
||||
when(sourceProvider.getEmptyLayerSet()).thenReturn(layerSet);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
LocationLayerController controller =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
controller.initializeComponents(mapboxMap.getStyle(), options);
|
||||
|
||||
assertEquals(6, layerSet.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleShadowWithValidElevation() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateShadowBitmap(any(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.elevation()).thenReturn(2f);
|
||||
|
||||
// Style is applied on initialization
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addImage(SHADOW_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_ignoreStyleShadowWithInvalidElevation() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateShadowBitmap(any(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.elevation()).thenReturn(0f);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style, times(0)).addImage(SHADOW_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleForegroundFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
int drawableResId = 123;
|
||||
int tintColor = 456;
|
||||
when(options.foregroundDrawable()).thenReturn(drawableResId);
|
||||
when(options.foregroundTintColor()).thenReturn(tintColor);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addImage(FOREGROUND_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleForegroundStaleFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
int drawableResId = 123;
|
||||
int tintColor = 456;
|
||||
when(options.foregroundDrawableStale()).thenReturn(drawableResId);
|
||||
when(options.foregroundStaleTintColor()).thenReturn(tintColor);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addImage(FOREGROUND_STALE_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBackgroundFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
int drawableResId = 123;
|
||||
int tintColor = 456;
|
||||
when(options.backgroundDrawable()).thenReturn(drawableResId);
|
||||
when(options.backgroundTintColor()).thenReturn(tintColor);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addImage(BACKGROUND_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBackgroundStaleFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
int drawableResId = 123;
|
||||
int tintColor = 456;
|
||||
when(options.backgroundDrawableStale()).thenReturn(drawableResId);
|
||||
when(options.backgroundStaleTintColor()).thenReturn(tintColor);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addImage(BACKGROUND_STALE_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBearingFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
int drawableResId = 123;
|
||||
int tintColor = 456;
|
||||
when(options.bearingDrawable()).thenReturn(drawableResId);
|
||||
when(options.bearingTintColor()).thenReturn(tintColor);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addImage(BEARING_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_specializedLayer_ignoreBitmapNames() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.foregroundName()).thenReturn("new_name");
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, true);
|
||||
|
||||
verify(indicatorRenderer).updateIconIds(eq(FOREGROUND_ICON), anyString(), anyString(), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowChanged() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateShadowBitmap(any(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
Layer bearingLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer2);
|
||||
Layer foregroundLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(foregroundLayer2);
|
||||
Layer backgroundLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(backgroundLayer2);
|
||||
Layer shadowLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(shadowLayer2);
|
||||
Layer accuracyLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer2);
|
||||
String layerBelow = "layer-below";
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
|
||||
layerController.applyStyle(options);
|
||||
|
||||
verify(style).removeLayer(BEARING_LAYER);
|
||||
verify(style).removeLayer(FOREGROUND_LAYER);
|
||||
verify(style).removeLayer(BACKGROUND_LAYER);
|
||||
verify(style).removeLayer(SHADOW_LAYER);
|
||||
verify(style).removeLayer(ACCURACY_LAYER);
|
||||
|
||||
verify(style).addLayerBelow(bearingLayer2, layerBelow);
|
||||
verify(style).addLayerBelow(foregroundLayer2, BEARING_LAYER);
|
||||
verify(style).addLayerBelow(backgroundLayer2, FOREGROUND_LAYER);
|
||||
verify(style).addLayerBelow(shadowLayer2, BACKGROUND_LAYER);
|
||||
verify(style).addLayerBelow(accuracyLayer2, BACKGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowNotChanged() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateShadowBitmap(any(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
|
||||
String layerBelow = "layer-below";
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
options = mock(LocationComponentOptions.class);
|
||||
layerBelow = "layer-below";
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
layerController.applyStyle(options);
|
||||
|
||||
verify(style, times(0)).removeLayer(any(String.class));
|
||||
verify(style, times(6)).addLayerBelow(any(Layer.class), any(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowNotChangedNull() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateShadowBitmap(any(LocationComponentOptions.class))).thenReturn(bitmap);
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
options = mock(LocationComponentOptions.class);
|
||||
layerController.applyStyle(options);
|
||||
|
||||
verify(style, times(0)).removeLayer(any(String.class));
|
||||
verify(style, times(1)).addLayer(any(Layer.class));
|
||||
verify(style, times(5)).addLayerBelow(any(Layer.class), Mockito.<String>any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateForegroundOffset_foregroundIconPropertyIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
layer.cameraTiltUpdated(2d);
|
||||
|
||||
verify(locationFeature).addProperty(eq(PROPERTY_FOREGROUND_ICON_OFFSET), any(JsonElement.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateForegroundOffset_shadowPropertyIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
layer.cameraTiltUpdated(2d);
|
||||
|
||||
verify(locationFeature).addProperty(eq(PROPERTY_SHADOW_ICON_OFFSET), any(JsonElement.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewLatLngValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_LATLNG, layer.getAnimationListeners()).onNewAnimationValue(new LatLng());
|
||||
|
||||
// wanted twice (once for initialization)
|
||||
verify(locationSource, times(2)).setGeoJson(locationFeature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewGpsBearingValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float gpsBearing = 2f;
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_GPS_BEARING, layer.getAnimationListeners()).onNewAnimationValue(gpsBearing);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_GPS_BEARING, gpsBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewGpsBearingValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
layer.setRenderMode(RenderMode.COMPASS);
|
||||
float gpsBearing = 2f;
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_GPS_BEARING, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0)).addNumberProperty(PROPERTY_GPS_BEARING, gpsBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewCompassBearingValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
layer.setRenderMode(RenderMode.COMPASS);
|
||||
float compassBearing = 2f;
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_COMPASS_BEARING, layer.getAnimationListeners())
|
||||
.onNewAnimationValue(compassBearing);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_COMPASS_BEARING, compassBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewCompassBearingValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float compassBearing = 2f;
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_COMPASS_BEARING, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0)).addNumberProperty(PROPERTY_COMPASS_BEARING, compassBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewAccuracyRadiusValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
layer.setRenderMode(RenderMode.NORMAL);
|
||||
float accuracyRadiusValue = 2f;
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_ACCURACY, layer.getAnimationListeners())
|
||||
.onNewAnimationValue(accuracyRadiusValue);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracyRadiusValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewAccuracyRadiusValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float accuracyRadiusValue = 2f;
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_ACCURACY, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0))
|
||||
.addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracyRadiusValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderModeChanged_doNotNotifyAboutDuplicates_NORMAL() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
LocationLayerController controller =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
controller.setRenderMode(RenderMode.NORMAL);
|
||||
controller.setRenderMode(RenderMode.NORMAL);
|
||||
|
||||
verify(internalRenderModeChangedListener, times(1)).onRenderModeChanged(RenderMode.NORMAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderModeChanged_doNotNotifyAboutDuplicates_GPS() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
LocationLayerController controller =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
controller.setRenderMode(RenderMode.GPS);
|
||||
controller.setRenderMode(RenderMode.GPS);
|
||||
|
||||
verify(internalRenderModeChangedListener, times(1)).onRenderModeChanged(RenderMode.GPS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void layerHidden_renderModeChanged_layerShown_foregroundIconUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
int drawableResId = 123;
|
||||
int tintColor = 456;
|
||||
when(options.foregroundDrawable()).thenReturn(drawableResId);
|
||||
when(options.foregroundTintColor()).thenReturn(tintColor);
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
Bitmap bitmap = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
LocationLayerController controller =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options, internalRenderModeChangedListener, false);
|
||||
|
||||
verify(style).addImage(FOREGROUND_ICON, bitmap);
|
||||
|
||||
int drawableGpsResId = 789;
|
||||
when(options.gpsDrawable()).thenReturn(drawableGpsResId);
|
||||
|
||||
Bitmap bitmapGps = mock(Bitmap.class);
|
||||
when(bitmapProvider.generateBitmap(drawableGpsResId, tintColor)).thenReturn(bitmapGps);
|
||||
|
||||
controller.hide();
|
||||
|
||||
controller.setRenderMode(RenderMode.GPS);
|
||||
|
||||
controller.show();
|
||||
|
||||
verify(style).addImage(FOREGROUND_ICON, bitmapGps);
|
||||
}
|
||||
|
||||
private LayerFeatureProvider buildFeatureProvider(@NonNull LocationComponentOptions options) {
|
||||
LayerFeatureProvider provider = mock(LayerFeatureProvider.class);
|
||||
when(provider.generateLocationFeature(null, options.enableStaleState())).thenReturn(mock(Feature.class));
|
||||
return provider;
|
||||
}
|
||||
|
||||
private LayerFeatureProvider buildFeatureProvider(Feature feature, @NonNull LocationComponentOptions options) {
|
||||
LayerFeatureProvider provider = mock(LayerFeatureProvider.class);
|
||||
when(provider.generateLocationFeature(null, options.enableStaleState())).thenReturn(feature);
|
||||
return provider;
|
||||
}
|
||||
|
||||
private LayerSourceProvider buildLayerProvider() {
|
||||
final LayerSourceProvider layerSourceProvider = mock(LayerSourceProvider.class);
|
||||
when(layerSourceProvider.getIndicatorLocationLayerRenderer()).thenReturn(indicatorRenderer);
|
||||
when(layerSourceProvider.getSymbolLocationLayerRenderer(any(LayerFeatureProvider.class), anyBoolean())).thenAnswer(
|
||||
new Answer<LocationLayerRenderer>() {
|
||||
@Override
|
||||
public LocationLayerRenderer answer(InvocationOnMock invocation) {
|
||||
LayerFeatureProvider featureProvider = invocation.getArgument(0);
|
||||
boolean isStale = invocation.getArgument(1);
|
||||
return new SymbolLocationLayerRenderer(layerSourceProvider, featureProvider, isStale);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Layer shadowLayer = mock(Layer.class);
|
||||
when(shadowLayer.getId()).thenReturn(SHADOW_LAYER);
|
||||
when(layerSourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(shadowLayer);
|
||||
|
||||
Layer backgroundLayer = mock(Layer.class);
|
||||
when(backgroundLayer.getId()).thenReturn(BACKGROUND_LAYER);
|
||||
when(layerSourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(backgroundLayer);
|
||||
|
||||
Layer foregroundLayer = mock(Layer.class);
|
||||
when(foregroundLayer.getId()).thenReturn(FOREGROUND_LAYER);
|
||||
when(layerSourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(foregroundLayer);
|
||||
|
||||
Layer bearingLayer = mock(Layer.class);
|
||||
when(bearingLayer.getId()).thenReturn(BEARING_LAYER);
|
||||
when(layerSourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer);
|
||||
|
||||
Layer accuracyLayer = mock(Layer.class);
|
||||
when(accuracyLayer.getId()).thenReturn(ACCURACY_LAYER);
|
||||
when(layerSourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer);
|
||||
Layer pulsingCircleLayer = mock(Layer.class);
|
||||
when(pulsingCircleLayer.getId()).thenReturn(PULSING_CIRCLE_LAYER);
|
||||
when(layerSourceProvider.generatePulsingCircleLayer()).thenReturn(pulsingCircleLayer);
|
||||
return layerSourceProvider;
|
||||
}
|
||||
|
||||
private <T> MapboxAnimator.AnimationsValueChangeListener<T> getAnimationListener(
|
||||
@MapboxAnimator.Type int animatorType,
|
||||
Set<AnimatorListenerHolder> holders) {
|
||||
for (AnimatorListenerHolder holder : holders) {
|
||||
@MapboxAnimator.Type int type = holder.getAnimatorType();
|
||||
if (type == animatorType) {
|
||||
return holder.getListener();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,28 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
public final class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void shortestRotation_doesReturnValueDistanceQuickestToZero() throws Exception {
|
||||
float value = Utils.shortestRotation(0, 181);
|
||||
assertEquals(360f, value);
|
||||
value = Utils.shortestRotation(0, 179);
|
||||
assertEquals(0f, value);
|
||||
value = Utils.shortestRotation(0, 180);
|
||||
assertEquals(0f, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortestRotation_doesReturnValueDistanceQuickestToFifty() throws Exception {
|
||||
float value = Utils.shortestRotation(50, 231);
|
||||
assertEquals(410f, value);
|
||||
value = Utils.shortestRotation(50, 229);
|
||||
assertEquals(50f, value);
|
||||
value = Utils.shortestRotation(50, 180);
|
||||
assertEquals(50f, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mapbox.mapboxsdk.location
|
||||
|
||||
import junit.framework.Assert
|
||||
import org.junit.Test
|
||||
|
||||
class UtilsTest {
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun shortestRotation_doesReturnValueDistanceQuickestToZero() {
|
||||
var value = Utils.shortestRotation(0f, 181f)
|
||||
Assert.assertEquals(360f, value)
|
||||
value = Utils.shortestRotation(0f, 179f)
|
||||
Assert.assertEquals(0f, value)
|
||||
value = Utils.shortestRotation(0f, 180f)
|
||||
Assert.assertEquals(0f, value)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun shortestRotation_doesReturnValueDistanceQuickestToFifty() {
|
||||
var value = Utils.shortestRotation(50f, 231f)
|
||||
Assert.assertEquals(410f, value)
|
||||
value = Utils.shortestRotation(50f, 229f)
|
||||
Assert.assertEquals(50f, value)
|
||||
value = Utils.shortestRotation(50f, 180f)
|
||||
Assert.assertEquals(50f, value)
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import androidx.collection.LongSparseArray;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Annotation;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class AnnotationManagerTest {
|
||||
|
||||
@Test
|
||||
public void checksAddAMarker() throws Exception {
|
||||
NativeMap aNativeMapView = mock(NativeMapView.class);
|
||||
MapView aMapView = mock(MapView.class);
|
||||
LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>();
|
||||
IconManager aIconManager = mock(IconManager.class);
|
||||
Annotations annotations = new AnnotationContainer(aNativeMapView, annotationsArray);
|
||||
Markers markers = new MarkerContainer(aNativeMapView, annotationsArray, aIconManager);
|
||||
Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray);
|
||||
Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray);
|
||||
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray);
|
||||
AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray,
|
||||
aIconManager, annotations, markers, polygons, polylines, shapeAnnotations);
|
||||
Marker aMarker = mock(Marker.class);
|
||||
long aId = 5L;
|
||||
when(aNativeMapView.addMarker(aMarker)).thenReturn(aId);
|
||||
BaseMarkerOptions aMarkerOptions = mock(BaseMarkerOptions.class);
|
||||
MapboxMap aMapboxMap = mock(MapboxMap.class);
|
||||
when(aMarkerOptions.getMarker()).thenReturn(aMarker);
|
||||
|
||||
annotationManager.addMarker(aMarkerOptions, aMapboxMap);
|
||||
|
||||
assertEquals(aMarker, annotationManager.getAnnotations().get(0));
|
||||
assertEquals(aMarker, annotationManager.getAnnotation(aId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checksAddMarkers() throws Exception {
|
||||
NativeMapView aNativeMapView = mock(NativeMapView.class);
|
||||
MapView aMapView = mock(MapView.class);
|
||||
LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>();
|
||||
IconManager aIconManager = mock(IconManager.class);
|
||||
Annotations annotations = new AnnotationContainer(aNativeMapView, annotationsArray);
|
||||
Markers markers = new MarkerContainer(aNativeMapView, annotationsArray, aIconManager);
|
||||
Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray);
|
||||
Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray);
|
||||
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray);
|
||||
AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray,
|
||||
aIconManager, annotations, markers, polygons, polylines, shapeAnnotations);
|
||||
|
||||
long firstId = 1L;
|
||||
long secondId = 2L;
|
||||
List<BaseMarkerOptions> markerList = new ArrayList<>();
|
||||
MarkerOptions firstMarkerOption = new MarkerOptions().position(new LatLng()).title("first");
|
||||
MarkerOptions secondMarkerOption = new MarkerOptions().position(new LatLng()).title("second");
|
||||
|
||||
markerList.add(firstMarkerOption);
|
||||
markerList.add(secondMarkerOption);
|
||||
MapboxMap aMapboxMap = mock(MapboxMap.class);
|
||||
when(aNativeMapView.addMarker(any(Marker.class))).thenReturn(firstId, secondId);
|
||||
|
||||
when(aNativeMapView.addMarkers(ArgumentMatchers.<Marker>anyList()))
|
||||
.thenReturn(new long[] {firstId, secondId});
|
||||
|
||||
annotationManager.addMarkers(markerList, aMapboxMap);
|
||||
|
||||
assertEquals(2, annotationManager.getAnnotations().size());
|
||||
assertEquals("first", ((Marker) annotationManager.getAnnotations().get(0)).getTitle());
|
||||
assertEquals("second", ((Marker) annotationManager.getAnnotations().get(1)).getTitle());
|
||||
assertEquals("first", ((Marker) annotationManager.getAnnotation(firstId)).getTitle());
|
||||
assertEquals("second", ((Marker) annotationManager.getAnnotation(secondId)).getTitle());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import androidx.collection.LongSparseArray
|
||||
import com.mapbox.mapboxsdk.annotations.Annotation
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions
|
||||
import com.mapbox.mapboxsdk.annotations.Marker
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import junit.framework.Assert
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mockito
|
||||
|
||||
class AnnotationManagerTest {
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checksAddAMarker() {
|
||||
val aNativeMapView: NativeMap = Mockito.mock(NativeMapView::class.java)
|
||||
val aMapView = Mockito.mock(MapView::class.java)
|
||||
val annotationsArray = LongSparseArray<Annotation>()
|
||||
val aIconManager = Mockito.mock(
|
||||
IconManager::class.java
|
||||
)
|
||||
val annotations: Annotations = AnnotationContainer(aNativeMapView, annotationsArray)
|
||||
val markers: Markers = MarkerContainer(aNativeMapView, annotationsArray, aIconManager)
|
||||
val polygons: Polygons = PolygonContainer(aNativeMapView, annotationsArray)
|
||||
val polylines: Polylines = PolylineContainer(aNativeMapView, annotationsArray)
|
||||
val shapeAnnotations: ShapeAnnotations =
|
||||
ShapeAnnotationContainer(aNativeMapView, annotationsArray)
|
||||
val annotationManager = AnnotationManager(
|
||||
aMapView,
|
||||
annotationsArray,
|
||||
aIconManager,
|
||||
annotations,
|
||||
markers,
|
||||
polygons,
|
||||
polylines,
|
||||
shapeAnnotations
|
||||
)
|
||||
val aMarker = Mockito.mock(
|
||||
Marker::class.java
|
||||
)
|
||||
val aId = 5L
|
||||
Mockito.`when`(aNativeMapView.addMarker(aMarker)).thenReturn(aId)
|
||||
val aMarkerOptions = Mockito.mock(
|
||||
BaseMarkerOptions::class.java
|
||||
)
|
||||
val aMapboxMap = Mockito.mock(MapboxMap::class.java)
|
||||
Mockito.`when`(aMarkerOptions.marker).thenReturn(aMarker)
|
||||
annotationManager.addMarker(aMarkerOptions, aMapboxMap)
|
||||
Assert.assertEquals(aMarker, annotationManager.annotations[0])
|
||||
Assert.assertEquals(aMarker, annotationManager.getAnnotation(aId))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checksAddMarkers() {
|
||||
val aNativeMapView = Mockito.mock(NativeMapView::class.java)
|
||||
val aMapView = Mockito.mock(MapView::class.java)
|
||||
val annotationsArray = LongSparseArray<Annotation>()
|
||||
val aIconManager = Mockito.mock(
|
||||
IconManager::class.java
|
||||
)
|
||||
val annotations: Annotations = AnnotationContainer(aNativeMapView, annotationsArray)
|
||||
val markers: Markers = MarkerContainer(aNativeMapView, annotationsArray, aIconManager)
|
||||
val polygons: Polygons = PolygonContainer(aNativeMapView, annotationsArray)
|
||||
val polylines: Polylines = PolylineContainer(aNativeMapView, annotationsArray)
|
||||
val shapeAnnotations: ShapeAnnotations =
|
||||
ShapeAnnotationContainer(aNativeMapView, annotationsArray)
|
||||
val annotationManager = AnnotationManager(
|
||||
aMapView,
|
||||
annotationsArray,
|
||||
aIconManager,
|
||||
annotations,
|
||||
markers,
|
||||
polygons,
|
||||
polylines,
|
||||
shapeAnnotations
|
||||
)
|
||||
val firstId = 1L
|
||||
val secondId = 2L
|
||||
val markerList: MutableList<BaseMarkerOptions<*, *>> = ArrayList()
|
||||
val firstMarkerOption = MarkerOptions().position(LatLng()).title("first")
|
||||
val secondMarkerOption = MarkerOptions().position(LatLng()).title("second")
|
||||
markerList.add(firstMarkerOption)
|
||||
markerList.add(secondMarkerOption)
|
||||
val aMapboxMap = Mockito.mock(MapboxMap::class.java)
|
||||
Mockito.`when`(
|
||||
aNativeMapView.addMarker(
|
||||
ArgumentMatchers.any(
|
||||
Marker::class.java
|
||||
)
|
||||
)
|
||||
).thenReturn(firstId, secondId)
|
||||
Mockito.`when`(aNativeMapView.addMarkers(ArgumentMatchers.anyList()))
|
||||
.thenReturn(longArrayOf(firstId, secondId))
|
||||
annotationManager.addMarkers(markerList, aMapboxMap)
|
||||
Assert.assertEquals(2, annotationManager.annotations.size)
|
||||
Assert.assertEquals("first", (annotationManager.annotations[0] as Marker).title)
|
||||
Assert.assertEquals("second", (annotationManager.annotations[1] as Marker).title)
|
||||
Assert.assertEquals("first", (annotationManager.getAnnotation(firstId) as Marker).title)
|
||||
Assert.assertEquals("second", (annotationManager.getAnnotation(secondId) as Marker).title)
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AttributionDialogManagerTest {
|
||||
@InjectMocks
|
||||
Context context = mock(Context.class);
|
||||
|
||||
@InjectMocks
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
|
||||
@InjectMocks
|
||||
Style style = mock(Style.class);
|
||||
|
||||
private AttributionDialogManager attributionDialogManager;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
attributionDialogManager = new AttributionDialogManager(context, mapboxMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("AttributionDialogManager should not be null", attributionDialogManager);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.content.Context
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mockito
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class AttributionDialogManagerTest {
|
||||
@InjectMocks
|
||||
var context = Mockito.mock(
|
||||
Context::class.java
|
||||
)
|
||||
|
||||
@InjectMocks
|
||||
var mapboxMap = Mockito.mock(MapboxMap::class.java)
|
||||
|
||||
@InjectMocks
|
||||
var style = Mockito.mock(
|
||||
Style::class.java
|
||||
)
|
||||
private var attributionDialogManager: AttributionDialogManager? = null
|
||||
|
||||
@Before
|
||||
fun beforeTest() {
|
||||
attributionDialogManager = AttributionDialogManager(context, mapboxMap)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSanity() {
|
||||
Assert.assertNotNull(
|
||||
"AttributionDialogManager should not be null",
|
||||
attributionDialogManager
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,586 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import com.google.common.util.concurrent.ExecutionError;
|
||||
import com.mapbox.mapboxsdk.log.Logger;
|
||||
import com.mapbox.mapboxsdk.log.LoggerDefinition;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests integration of MapChangeDispatcher and see if events are correctly forwarded.
|
||||
*/
|
||||
public class MapChangeReceiverTest {
|
||||
|
||||
private static final String TEST_STRING = "mapChangeRandom";
|
||||
|
||||
private MapChangeReceiver mapChangeEventManager;
|
||||
|
||||
@Mock
|
||||
private MapView.OnCameraWillChangeListener onCameraWillChangeListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnCameraDidChangeListener onCameraDidChangeListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnCameraIsChangingListener onCameraIsChangingListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnWillStartLoadingMapListener onWillStartLoadingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFinishLoadingMapListener onDidFinishLoadingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFailLoadingMapListener onDidFailLoadingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnWillStartRenderingFrameListener onWillStartRenderingFrameListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFinishRenderingFrameListener onDidFinishRenderingFrameListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnWillStartRenderingMapListener onWillStartRenderingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFinishRenderingMapListener onDidFinishRenderingMapListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidBecomeIdleListener onDidBecomeIdleListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnDidFinishLoadingStyleListener onDidFinishLoadingStyleListener;
|
||||
|
||||
@Mock
|
||||
private MapView.OnSourceChangedListener onSourceChangedListener;
|
||||
|
||||
@Mock
|
||||
private LoggerDefinition loggerDefinition;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mapChangeEventManager = new MapChangeReceiver();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraRegionWillChangeListener() {
|
||||
mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
mapChangeEventManager.onCameraWillChange(false);
|
||||
verify(onCameraWillChangeListener).onCameraWillChange(false);
|
||||
|
||||
mapChangeEventManager.removeOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
mapChangeEventManager.onCameraWillChange(false);
|
||||
verify(onCameraWillChangeListener).onCameraWillChange(false);
|
||||
|
||||
mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraWillChangeListener).onCameraWillChange(false);
|
||||
try {
|
||||
mapChangeEventManager.onCameraWillChange(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraWillChangeListener).onCameraWillChange(false);
|
||||
try {
|
||||
mapChangeEventManager.onCameraWillChange(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraRegionWillChangeAnimatedListener() {
|
||||
mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
mapChangeEventManager.onCameraWillChange(true);
|
||||
verify(onCameraWillChangeListener).onCameraWillChange(true);
|
||||
mapChangeEventManager.removeOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
mapChangeEventManager.onCameraWillChange(true);
|
||||
verify(onCameraWillChangeListener).onCameraWillChange(true);
|
||||
|
||||
mapChangeEventManager.addOnCameraWillChangeListener(onCameraWillChangeListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraWillChangeListener).onCameraWillChange(true);
|
||||
try {
|
||||
mapChangeEventManager.onCameraWillChange(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraWillChangeListener).onCameraWillChange(true);
|
||||
try {
|
||||
mapChangeEventManager.onCameraWillChange(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraIsChangingListener() {
|
||||
mapChangeEventManager.addOnCameraIsChangingListener(onCameraIsChangingListener);
|
||||
mapChangeEventManager.onCameraIsChanging();
|
||||
verify(onCameraIsChangingListener).onCameraIsChanging();
|
||||
mapChangeEventManager.removeOnCameraIsChangingListener(onCameraIsChangingListener);
|
||||
mapChangeEventManager.onCameraIsChanging();
|
||||
verify(onCameraIsChangingListener).onCameraIsChanging();
|
||||
|
||||
mapChangeEventManager.addOnCameraIsChangingListener(onCameraIsChangingListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraIsChangingListener).onCameraIsChanging();
|
||||
try {
|
||||
mapChangeEventManager.onCameraIsChanging();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraIsChangingListener).onCameraIsChanging();
|
||||
try {
|
||||
mapChangeEventManager.onCameraIsChanging();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraRegionDidChangeListener() {
|
||||
mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
mapChangeEventManager.onCameraDidChange(false);
|
||||
verify(onCameraDidChangeListener).onCameraDidChange(false);
|
||||
mapChangeEventManager.removeOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
mapChangeEventManager.onCameraDidChange(false);
|
||||
verify(onCameraDidChangeListener).onCameraDidChange(false);
|
||||
|
||||
mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraDidChangeListener).onCameraDidChange(false);
|
||||
try {
|
||||
mapChangeEventManager.onCameraDidChange(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraDidChangeListener).onCameraDidChange(false);
|
||||
try {
|
||||
mapChangeEventManager.onCameraDidChange(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCameraRegionDidChangeAnimatedListener() {
|
||||
mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
mapChangeEventManager.onCameraDidChange(true);
|
||||
verify(onCameraDidChangeListener).onCameraDidChange(true);
|
||||
mapChangeEventManager.removeOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
mapChangeEventManager.onCameraDidChange(true);
|
||||
verify(onCameraDidChangeListener).onCameraDidChange(true);
|
||||
|
||||
mapChangeEventManager.addOnCameraDidChangeListener(onCameraDidChangeListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onCameraDidChangeListener).onCameraDidChange(true);
|
||||
try {
|
||||
mapChangeEventManager.onCameraDidChange(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onCameraDidChangeListener).onCameraDidChange(true);
|
||||
try {
|
||||
mapChangeEventManager.onCameraDidChange(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnWillStartLoadingMapListener() {
|
||||
mapChangeEventManager.addOnWillStartLoadingMapListener(onWillStartLoadingMapListener);
|
||||
mapChangeEventManager.onWillStartLoadingMap();
|
||||
verify(onWillStartLoadingMapListener).onWillStartLoadingMap();
|
||||
mapChangeEventManager.removeOnWillStartLoadingMapListener(onWillStartLoadingMapListener);
|
||||
mapChangeEventManager.onWillStartLoadingMap();
|
||||
verify(onWillStartLoadingMapListener).onWillStartLoadingMap();
|
||||
|
||||
mapChangeEventManager.addOnWillStartLoadingMapListener(onWillStartLoadingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onWillStartLoadingMapListener).onWillStartLoadingMap();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartLoadingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onWillStartLoadingMapListener).onWillStartLoadingMap();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartLoadingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishLoadingMapListener() {
|
||||
mapChangeEventManager.addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener);
|
||||
mapChangeEventManager.onDidFinishLoadingMap();
|
||||
verify(onDidFinishLoadingMapListener).onDidFinishLoadingMap();
|
||||
mapChangeEventManager.removeOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener);
|
||||
mapChangeEventManager.onDidFinishLoadingMap();
|
||||
verify(onDidFinishLoadingMapListener).onDidFinishLoadingMap();
|
||||
|
||||
mapChangeEventManager.addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishLoadingMapListener).onDidFinishLoadingMap();
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishLoadingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishLoadingMapListener).onDidFinishLoadingMap();
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishLoadingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFailLoadingMapListener() {
|
||||
mapChangeEventManager.addOnDidFailLoadingMapListener(onDidFailLoadingMapListener);
|
||||
mapChangeEventManager.onDidFailLoadingMap(TEST_STRING);
|
||||
verify(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING);
|
||||
mapChangeEventManager.removeOnDidFailLoadingMapListener(onDidFailLoadingMapListener);
|
||||
mapChangeEventManager.onDidFailLoadingMap(TEST_STRING);
|
||||
verify(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING);
|
||||
|
||||
mapChangeEventManager.addOnDidFailLoadingMapListener(onDidFailLoadingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING);
|
||||
try {
|
||||
mapChangeEventManager.onDidFailLoadingMap(TEST_STRING);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFailLoadingMapListener).onDidFailLoadingMap(TEST_STRING);
|
||||
try {
|
||||
mapChangeEventManager.onDidFailLoadingMap(TEST_STRING);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnWillStartRenderingFrameListener() {
|
||||
mapChangeEventManager.addOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener);
|
||||
mapChangeEventManager.onWillStartRenderingFrame();
|
||||
verify(onWillStartRenderingFrameListener).onWillStartRenderingFrame();
|
||||
mapChangeEventManager.removeOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener);
|
||||
mapChangeEventManager.onWillStartRenderingFrame();
|
||||
verify(onWillStartRenderingFrameListener).onWillStartRenderingFrame();
|
||||
|
||||
mapChangeEventManager.addOnWillStartRenderingFrameListener(onWillStartRenderingFrameListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onWillStartRenderingFrameListener).onWillStartRenderingFrame();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartRenderingFrame();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onWillStartRenderingFrameListener).onWillStartRenderingFrame();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartRenderingFrame();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishRenderingFrameListener() {
|
||||
mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(true);
|
||||
verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true);
|
||||
mapChangeEventManager.removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(true);
|
||||
verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true);
|
||||
|
||||
mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(true);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishRenderingFrameFullyRenderedListener() {
|
||||
mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(false);
|
||||
verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false);
|
||||
mapChangeEventManager.removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(false);
|
||||
verify(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false);
|
||||
|
||||
mapChangeEventManager.addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishRenderingFrameListener).onDidFinishRenderingFrame(false);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingFrame(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnWillStartRenderingMapListener() {
|
||||
mapChangeEventManager.addOnWillStartRenderingMapListener(onWillStartRenderingMapListener);
|
||||
mapChangeEventManager.onWillStartRenderingMap();
|
||||
verify(onWillStartRenderingMapListener).onWillStartRenderingMap();
|
||||
mapChangeEventManager.removeOnWillStartRenderingMapListener(onWillStartRenderingMapListener);
|
||||
mapChangeEventManager.onWillStartRenderingMap();
|
||||
verify(onWillStartRenderingMapListener).onWillStartRenderingMap();
|
||||
|
||||
mapChangeEventManager.addOnWillStartRenderingMapListener(onWillStartRenderingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onWillStartRenderingMapListener).onWillStartRenderingMap();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartRenderingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onWillStartRenderingMapListener).onWillStartRenderingMap();
|
||||
try {
|
||||
mapChangeEventManager.onWillStartRenderingMap();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishRenderingMapListener() {
|
||||
mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
mapChangeEventManager.onDidFinishRenderingMap(true);
|
||||
verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true);
|
||||
mapChangeEventManager.removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
mapChangeEventManager.onDidFinishRenderingMap(true);
|
||||
verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true);
|
||||
|
||||
mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingMap(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(true);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingMap(true);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishRenderingMapFullyRenderedListener() {
|
||||
mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
mapChangeEventManager.onDidFinishRenderingMap(false);
|
||||
verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false);
|
||||
mapChangeEventManager.removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
mapChangeEventManager.onDidFinishRenderingMap(false);
|
||||
verify(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false);
|
||||
|
||||
mapChangeEventManager.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingMap(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishRenderingMapListener).onDidFinishRenderingMap(false);
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishRenderingMap(false);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidBecomeIdleListener() {
|
||||
mapChangeEventManager.addOnDidBecomeIdleListener(onDidBecomeIdleListener);
|
||||
mapChangeEventManager.onDidBecomeIdle();
|
||||
verify(onDidBecomeIdleListener).onDidBecomeIdle();
|
||||
mapChangeEventManager.removeOnDidBecomeIdleListener(onDidBecomeIdleListener);
|
||||
mapChangeEventManager.onDidBecomeIdle();
|
||||
verify(onDidBecomeIdleListener).onDidBecomeIdle();
|
||||
|
||||
mapChangeEventManager.addOnDidBecomeIdleListener(onDidBecomeIdleListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidBecomeIdleListener).onDidBecomeIdle();
|
||||
try {
|
||||
mapChangeEventManager.onDidBecomeIdle();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidBecomeIdleListener).onDidBecomeIdle();
|
||||
try {
|
||||
mapChangeEventManager.onDidBecomeIdle();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnDidFinishLoadingStyleListener() {
|
||||
mapChangeEventManager.addOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener);
|
||||
mapChangeEventManager.onDidFinishLoadingStyle();
|
||||
verify(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle();
|
||||
mapChangeEventManager.removeOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener);
|
||||
mapChangeEventManager.onDidFinishLoadingStyle();
|
||||
verify(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle();
|
||||
|
||||
mapChangeEventManager.addOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle();
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishLoadingStyle();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onDidFinishLoadingStyleListener).onDidFinishLoadingStyle();
|
||||
try {
|
||||
mapChangeEventManager.onDidFinishLoadingStyle();
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnSourceChangedListener() {
|
||||
mapChangeEventManager.addOnSourceChangedListener(onSourceChangedListener);
|
||||
mapChangeEventManager.onSourceChanged(TEST_STRING);
|
||||
verify(onSourceChangedListener).onSourceChangedListener(TEST_STRING);
|
||||
mapChangeEventManager.removeOnSourceChangedListener(onSourceChangedListener);
|
||||
mapChangeEventManager.onSourceChanged(TEST_STRING);
|
||||
verify(onSourceChangedListener).onSourceChangedListener(TEST_STRING);
|
||||
|
||||
mapChangeEventManager.addOnSourceChangedListener(onSourceChangedListener);
|
||||
Logger.setLoggerDefinition(loggerDefinition);
|
||||
Exception exc = new RuntimeException();
|
||||
doThrow(exc).when(onSourceChangedListener).onSourceChangedListener(TEST_STRING);
|
||||
try {
|
||||
mapChangeEventManager.onSourceChanged(TEST_STRING);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (RuntimeException throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(exc));
|
||||
}
|
||||
|
||||
Error err = new ExecutionError("", new Error());
|
||||
doThrow(err).when(onSourceChangedListener).onSourceChangedListener(TEST_STRING);
|
||||
try {
|
||||
mapChangeEventManager.onSourceChanged(TEST_STRING);
|
||||
Assert.fail("The exception should've been re-thrown.");
|
||||
} catch (ExecutionError throwable) {
|
||||
verify(loggerDefinition).e(anyString(), anyString(), eq(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,714 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import com.google.common.util.concurrent.ExecutionError
|
||||
import com.mapbox.mapboxsdk.log.Logger
|
||||
import com.mapbox.mapboxsdk.log.LoggerDefinition
|
||||
import com.mapbox.mapboxsdk.maps.MapView.*
|
||||
import junit.framework.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
/**
|
||||
* Tests integration of MapChangeDispatcher and see if events are correctly forwarded.
|
||||
*/
|
||||
class MapChangeReceiverTest {
|
||||
private var mapChangeEventManager: MapChangeReceiver? = null
|
||||
|
||||
@Mock
|
||||
private val onCameraWillChangeListener: OnCameraWillChangeListener? = null
|
||||
|
||||
@Mock
|
||||
private val onCameraDidChangeListener: OnCameraDidChangeListener? = null
|
||||
|
||||
@Mock
|
||||
private val onCameraIsChangingListener: OnCameraIsChangingListener? = null
|
||||
|
||||
@Mock
|
||||
private val onWillStartLoadingMapListener: OnWillStartLoadingMapListener? = null
|
||||
|
||||
@Mock
|
||||
private val onDidFinishLoadingMapListener: OnDidFinishLoadingMapListener? = null
|
||||
|
||||
@Mock
|
||||
private val onDidFailLoadingMapListener: OnDidFailLoadingMapListener? = null
|
||||
|
||||
@Mock
|
||||
private val onWillStartRenderingFrameListener: OnWillStartRenderingFrameListener? = null
|
||||
|
||||
@Mock
|
||||
private val onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener? = null
|
||||
|
||||
@Mock
|
||||
private val onWillStartRenderingMapListener: OnWillStartRenderingMapListener? = null
|
||||
|
||||
@Mock
|
||||
private val onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener? = null
|
||||
|
||||
@Mock
|
||||
private val onDidBecomeIdleListener: OnDidBecomeIdleListener? = null
|
||||
|
||||
@Mock
|
||||
private val onDidFinishLoadingStyleListener: OnDidFinishLoadingStyleListener? = null
|
||||
|
||||
@Mock
|
||||
private val onSourceChangedListener: OnSourceChangedListener? = null
|
||||
|
||||
@Mock
|
||||
private val loggerDefinition: LoggerDefinition? = null
|
||||
|
||||
@Before
|
||||
fun beforeTest() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
mapChangeEventManager = MapChangeReceiver()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnCameraRegionWillChangeListener() {
|
||||
mapChangeEventManager!!.addOnCameraWillChangeListener(onCameraWillChangeListener)
|
||||
mapChangeEventManager!!?.onCameraWillChange(false)
|
||||
Mockito.verify(onCameraWillChangeListener)?.onCameraWillChange(false)
|
||||
mapChangeEventManager!!.removeOnCameraWillChangeListener(onCameraWillChangeListener)
|
||||
mapChangeEventManager!!?.onCameraWillChange(false)
|
||||
Mockito.verify(onCameraWillChangeListener)?.onCameraWillChange(false)
|
||||
mapChangeEventManager!!.addOnCameraWillChangeListener(onCameraWillChangeListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onCameraWillChangeListener)?.onCameraWillChange(false)
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraWillChange(false)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onCameraWillChangeListener)?.onCameraWillChange(false)
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraWillChange(false)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnCameraRegionWillChangeAnimatedListener() {
|
||||
mapChangeEventManager!!.addOnCameraWillChangeListener(onCameraWillChangeListener)
|
||||
mapChangeEventManager!!?.onCameraWillChange(true)
|
||||
Mockito.verify(onCameraWillChangeListener)?.onCameraWillChange(true)
|
||||
mapChangeEventManager!!.removeOnCameraWillChangeListener(onCameraWillChangeListener)
|
||||
mapChangeEventManager!!?.onCameraWillChange(true)
|
||||
Mockito.verify(onCameraWillChangeListener)?.onCameraWillChange(true)
|
||||
mapChangeEventManager!!.addOnCameraWillChangeListener(onCameraWillChangeListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onCameraWillChangeListener)?.onCameraWillChange(true)
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraWillChange(true)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onCameraWillChangeListener)?.onCameraWillChange(true)
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraWillChange(true)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnCameraIsChangingListener() {
|
||||
mapChangeEventManager!!.addOnCameraIsChangingListener(onCameraIsChangingListener)
|
||||
mapChangeEventManager!!?.onCameraIsChanging()
|
||||
Mockito.verify(onCameraIsChangingListener)?.onCameraIsChanging()
|
||||
mapChangeEventManager!!.removeOnCameraIsChangingListener(onCameraIsChangingListener)
|
||||
mapChangeEventManager!!?.onCameraIsChanging()
|
||||
Mockito.verify(onCameraIsChangingListener)?.onCameraIsChanging()
|
||||
mapChangeEventManager!!.addOnCameraIsChangingListener(onCameraIsChangingListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onCameraIsChangingListener)?.onCameraIsChanging()
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraIsChanging()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onCameraIsChangingListener)?.onCameraIsChanging()
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraIsChanging()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnCameraRegionDidChangeListener() {
|
||||
mapChangeEventManager!!.addOnCameraDidChangeListener(onCameraDidChangeListener)
|
||||
mapChangeEventManager!!?.onCameraDidChange(false)
|
||||
Mockito.verify(onCameraDidChangeListener)?.onCameraDidChange(false)
|
||||
mapChangeEventManager!!.removeOnCameraDidChangeListener(onCameraDidChangeListener)
|
||||
mapChangeEventManager!!?.onCameraDidChange(false)
|
||||
Mockito.verify(onCameraDidChangeListener)?.onCameraDidChange(false)
|
||||
mapChangeEventManager!!.addOnCameraDidChangeListener(onCameraDidChangeListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onCameraDidChangeListener)?.onCameraDidChange(false)
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraDidChange(false)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onCameraDidChangeListener)?.onCameraDidChange(false)
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraDidChange(false)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnCameraRegionDidChangeAnimatedListener() {
|
||||
mapChangeEventManager!!.addOnCameraDidChangeListener(onCameraDidChangeListener)
|
||||
mapChangeEventManager!!?.onCameraDidChange(true)
|
||||
Mockito.verify(onCameraDidChangeListener)?.onCameraDidChange(true)
|
||||
mapChangeEventManager!!.removeOnCameraDidChangeListener(onCameraDidChangeListener)
|
||||
mapChangeEventManager!!?.onCameraDidChange(true)
|
||||
Mockito.verify(onCameraDidChangeListener)?.onCameraDidChange(true)
|
||||
mapChangeEventManager!!.addOnCameraDidChangeListener(onCameraDidChangeListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onCameraDidChangeListener)?.onCameraDidChange(true)
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraDidChange(true)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onCameraDidChangeListener)?.onCameraDidChange(true)
|
||||
try {
|
||||
mapChangeEventManager!!?.onCameraDidChange(true)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnWillStartLoadingMapListener() {
|
||||
mapChangeEventManager!!.addOnWillStartLoadingMapListener(onWillStartLoadingMapListener)
|
||||
mapChangeEventManager!!?.onWillStartLoadingMap()
|
||||
Mockito.verify(onWillStartLoadingMapListener)?.onWillStartLoadingMap()
|
||||
mapChangeEventManager!!.removeOnWillStartLoadingMapListener(onWillStartLoadingMapListener)
|
||||
mapChangeEventManager!!?.onWillStartLoadingMap()
|
||||
Mockito.verify(onWillStartLoadingMapListener)?.onWillStartLoadingMap()
|
||||
mapChangeEventManager!!.addOnWillStartLoadingMapListener(onWillStartLoadingMapListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onWillStartLoadingMapListener)?.onWillStartLoadingMap()
|
||||
try {
|
||||
mapChangeEventManager!!?.onWillStartLoadingMap()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onWillStartLoadingMapListener)?.onWillStartLoadingMap()
|
||||
try {
|
||||
mapChangeEventManager!!?.onWillStartLoadingMap()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnDidFinishLoadingMapListener() {
|
||||
mapChangeEventManager!!.addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener)
|
||||
mapChangeEventManager!!?.onDidFinishLoadingMap()
|
||||
Mockito.verify(onDidFinishLoadingMapListener)?.onDidFinishLoadingMap()
|
||||
mapChangeEventManager!!.removeOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener)
|
||||
mapChangeEventManager!!?.onDidFinishLoadingMap()
|
||||
Mockito.verify(onDidFinishLoadingMapListener)?.onDidFinishLoadingMap()
|
||||
mapChangeEventManager!!.addOnDidFinishLoadingMapListener(onDidFinishLoadingMapListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onDidFinishLoadingMapListener)?.onDidFinishLoadingMap()
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishLoadingMap()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onDidFinishLoadingMapListener)?.onDidFinishLoadingMap()
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishLoadingMap()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnDidFailLoadingMapListener() {
|
||||
mapChangeEventManager!!.addOnDidFailLoadingMapListener(onDidFailLoadingMapListener)
|
||||
mapChangeEventManager!!?.onDidFailLoadingMap(TEST_STRING)
|
||||
Mockito.verify(onDidFailLoadingMapListener)?.onDidFailLoadingMap(TEST_STRING)
|
||||
mapChangeEventManager!!.removeOnDidFailLoadingMapListener(onDidFailLoadingMapListener)
|
||||
mapChangeEventManager!!?.onDidFailLoadingMap(TEST_STRING)
|
||||
Mockito.verify(onDidFailLoadingMapListener)?.onDidFailLoadingMap(TEST_STRING)
|
||||
mapChangeEventManager!!.addOnDidFailLoadingMapListener(onDidFailLoadingMapListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onDidFailLoadingMapListener)?.onDidFailLoadingMap(TEST_STRING)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFailLoadingMap(TEST_STRING)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onDidFailLoadingMapListener)?.onDidFailLoadingMap(TEST_STRING)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFailLoadingMap(TEST_STRING)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnWillStartRenderingFrameListener() {
|
||||
mapChangeEventManager!!.addOnWillStartRenderingFrameListener(
|
||||
onWillStartRenderingFrameListener
|
||||
)
|
||||
mapChangeEventManager!!?.onWillStartRenderingFrame()
|
||||
Mockito.verify(onWillStartRenderingFrameListener)?.onWillStartRenderingFrame()
|
||||
mapChangeEventManager!!.removeOnWillStartRenderingFrameListener(
|
||||
onWillStartRenderingFrameListener
|
||||
)
|
||||
mapChangeEventManager!!?.onWillStartRenderingFrame()
|
||||
Mockito.verify(onWillStartRenderingFrameListener)?.onWillStartRenderingFrame()
|
||||
mapChangeEventManager!!.addOnWillStartRenderingFrameListener(
|
||||
onWillStartRenderingFrameListener
|
||||
)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onWillStartRenderingFrameListener)?.onWillStartRenderingFrame()
|
||||
try {
|
||||
mapChangeEventManager!!?.onWillStartRenderingFrame()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onWillStartRenderingFrameListener)?.onWillStartRenderingFrame()
|
||||
try {
|
||||
mapChangeEventManager!!?.onWillStartRenderingFrame()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnDidFinishRenderingFrameListener() {
|
||||
mapChangeEventManager!!.addOnDidFinishRenderingFrameListener(
|
||||
onDidFinishRenderingFrameListener
|
||||
)
|
||||
mapChangeEventManager!!?.onDidFinishRenderingFrame(true)
|
||||
Mockito.verify(onDidFinishRenderingFrameListener)?.onDidFinishRenderingFrame(true)
|
||||
mapChangeEventManager!!.removeOnDidFinishRenderingFrameListener(
|
||||
onDidFinishRenderingFrameListener
|
||||
)
|
||||
mapChangeEventManager!!?.onDidFinishRenderingFrame(true)
|
||||
Mockito.verify(onDidFinishRenderingFrameListener)?.onDidFinishRenderingFrame(true)
|
||||
mapChangeEventManager!!.addOnDidFinishRenderingFrameListener(
|
||||
onDidFinishRenderingFrameListener
|
||||
)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onDidFinishRenderingFrameListener)
|
||||
?.onDidFinishRenderingFrame(true)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishRenderingFrame(true)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onDidFinishRenderingFrameListener)
|
||||
?.onDidFinishRenderingFrame(true)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishRenderingFrame(true)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnDidFinishRenderingFrameFullyRenderedListener() {
|
||||
mapChangeEventManager!!.addOnDidFinishRenderingFrameListener(
|
||||
onDidFinishRenderingFrameListener
|
||||
)
|
||||
mapChangeEventManager!!?.onDidFinishRenderingFrame(false)
|
||||
Mockito.verify(onDidFinishRenderingFrameListener)?.onDidFinishRenderingFrame(false)
|
||||
mapChangeEventManager!!.removeOnDidFinishRenderingFrameListener(
|
||||
onDidFinishRenderingFrameListener
|
||||
)
|
||||
mapChangeEventManager!!?.onDidFinishRenderingFrame(false)
|
||||
Mockito.verify(onDidFinishRenderingFrameListener)?.onDidFinishRenderingFrame(false)
|
||||
mapChangeEventManager!!.addOnDidFinishRenderingFrameListener(
|
||||
onDidFinishRenderingFrameListener
|
||||
)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onDidFinishRenderingFrameListener)
|
||||
?.onDidFinishRenderingFrame(false)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishRenderingFrame(false)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onDidFinishRenderingFrameListener)
|
||||
?.onDidFinishRenderingFrame(false)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishRenderingFrame(false)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnWillStartRenderingMapListener() {
|
||||
mapChangeEventManager!!.addOnWillStartRenderingMapListener(onWillStartRenderingMapListener)
|
||||
mapChangeEventManager!!?.onWillStartRenderingMap()
|
||||
Mockito.verify(onWillStartRenderingMapListener)?.onWillStartRenderingMap()
|
||||
mapChangeEventManager!!.removeOnWillStartRenderingMapListener(
|
||||
onWillStartRenderingMapListener
|
||||
)
|
||||
mapChangeEventManager!!?.onWillStartRenderingMap()
|
||||
Mockito.verify(onWillStartRenderingMapListener)?.onWillStartRenderingMap()
|
||||
mapChangeEventManager!!.addOnWillStartRenderingMapListener(onWillStartRenderingMapListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onWillStartRenderingMapListener)?.onWillStartRenderingMap()
|
||||
try {
|
||||
mapChangeEventManager!!?.onWillStartRenderingMap()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onWillStartRenderingMapListener)?.onWillStartRenderingMap()
|
||||
try {
|
||||
mapChangeEventManager!!?.onWillStartRenderingMap()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnDidFinishRenderingMapListener() {
|
||||
mapChangeEventManager!!.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener)
|
||||
mapChangeEventManager!!?.onDidFinishRenderingMap(true)
|
||||
Mockito.verify(onDidFinishRenderingMapListener)?.onDidFinishRenderingMap(true)
|
||||
mapChangeEventManager!!.removeOnDidFinishRenderingMapListener(
|
||||
onDidFinishRenderingMapListener
|
||||
)
|
||||
mapChangeEventManager!!?.onDidFinishRenderingMap(true)
|
||||
Mockito.verify(onDidFinishRenderingMapListener)?.onDidFinishRenderingMap(true)
|
||||
mapChangeEventManager!!.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onDidFinishRenderingMapListener)?.onDidFinishRenderingMap(true)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishRenderingMap(true)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onDidFinishRenderingMapListener)?.onDidFinishRenderingMap(true)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishRenderingMap(true)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnDidFinishRenderingMapFullyRenderedListener() {
|
||||
mapChangeEventManager!!.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener)
|
||||
mapChangeEventManager!!?.onDidFinishRenderingMap(false)
|
||||
Mockito.verify(onDidFinishRenderingMapListener)?.onDidFinishRenderingMap(false)
|
||||
mapChangeEventManager!!.removeOnDidFinishRenderingMapListener(
|
||||
onDidFinishRenderingMapListener
|
||||
)
|
||||
mapChangeEventManager!!?.onDidFinishRenderingMap(false)
|
||||
Mockito.verify(onDidFinishRenderingMapListener)?.onDidFinishRenderingMap(false)
|
||||
mapChangeEventManager!!.addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onDidFinishRenderingMapListener)?.onDidFinishRenderingMap(false)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishRenderingMap(false)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onDidFinishRenderingMapListener)?.onDidFinishRenderingMap(false)
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishRenderingMap(false)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnDidBecomeIdleListener() {
|
||||
mapChangeEventManager!!.addOnDidBecomeIdleListener(onDidBecomeIdleListener)
|
||||
mapChangeEventManager!!?.onDidBecomeIdle()
|
||||
Mockito.verify(onDidBecomeIdleListener)?.onDidBecomeIdle()
|
||||
mapChangeEventManager!!.removeOnDidBecomeIdleListener(onDidBecomeIdleListener)
|
||||
mapChangeEventManager!!?.onDidBecomeIdle()
|
||||
Mockito.verify(onDidBecomeIdleListener)?.onDidBecomeIdle()
|
||||
mapChangeEventManager!!.addOnDidBecomeIdleListener(onDidBecomeIdleListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onDidBecomeIdleListener)?.onDidBecomeIdle()
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidBecomeIdle()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onDidBecomeIdleListener)?.onDidBecomeIdle()
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidBecomeIdle()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnDidFinishLoadingStyleListener() {
|
||||
mapChangeEventManager!!.addOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener)
|
||||
mapChangeEventManager!!?.onDidFinishLoadingStyle()
|
||||
Mockito.verify(onDidFinishLoadingStyleListener)?.onDidFinishLoadingStyle()
|
||||
mapChangeEventManager!!.removeOnDidFinishLoadingStyleListener(
|
||||
onDidFinishLoadingStyleListener
|
||||
)
|
||||
mapChangeEventManager!!?.onDidFinishLoadingStyle()
|
||||
Mockito.verify(onDidFinishLoadingStyleListener)?.onDidFinishLoadingStyle()
|
||||
mapChangeEventManager!!.addOnDidFinishLoadingStyleListener(onDidFinishLoadingStyleListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onDidFinishLoadingStyleListener)?.onDidFinishLoadingStyle()
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishLoadingStyle()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onDidFinishLoadingStyleListener)?.onDidFinishLoadingStyle()
|
||||
try {
|
||||
mapChangeEventManager!!?.onDidFinishLoadingStyle()
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOnSourceChangedListener() {
|
||||
mapChangeEventManager!!.addOnSourceChangedListener(onSourceChangedListener)
|
||||
mapChangeEventManager!!?.onSourceChanged(TEST_STRING)
|
||||
Mockito.verify(onSourceChangedListener)?.onSourceChangedListener(TEST_STRING)
|
||||
mapChangeEventManager!!.removeOnSourceChangedListener(onSourceChangedListener)
|
||||
mapChangeEventManager!!?.onSourceChanged(TEST_STRING)
|
||||
Mockito.verify(onSourceChangedListener)?.onSourceChangedListener(TEST_STRING)
|
||||
mapChangeEventManager!!.addOnSourceChangedListener(onSourceChangedListener)
|
||||
Logger.setLoggerDefinition(loggerDefinition)
|
||||
val exc: Exception = RuntimeException()
|
||||
Mockito.doThrow(exc).`when`(onSourceChangedListener)?.onSourceChangedListener(TEST_STRING)
|
||||
try {
|
||||
mapChangeEventManager!!?.onSourceChanged(TEST_STRING)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: RuntimeException) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(exc)
|
||||
)
|
||||
}
|
||||
val err: Error = ExecutionError("", Error())
|
||||
Mockito.doThrow(err).`when`(onSourceChangedListener)?.onSourceChangedListener(TEST_STRING)
|
||||
try {
|
||||
mapChangeEventManager!!?.onSourceChanged(TEST_STRING)
|
||||
Assert.fail("The exception should've been re-thrown.")
|
||||
} catch (throwable: ExecutionError) {
|
||||
Mockito.verify(loggerDefinition)?.e(
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.anyString(),
|
||||
ArgumentMatchers.eq(err)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TEST_STRING = "mapChangeRandom"
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.graphics.PointF;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mapbox.android.gestures.MoveGestureDetector;
|
||||
import com.mapbox.android.gestures.RotateGestureDetector;
|
||||
import com.mapbox.android.gestures.ShoveGestureDetector;
|
||||
import com.mapbox.android.gestures.StandardScaleGestureDetector;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Before;
|
||||
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 {
|
||||
|
||||
@Nullable
|
||||
private MapGestureDetector mapGestureDetector;
|
||||
private LatLng latLng;
|
||||
private PointF pointF;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
latLng = new LatLng();
|
||||
pointF = new PointF();
|
||||
|
||||
Projection projection = mock(Projection.class);
|
||||
when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
|
||||
mapGestureDetector = new MapGestureDetector(null,
|
||||
null, projection, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onMapClickListenerTest() throws Exception {
|
||||
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 {
|
||||
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 {
|
||||
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 onMoveListenerTest() throws Exception {
|
||||
MapboxMap.OnMoveListener listener = mock(MapboxMap.OnMoveListener.class);
|
||||
MoveGestureDetector detector = mock(MoveGestureDetector.class);
|
||||
mapGestureDetector.addOnMoveListener(listener);
|
||||
mapGestureDetector.notifyOnMoveBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnMoveListeners(detector);
|
||||
mapGestureDetector.notifyOnMoveEndListeners(detector);
|
||||
verify(listener, times(1)).onMoveBegin(detector);
|
||||
verify(listener, times(1)).onMove(detector);
|
||||
verify(listener, times(1)).onMoveEnd(detector);
|
||||
|
||||
mapGestureDetector.removeOnMoveListener(listener);
|
||||
mapGestureDetector.notifyOnMoveBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnMoveListeners(detector);
|
||||
mapGestureDetector.notifyOnMoveEndListeners(detector);
|
||||
verify(listener, times(1)).onMoveBegin(detector);
|
||||
verify(listener, times(1)).onMove(detector);
|
||||
verify(listener, times(1)).onMoveEnd(detector);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onRotateListenerTest() throws Exception {
|
||||
MapboxMap.OnRotateListener listener = mock(MapboxMap.OnRotateListener.class);
|
||||
RotateGestureDetector detector = mock(RotateGestureDetector.class);
|
||||
mapGestureDetector.addOnRotateListener(listener);
|
||||
mapGestureDetector.notifyOnRotateBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnRotateListeners(detector);
|
||||
mapGestureDetector.notifyOnRotateEndListeners(detector);
|
||||
verify(listener, times(1)).onRotateBegin(detector);
|
||||
verify(listener, times(1)).onRotate(detector);
|
||||
verify(listener, times(1)).onRotateEnd(detector);
|
||||
|
||||
mapGestureDetector.removeOnRotateListener(listener);
|
||||
mapGestureDetector.notifyOnRotateBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnRotateListeners(detector);
|
||||
mapGestureDetector.notifyOnRotateEndListeners(detector);
|
||||
verify(listener, times(1)).onRotateBegin(detector);
|
||||
verify(listener, times(1)).onRotate(detector);
|
||||
verify(listener, times(1)).onRotateEnd(detector);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onScaleListenerTest() throws Exception {
|
||||
MapboxMap.OnScaleListener listener = mock(MapboxMap.OnScaleListener.class);
|
||||
StandardScaleGestureDetector detector = mock(StandardScaleGestureDetector.class);
|
||||
mapGestureDetector.addOnScaleListener(listener);
|
||||
mapGestureDetector.notifyOnScaleBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnScaleListeners(detector);
|
||||
mapGestureDetector.notifyOnScaleEndListeners(detector);
|
||||
verify(listener, times(1)).onScaleBegin(detector);
|
||||
verify(listener, times(1)).onScale(detector);
|
||||
verify(listener, times(1)).onScaleEnd(detector);
|
||||
|
||||
mapGestureDetector.removeOnScaleListener(listener);
|
||||
mapGestureDetector.notifyOnScaleBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnScaleListeners(detector);
|
||||
mapGestureDetector.notifyOnScaleEndListeners(detector);
|
||||
verify(listener, times(1)).onScaleBegin(detector);
|
||||
verify(listener, times(1)).onScale(detector);
|
||||
verify(listener, times(1)).onScaleEnd(detector);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onShoveListenerTest() throws Exception {
|
||||
MapboxMap.OnShoveListener listener = mock(MapboxMap.OnShoveListener.class);
|
||||
ShoveGestureDetector detector = mock(ShoveGestureDetector.class);
|
||||
mapGestureDetector.addShoveListener(listener);
|
||||
mapGestureDetector.notifyOnShoveBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnShoveListeners(detector);
|
||||
mapGestureDetector.notifyOnShoveEndListeners(detector);
|
||||
verify(listener, times(1)).onShoveBegin(detector);
|
||||
verify(listener, times(1)).onShove(detector);
|
||||
verify(listener, times(1)).onShoveEnd(detector);
|
||||
|
||||
mapGestureDetector.removeShoveListener(listener);
|
||||
mapGestureDetector.notifyOnShoveBeginListeners(detector);
|
||||
mapGestureDetector.notifyOnShoveListeners(detector);
|
||||
mapGestureDetector.notifyOnShoveEndListeners(detector);
|
||||
verify(listener, times(1)).onShoveBegin(detector);
|
||||
verify(listener, times(1)).onShove(detector);
|
||||
verify(listener, times(1)).onShoveEnd(detector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.graphics.PointF
|
||||
import com.mapbox.android.gestures.MoveGestureDetector
|
||||
import com.mapbox.android.gestures.RotateGestureDetector
|
||||
import com.mapbox.android.gestures.ShoveGestureDetector
|
||||
import com.mapbox.android.gestures.StandardScaleGestureDetector
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito
|
||||
|
||||
class MapTouchListenersTest {
|
||||
private var mapGestureDetector: MapGestureDetector? = null
|
||||
private var latLng: LatLng? = null
|
||||
private var pointF: PointF? = null
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
latLng = LatLng()
|
||||
pointF = PointF()
|
||||
val projection = Mockito.mock(
|
||||
Projection::class.java
|
||||
)
|
||||
Mockito.`when`(projection.fromScreenLocation(pointF!!)).thenReturn(latLng)
|
||||
mapGestureDetector = MapGestureDetector(
|
||||
null,
|
||||
null,
|
||||
projection,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun onMapClickListenerTest() {
|
||||
val listener = Mockito.mock(
|
||||
OnMapClickListener::class.java
|
||||
)
|
||||
mapGestureDetector!!.addOnMapClickListener(listener)
|
||||
mapGestureDetector!!.notifyOnMapClickListeners(pointF!!)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMapClick(
|
||||
latLng!!
|
||||
)
|
||||
mapGestureDetector!!.removeOnMapClickListener(listener)
|
||||
mapGestureDetector!!.notifyOnMapClickListeners(pointF!!)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMapClick(
|
||||
latLng!!
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun onMapLongClickListenerTest() {
|
||||
val listener = Mockito.mock(
|
||||
OnMapLongClickListener::class.java
|
||||
)
|
||||
mapGestureDetector!!.addOnMapLongClickListener(listener)
|
||||
mapGestureDetector!!.notifyOnMapLongClickListeners(pointF!!)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMapLongClick(
|
||||
latLng!!
|
||||
)
|
||||
mapGestureDetector!!.removeOnMapLongClickListener(listener)
|
||||
mapGestureDetector!!.notifyOnMapLongClickListeners(pointF!!)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMapLongClick(
|
||||
latLng!!
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun onFlingListenerTest() {
|
||||
val listener = Mockito.mock(
|
||||
MapboxMap.OnFlingListener::class.java
|
||||
)
|
||||
mapGestureDetector!!.addOnFlingListener(listener)
|
||||
mapGestureDetector!!.notifyOnFlingListeners()
|
||||
Mockito.verify(listener, Mockito.times(1)).onFling()
|
||||
mapGestureDetector!!.removeOnFlingListener(listener)
|
||||
mapGestureDetector!!.notifyOnFlingListeners()
|
||||
Mockito.verify(listener, Mockito.times(1)).onFling()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun onMoveListenerTest() {
|
||||
val listener = Mockito.mock(OnMoveListener::class.java)
|
||||
val detector = Mockito.mock(
|
||||
MoveGestureDetector::class.java
|
||||
)
|
||||
mapGestureDetector!!.addOnMoveListener(listener)
|
||||
mapGestureDetector!!.notifyOnMoveBeginListeners(detector)
|
||||
mapGestureDetector!!.notifyOnMoveListeners(detector)
|
||||
mapGestureDetector!!.notifyOnMoveEndListeners(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMoveBegin(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMove(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMoveEnd(detector)
|
||||
mapGestureDetector!!.removeOnMoveListener(listener)
|
||||
mapGestureDetector!!.notifyOnMoveBeginListeners(detector)
|
||||
mapGestureDetector!!.notifyOnMoveListeners(detector)
|
||||
mapGestureDetector!!.notifyOnMoveEndListeners(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMoveBegin(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMove(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onMoveEnd(detector)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun onRotateListenerTest() {
|
||||
val listener = Mockito.mock(
|
||||
MapboxMap.OnRotateListener::class.java
|
||||
)
|
||||
val detector = Mockito.mock(
|
||||
RotateGestureDetector::class.java
|
||||
)
|
||||
mapGestureDetector!!.addOnRotateListener(listener)
|
||||
mapGestureDetector!!.notifyOnRotateBeginListeners(detector)
|
||||
mapGestureDetector!!.notifyOnRotateListeners(detector)
|
||||
mapGestureDetector!!.notifyOnRotateEndListeners(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onRotateBegin(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onRotate(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onRotateEnd(detector)
|
||||
mapGestureDetector!!.removeOnRotateListener(listener)
|
||||
mapGestureDetector!!.notifyOnRotateBeginListeners(detector)
|
||||
mapGestureDetector!!.notifyOnRotateListeners(detector)
|
||||
mapGestureDetector!!.notifyOnRotateEndListeners(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onRotateBegin(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onRotate(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onRotateEnd(detector)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun onScaleListenerTest() {
|
||||
val listener = Mockito.mock(OnScaleListener::class.java)
|
||||
val detector = Mockito.mock(
|
||||
StandardScaleGestureDetector::class.java
|
||||
)
|
||||
mapGestureDetector!!.addOnScaleListener(listener)
|
||||
mapGestureDetector!!.notifyOnScaleBeginListeners(detector)
|
||||
mapGestureDetector!!.notifyOnScaleListeners(detector)
|
||||
mapGestureDetector!!.notifyOnScaleEndListeners(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onScaleBegin(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onScale(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onScaleEnd(detector)
|
||||
mapGestureDetector!!.removeOnScaleListener(listener)
|
||||
mapGestureDetector!!.notifyOnScaleBeginListeners(detector)
|
||||
mapGestureDetector!!.notifyOnScaleListeners(detector)
|
||||
mapGestureDetector!!.notifyOnScaleEndListeners(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onScaleBegin(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onScale(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onScaleEnd(detector)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun onShoveListenerTest() {
|
||||
val listener = Mockito.mock(OnShoveListener::class.java)
|
||||
val detector = Mockito.mock(
|
||||
ShoveGestureDetector::class.java
|
||||
)
|
||||
mapGestureDetector!!.addShoveListener(listener)
|
||||
mapGestureDetector!!.notifyOnShoveBeginListeners(detector)
|
||||
mapGestureDetector!!.notifyOnShoveListeners(detector)
|
||||
mapGestureDetector!!.notifyOnShoveEndListeners(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onShoveBegin(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onShove(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onShoveEnd(detector)
|
||||
mapGestureDetector!!.removeShoveListener(listener)
|
||||
mapGestureDetector!!.notifyOnShoveBeginListeners(detector)
|
||||
mapGestureDetector!!.notifyOnShoveListeners(detector)
|
||||
mapGestureDetector!!.notifyOnShoveEndListeners(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onShoveBegin(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onShove(detector)
|
||||
Mockito.verify(listener, Mockito.times(1)).onShoveEnd(detector)
|
||||
}
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MapboxMapOptionsTest {
|
||||
|
||||
private static final double DELTA = 1e-15;
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("should not be null", new MapboxMapOptions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDebugEnabled() {
|
||||
assertFalse(new MapboxMapOptions().getDebugActive());
|
||||
assertTrue(new MapboxMapOptions().debugActive(true).getDebugActive());
|
||||
assertFalse(new MapboxMapOptions().debugActive(false).getDebugActive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassEnabled() {
|
||||
assertTrue(new MapboxMapOptions().compassEnabled(true).getCompassEnabled());
|
||||
assertFalse(new MapboxMapOptions().compassEnabled(false).getCompassEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassGravity() {
|
||||
assertEquals(Gravity.TOP | Gravity.END, new MapboxMapOptions().getCompassGravity());
|
||||
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity());
|
||||
assertNotEquals(Gravity.START, new MapboxMapOptions().compassGravity(Gravity.BOTTOM).getCompassGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassMargins() {
|
||||
assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().compassMargins(
|
||||
new int[] {0, 1, 2, 3}).getCompassMargins()));
|
||||
assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().compassMargins(
|
||||
new int[] {0, 0, 0, 0}).getCompassMargins()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoEnabled() {
|
||||
assertTrue(new MapboxMapOptions().logoEnabled(true).getLogoEnabled());
|
||||
assertFalse(new MapboxMapOptions().logoEnabled(false).getLogoEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoGravity() {
|
||||
assertEquals(Gravity.BOTTOM | Gravity.START, new MapboxMapOptions().getLogoGravity());
|
||||
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().logoGravity(Gravity.BOTTOM).getLogoGravity());
|
||||
assertNotEquals(Gravity.START, new MapboxMapOptions().logoGravity(Gravity.BOTTOM).getLogoGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoMargins() {
|
||||
assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().logoMargins(
|
||||
new int[] {0, 1, 2, 3}).getLogoMargins()));
|
||||
assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().logoMargins(
|
||||
new int[] {0, 0, 0, 0}).getLogoMargins()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionTintColor() {
|
||||
assertEquals(-1, new MapboxMapOptions().getAttributionTintColor());
|
||||
assertEquals(Color.RED, new MapboxMapOptions().attributionTintColor(Color.RED).getAttributionTintColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionEnabled() {
|
||||
assertTrue(new MapboxMapOptions().attributionEnabled(true).getAttributionEnabled());
|
||||
assertFalse(new MapboxMapOptions().attributionEnabled(false).getAttributionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionGravity() {
|
||||
assertEquals(Gravity.BOTTOM | Gravity.START, new MapboxMapOptions().getAttributionGravity());
|
||||
assertEquals(Gravity.BOTTOM, new MapboxMapOptions().attributionGravity(Gravity.BOTTOM).getAttributionGravity());
|
||||
assertNotEquals(Gravity.START, new MapboxMapOptions().attributionGravity(Gravity.BOTTOM).getAttributionGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionMargins() {
|
||||
assertTrue(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().attributionMargins(
|
||||
new int[] {0, 1, 2, 3}).getAttributionMargins()));
|
||||
assertFalse(Arrays.equals(new int[] {0, 1, 2, 3}, new MapboxMapOptions().attributionMargins(
|
||||
new int[] {0, 0, 0, 0}).getAttributionMargins()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinZoom() {
|
||||
assertEquals(MapboxConstants.MINIMUM_ZOOM, new MapboxMapOptions().getMinZoomPreference(), DELTA);
|
||||
assertEquals(5.0f, new MapboxMapOptions().minZoomPreference(5.0f).getMinZoomPreference(), DELTA);
|
||||
assertNotEquals(2.0f, new MapboxMapOptions().minZoomPreference(5.0f).getMinZoomPreference(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxZoom() {
|
||||
assertEquals(MapboxConstants.MAXIMUM_ZOOM, new MapboxMapOptions().getMaxZoomPreference(), DELTA);
|
||||
assertEquals(5.0f, new MapboxMapOptions().maxZoomPreference(5.0f).getMaxZoomPreference(), DELTA);
|
||||
assertNotEquals(2.0f, new MapboxMapOptions().maxZoomPreference(5.0f).getMaxZoomPreference(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinPitch() {
|
||||
assertEquals(MapboxConstants.MINIMUM_PITCH, new MapboxMapOptions().getMinPitchPreference(), DELTA);
|
||||
assertEquals(5.0f, new MapboxMapOptions().minPitchPreference(5.0f).getMinPitchPreference(), DELTA);
|
||||
assertNotEquals(2.0f, new MapboxMapOptions().minPitchPreference(5.0f).getMinPitchPreference(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxPitch() {
|
||||
assertEquals(MapboxConstants.MAXIMUM_PITCH, new MapboxMapOptions().getMaxPitchPreference(), DELTA);
|
||||
assertEquals(5.0f, new MapboxMapOptions().maxPitchPreference(5.0f).getMaxPitchPreference(), DELTA);
|
||||
assertNotEquals(2.0f, new MapboxMapOptions().maxPitchPreference(5.0f).getMaxPitchPreference(), DELTA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTiltGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getTiltGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().tiltGesturesEnabled(true).getTiltGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().tiltGesturesEnabled(false).getTiltGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getScrollGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().scrollGesturesEnabled(true).getScrollGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().scrollGesturesEnabled(false).getScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHorizontalScrollGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getHorizontalScrollGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().horizontalScrollGesturesEnabled(true).getHorizontalScrollGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().horizontalScrollGesturesEnabled(false).getHorizontalScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getZoomGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().zoomGesturesEnabled(true).getZoomGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().zoomGesturesEnabled(false).getZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateGesturesEnabled() {
|
||||
assertTrue(new MapboxMapOptions().getRotateGesturesEnabled());
|
||||
assertTrue(new MapboxMapOptions().rotateGesturesEnabled(true).getRotateGesturesEnabled());
|
||||
assertFalse(new MapboxMapOptions().rotateGesturesEnabled(false).getRotateGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCamera() {
|
||||
CameraPosition position = new CameraPosition.Builder().build();
|
||||
assertEquals(new CameraPosition.Builder(position).build(), new MapboxMapOptions().camera(position).getCamera());
|
||||
assertNotEquals(new CameraPosition.Builder().target(new LatLng(1, 1)), new MapboxMapOptions().camera(position));
|
||||
assertNull(new MapboxMapOptions().getCamera());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrefetchesTiles() {
|
||||
// Default value
|
||||
assertTrue(new MapboxMapOptions().getPrefetchesTiles());
|
||||
|
||||
// Check mutations
|
||||
assertTrue(new MapboxMapOptions().setPrefetchesTiles(true).getPrefetchesTiles());
|
||||
assertFalse(new MapboxMapOptions().setPrefetchesTiles(false).getPrefetchesTiles());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrefetchZoomDelta() {
|
||||
// Default value
|
||||
assertEquals(4, new MapboxMapOptions().getPrefetchZoomDelta());
|
||||
|
||||
// Check mutations
|
||||
assertEquals(5, new MapboxMapOptions().setPrefetchZoomDelta(5).getPrefetchZoomDelta());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCrossSourceCollisions() {
|
||||
// Default value
|
||||
assertTrue(new MapboxMapOptions().getCrossSourceCollisions());
|
||||
|
||||
// check mutations
|
||||
assertTrue(new MapboxMapOptions().crossSourceCollisions(true).getCrossSourceCollisions());
|
||||
assertFalse(new MapboxMapOptions().crossSourceCollisions(false).getCrossSourceCollisions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalIdeographFontFamily_enabledByDefault() {
|
||||
MapboxMapOptions options = MapboxMapOptions.createFromAttributes(RuntimeEnvironment.application, null);
|
||||
assertEquals(MapboxConstants.DEFAULT_FONT, options.getLocalIdeographFontFamily());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.Gravity
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import java.util.*
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MapboxMapOptionsTest {
|
||||
@Test
|
||||
fun testSanity() {
|
||||
Assert.assertNotNull("should not be null", MapboxMapOptions())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDebugEnabled() {
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().debugActive)
|
||||
Assert.assertTrue(MapboxMapOptions().debugActive(true).debugActive)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().debugActive(false).debugActive)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompassEnabled() {
|
||||
Assert.assertTrue(MapboxMapOptions().compassEnabled(true).compassEnabled)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().compassEnabled(false).compassEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompassGravity() {
|
||||
junit.framework.Assert.assertEquals(
|
||||
Gravity.TOP or Gravity.END,
|
||||
MapboxMapOptions().compassGravity
|
||||
)
|
||||
junit.framework.Assert.assertEquals(
|
||||
Gravity.BOTTOM,
|
||||
MapboxMapOptions().compassGravity(Gravity.BOTTOM).compassGravity
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
Gravity.START.toLong(),
|
||||
MapboxMapOptions().compassGravity(Gravity.BOTTOM).compassGravity.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompassMargins() {
|
||||
Assert.assertTrue(
|
||||
Arrays.equals(
|
||||
intArrayOf(0, 1, 2, 3),
|
||||
MapboxMapOptions().compassMargins(intArrayOf(0, 1, 2, 3)).compassMargins
|
||||
)
|
||||
)
|
||||
junit.framework.Assert.assertFalse(
|
||||
Arrays.equals(
|
||||
intArrayOf(0, 1, 2, 3),
|
||||
MapboxMapOptions().compassMargins(intArrayOf(0, 0, 0, 0)).compassMargins
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLogoEnabled() {
|
||||
Assert.assertTrue(MapboxMapOptions().logoEnabled(true).logoEnabled)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().logoEnabled(false).logoEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLogoGravity() {
|
||||
junit.framework.Assert.assertEquals(
|
||||
Gravity.BOTTOM or Gravity.START,
|
||||
MapboxMapOptions().logoGravity
|
||||
)
|
||||
junit.framework.Assert.assertEquals(
|
||||
Gravity.BOTTOM,
|
||||
MapboxMapOptions().logoGravity(Gravity.BOTTOM).logoGravity
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
Gravity.START.toLong(),
|
||||
MapboxMapOptions().logoGravity(Gravity.BOTTOM).logoGravity.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLogoMargins() {
|
||||
Assert.assertTrue(
|
||||
Arrays.equals(
|
||||
intArrayOf(0, 1, 2, 3),
|
||||
MapboxMapOptions().logoMargins(intArrayOf(0, 1, 2, 3)).logoMargins
|
||||
)
|
||||
)
|
||||
junit.framework.Assert.assertFalse(
|
||||
Arrays.equals(
|
||||
intArrayOf(0, 1, 2, 3),
|
||||
MapboxMapOptions().logoMargins(intArrayOf(0, 0, 0, 0)).logoMargins
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAttributionTintColor() {
|
||||
junit.framework.Assert.assertEquals(-1, MapboxMapOptions().attributionTintColor)
|
||||
junit.framework.Assert.assertEquals(
|
||||
Color.RED,
|
||||
MapboxMapOptions().attributionTintColor(Color.RED).attributionTintColor
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAttributionEnabled() {
|
||||
Assert.assertTrue(MapboxMapOptions().attributionEnabled(true).attributionEnabled)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().attributionEnabled(false).attributionEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAttributionGravity() {
|
||||
junit.framework.Assert.assertEquals(
|
||||
Gravity.BOTTOM or Gravity.START,
|
||||
MapboxMapOptions().attributionGravity
|
||||
)
|
||||
junit.framework.Assert.assertEquals(
|
||||
Gravity.BOTTOM,
|
||||
MapboxMapOptions().attributionGravity(Gravity.BOTTOM).attributionGravity
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
Gravity.START.toLong(),
|
||||
MapboxMapOptions().attributionGravity(Gravity.BOTTOM).attributionGravity.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAttributionMargins() {
|
||||
Assert.assertTrue(
|
||||
Arrays.equals(
|
||||
intArrayOf(0, 1, 2, 3),
|
||||
MapboxMapOptions().attributionMargins(intArrayOf(0, 1, 2, 3)).attributionMargins
|
||||
)
|
||||
)
|
||||
junit.framework.Assert.assertFalse(
|
||||
Arrays.equals(
|
||||
intArrayOf(0, 1, 2, 3),
|
||||
MapboxMapOptions().attributionMargins(intArrayOf(0, 0, 0, 0)).attributionMargins
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinZoom() {
|
||||
junit.framework.Assert.assertEquals(
|
||||
MapboxConstants.MINIMUM_ZOOM.toDouble(),
|
||||
MapboxMapOptions().minZoomPreference,
|
||||
DELTA
|
||||
)
|
||||
junit.framework.Assert.assertEquals(
|
||||
5.0,
|
||||
MapboxMapOptions().minZoomPreference(5.0).minZoomPreference,
|
||||
DELTA
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
2.0,
|
||||
MapboxMapOptions().minZoomPreference(5.0).minZoomPreference,
|
||||
DELTA
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxZoom() {
|
||||
junit.framework.Assert.assertEquals(
|
||||
MapboxConstants.MAXIMUM_ZOOM.toDouble(),
|
||||
MapboxMapOptions().maxZoomPreference,
|
||||
DELTA
|
||||
)
|
||||
junit.framework.Assert.assertEquals(
|
||||
5.0,
|
||||
MapboxMapOptions().maxZoomPreference(5.0).maxZoomPreference,
|
||||
DELTA
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
2.0,
|
||||
MapboxMapOptions().maxZoomPreference(5.0).maxZoomPreference,
|
||||
DELTA
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinPitch() {
|
||||
junit.framework.Assert.assertEquals(
|
||||
MapboxConstants.MINIMUM_PITCH.toDouble(),
|
||||
MapboxMapOptions().minPitchPreference,
|
||||
DELTA
|
||||
)
|
||||
junit.framework.Assert.assertEquals(
|
||||
5.0,
|
||||
MapboxMapOptions().minPitchPreference(5.0).minPitchPreference,
|
||||
DELTA
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
2.0,
|
||||
MapboxMapOptions().minPitchPreference(5.0).minPitchPreference,
|
||||
DELTA
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMaxPitch() {
|
||||
junit.framework.Assert.assertEquals(
|
||||
MapboxConstants.MAXIMUM_PITCH.toDouble(),
|
||||
MapboxMapOptions().maxPitchPreference,
|
||||
DELTA
|
||||
)
|
||||
junit.framework.Assert.assertEquals(
|
||||
5.0,
|
||||
MapboxMapOptions().maxPitchPreference(5.0).maxPitchPreference,
|
||||
DELTA
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
2.0,
|
||||
MapboxMapOptions().maxPitchPreference(5.0).maxPitchPreference,
|
||||
DELTA
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTiltGesturesEnabled() {
|
||||
Assert.assertTrue(MapboxMapOptions().tiltGesturesEnabled)
|
||||
Assert.assertTrue(MapboxMapOptions().tiltGesturesEnabled(true).tiltGesturesEnabled)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().tiltGesturesEnabled(false).tiltGesturesEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScrollGesturesEnabled() {
|
||||
Assert.assertTrue(MapboxMapOptions().scrollGesturesEnabled)
|
||||
Assert.assertTrue(MapboxMapOptions().scrollGesturesEnabled(true).scrollGesturesEnabled)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().scrollGesturesEnabled(false).scrollGesturesEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHorizontalScrollGesturesEnabled() {
|
||||
Assert.assertTrue(MapboxMapOptions().horizontalScrollGesturesEnabled)
|
||||
Assert.assertTrue(MapboxMapOptions().horizontalScrollGesturesEnabled(true).horizontalScrollGesturesEnabled)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().horizontalScrollGesturesEnabled(false).horizontalScrollGesturesEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testZoomGesturesEnabled() {
|
||||
Assert.assertTrue(MapboxMapOptions().zoomGesturesEnabled)
|
||||
Assert.assertTrue(MapboxMapOptions().zoomGesturesEnabled(true).zoomGesturesEnabled)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().zoomGesturesEnabled(false).zoomGesturesEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateGesturesEnabled() {
|
||||
Assert.assertTrue(MapboxMapOptions().rotateGesturesEnabled)
|
||||
Assert.assertTrue(MapboxMapOptions().rotateGesturesEnabled(true).rotateGesturesEnabled)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().rotateGesturesEnabled(false).rotateGesturesEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCamera() {
|
||||
val position = CameraPosition.Builder().build()
|
||||
junit.framework.Assert.assertEquals(
|
||||
CameraPosition.Builder(position).build(),
|
||||
MapboxMapOptions().camera(position).camera
|
||||
)
|
||||
Assert.assertNotEquals(
|
||||
CameraPosition.Builder().target(LatLng(1.0, 1.0)),
|
||||
MapboxMapOptions().camera(position)
|
||||
)
|
||||
junit.framework.Assert.assertNull(MapboxMapOptions().camera)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPrefetchesTiles() {
|
||||
// Default value
|
||||
Assert.assertTrue(MapboxMapOptions().prefetchesTiles)
|
||||
|
||||
// Check mutations
|
||||
Assert.assertTrue(MapboxMapOptions().setPrefetchesTiles(true).prefetchesTiles)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().setPrefetchesTiles(false).prefetchesTiles)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPrefetchZoomDelta() {
|
||||
// Default value
|
||||
junit.framework.Assert.assertEquals(4, MapboxMapOptions().prefetchZoomDelta)
|
||||
|
||||
// Check mutations
|
||||
junit.framework.Assert.assertEquals(
|
||||
5,
|
||||
MapboxMapOptions().setPrefetchZoomDelta(5).prefetchZoomDelta
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCrossSourceCollisions() {
|
||||
// Default value
|
||||
Assert.assertTrue(MapboxMapOptions().crossSourceCollisions)
|
||||
|
||||
// check mutations
|
||||
Assert.assertTrue(MapboxMapOptions().crossSourceCollisions(true).crossSourceCollisions)
|
||||
junit.framework.Assert.assertFalse(MapboxMapOptions().crossSourceCollisions(false).crossSourceCollisions)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLocalIdeographFontFamily_enabledByDefault() {
|
||||
val options = MapboxMapOptions.createFromAttributes(RuntimeEnvironment.application, null)
|
||||
junit.framework.Assert.assertEquals(
|
||||
MapboxConstants.DEFAULT_FONT,
|
||||
options.localIdeographFontFamily
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DELTA = 1e-15
|
||||
}
|
||||
}
|
||||
@@ -1,472 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class UiSettingsTest {
|
||||
@InjectMocks
|
||||
MapView mapview = mock(MapView.class);
|
||||
|
||||
@InjectMocks
|
||||
Context context = mock(Context.class);
|
||||
|
||||
@InjectMocks
|
||||
Resources resources = mock(Resources.class);
|
||||
|
||||
@InjectMocks
|
||||
Projection projection = mock(Projection.class);
|
||||
|
||||
@InjectMocks
|
||||
FocalPointChangeListener focalPointChangeListener = mock(FocalPointChangeListener.class);
|
||||
|
||||
@InjectMocks
|
||||
CompassView compassView = mock(CompassView.class);
|
||||
|
||||
@InjectMocks
|
||||
ImageView attributionView = mock(ImageView.class);
|
||||
|
||||
@InjectMocks
|
||||
ImageView logoView = mock(ImageView.class);
|
||||
|
||||
@InjectMocks
|
||||
FrameLayout.LayoutParams layoutParams = mock(FrameLayout.LayoutParams.class);
|
||||
|
||||
private UiSettings uiSettings;
|
||||
private MapboxMapOptions mapboxMapOptions;
|
||||
|
||||
@Before
|
||||
public void beforeTest() {
|
||||
uiSettings = new UiSettings(projection, focalPointChangeListener, 1, mapview);
|
||||
uiSettings.compassView = this.compassView;
|
||||
uiSettings.attributionsView = this.attributionView;
|
||||
uiSettings.logoView = this.logoView;
|
||||
when(compassView.getContext()).thenReturn(context);
|
||||
when(attributionView.getContext()).thenReturn(context);
|
||||
when(logoView.getContext()).thenReturn(context);
|
||||
when(context.getResources()).thenReturn(resources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanity() {
|
||||
assertNotNull("uiSettings should not be null", uiSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCompassEnabled() {
|
||||
when(compassView.isEnabled()).thenReturn(true);
|
||||
assertEquals("Compass should be enabled", true, uiSettings.isCompassEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCompassEnabled() {
|
||||
uiSettings.isCompassInitialized = true;
|
||||
uiSettings.setCompassEnabled(true);
|
||||
verify(compassView).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassDisabled() {
|
||||
uiSettings.setCompassEnabled(false);
|
||||
assertEquals("Compass should be disabled", false, uiSettings.isCompassEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassGravity() {
|
||||
when(compassView.getLayoutParams()).thenReturn(layoutParams);
|
||||
layoutParams.gravity = Gravity.START;
|
||||
uiSettings.setCompassGravity(Gravity.START);
|
||||
assertEquals("Compass gravity should be same", Gravity.START, uiSettings.getCompassGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassMargins() {
|
||||
when(projection.getContentPadding()).thenReturn(new int[]{0, 0, 0, 0});
|
||||
when(compassView.getLayoutParams()).thenReturn(layoutParams);
|
||||
layoutParams.leftMargin = 1;
|
||||
layoutParams.topMargin = 2;
|
||||
layoutParams.rightMargin = 3;
|
||||
layoutParams.bottomMargin = 4;
|
||||
uiSettings.setCompassMargins(1, 2, 3, 4);
|
||||
assertTrue("Compass margin left should be same", uiSettings.getCompassMarginLeft() == 1);
|
||||
assertTrue("Compass margin top should be same", uiSettings.getCompassMarginTop() == 2);
|
||||
assertTrue("Compass margin right should be same", uiSettings.getCompassMarginRight() == 3);
|
||||
assertTrue("Compass margin bottom should be same", uiSettings.getCompassMarginBottom() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompassFadeWhenFacingNorth() {
|
||||
when(compassView.isFadeCompassViewFacingNorth()).thenReturn(true);
|
||||
assertTrue("Compass should fade when facing north by default.", uiSettings.isCompassFadeWhenFacingNorth());
|
||||
uiSettings.setCompassFadeFacingNorth(false);
|
||||
when(compassView.isFadeCompassViewFacingNorth()).thenReturn(false);
|
||||
assertFalse("Compass fading should be disabled", uiSettings.isCompassFadeWhenFacingNorth());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoEnabled() {
|
||||
uiSettings.isLogoInitialized = true;
|
||||
uiSettings.setLogoEnabled(true);
|
||||
assertEquals("Logo should be enabled", true, uiSettings.isLogoEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoDisabled() {
|
||||
when(logoView.getVisibility()).thenReturn(View.GONE);
|
||||
uiSettings.setLogoEnabled(false);
|
||||
assertEquals("Logo should be disabled", false, uiSettings.isLogoEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoGravity() {
|
||||
layoutParams.gravity = Gravity.END;
|
||||
when(logoView.getLayoutParams()).thenReturn(layoutParams);
|
||||
uiSettings.setLogoGravity(Gravity.END);
|
||||
assertEquals("Logo gravity should be same", Gravity.END, uiSettings.getLogoGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogoMargins() {
|
||||
when(projection.getContentPadding()).thenReturn(new int[]{0, 0, 0, 0});
|
||||
when(logoView.getLayoutParams()).thenReturn(layoutParams);
|
||||
layoutParams.leftMargin = 1;
|
||||
layoutParams.topMargin = 2;
|
||||
layoutParams.rightMargin = 3;
|
||||
layoutParams.bottomMargin = 4;
|
||||
uiSettings.setLogoMargins(1, 2, 3, 4);
|
||||
assertTrue("Compass margin left should be same", uiSettings.getLogoMarginLeft() == 1);
|
||||
assertTrue("Compass margin top should be same", uiSettings.getLogoMarginTop() == 2);
|
||||
assertTrue("Compass margin right should be same", uiSettings.getLogoMarginRight() == 3);
|
||||
assertTrue("Compass margin bottom should be same", uiSettings.getLogoMarginBottom() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionEnabled() {
|
||||
uiSettings.isAttributionInitialized = true;
|
||||
when(attributionView.getVisibility()).thenReturn(View.VISIBLE);
|
||||
uiSettings.setAttributionEnabled(true);
|
||||
assertEquals("Attribution should be enabled", true, uiSettings.isAttributionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionDisabled() {
|
||||
when(attributionView.getVisibility()).thenReturn(View.GONE);
|
||||
uiSettings.setAttributionEnabled(false);
|
||||
assertEquals("Attribution should be disabled", false, uiSettings.isAttributionEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionGravity() {
|
||||
when(attributionView.getLayoutParams()).thenReturn(layoutParams);
|
||||
layoutParams.gravity = Gravity.END;
|
||||
uiSettings.setAttributionGravity(Gravity.END);
|
||||
assertEquals("Attribution gravity should be same", Gravity.END, uiSettings.getAttributionGravity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributionMargins() {
|
||||
when(attributionView.getLayoutParams()).thenReturn(layoutParams);
|
||||
when(projection.getContentPadding()).thenReturn(new int[]{0, 0, 0, 0});
|
||||
layoutParams.leftMargin = 1;
|
||||
layoutParams.topMargin = 2;
|
||||
layoutParams.rightMargin = 3;
|
||||
layoutParams.bottomMargin = 4;
|
||||
uiSettings.setAttributionMargins(1, 2, 3, 4);
|
||||
assertTrue("Attribution margin left should be same", uiSettings.getAttributionMarginLeft() == 1);
|
||||
assertTrue("Attribution margin top should be same", uiSettings.getAttributionMarginTop() == 2);
|
||||
assertTrue("Attribution margin right should be same", uiSettings.getAttributionMarginRight() == 3);
|
||||
assertTrue("Attribution margin bottom should be same", uiSettings.getAttributionMarginBottom() == 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateGesturesEnabled() {
|
||||
uiSettings.setRotateGesturesEnabled(true);
|
||||
assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateGesturesDisabled() {
|
||||
uiSettings.setRotateGesturesEnabled(false);
|
||||
assertEquals("Rotate gesture should be disabled", false, uiSettings.isRotateGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateGestureChangeAllowed() {
|
||||
uiSettings.setRotateGesturesEnabled(false);
|
||||
assertEquals("Rotate gesture should be false", false, uiSettings.isRotateGesturesEnabled());
|
||||
uiSettings.setRotateGesturesEnabled(true);
|
||||
assertEquals("Rotate gesture should be true", true, uiSettings.isRotateGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTiltGesturesEnabled() {
|
||||
uiSettings.setTiltGesturesEnabled(true);
|
||||
assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTiltGesturesDisabled() {
|
||||
uiSettings.setTiltGesturesEnabled(false);
|
||||
assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTiltGestureChangeAllowed() {
|
||||
uiSettings.setTiltGesturesEnabled(false);
|
||||
assertEquals("Tilt gesture should be false", false, uiSettings.isTiltGesturesEnabled());
|
||||
uiSettings.setTiltGesturesEnabled(true);
|
||||
assertEquals("Tilt gesture should be true", true, uiSettings.isTiltGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomGesturesEnabled() {
|
||||
uiSettings.setZoomGesturesEnabled(true);
|
||||
assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomGesturesDisabled() {
|
||||
uiSettings.setZoomGesturesEnabled(false);
|
||||
assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomGestureChangeAllowed() {
|
||||
uiSettings.setZoomGesturesEnabled(false);
|
||||
assertEquals("Zoom gesture should be false", false, uiSettings.isZoomGesturesEnabled());
|
||||
uiSettings.setZoomGesturesEnabled(true);
|
||||
assertEquals("Zoom gesture should be true", true, uiSettings.isZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleTapGesturesEnabled() {
|
||||
uiSettings.setDoubleTapGesturesEnabled(true);
|
||||
assertEquals("DoubleTap gesture should be enabled", true, uiSettings.isDoubleTapGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleTapGesturesDisabled() {
|
||||
uiSettings.setDoubleTapGesturesEnabled(false);
|
||||
assertEquals("DoubleTap gesture should be disabled", false, uiSettings.isDoubleTapGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleTapGestureChangeAllowed() {
|
||||
uiSettings.setDoubleTapGesturesEnabled(false);
|
||||
assertEquals("DoubleTap gesture should be false", false, uiSettings.isDoubleTapGesturesEnabled());
|
||||
uiSettings.setDoubleTapGesturesEnabled(true);
|
||||
assertEquals("DoubleTap gesture should be true", true, uiSettings.isDoubleTapGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGesturesEnabled() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(true);
|
||||
assertEquals("QuickZoom gesture should be enabled", true, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGesturesDisabled() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(false);
|
||||
assertEquals("QuickZoom gesture should be disabled", false, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickZoomGestureChangeAllowed() {
|
||||
uiSettings.setQuickZoomGesturesEnabled(false);
|
||||
assertEquals("QuickZoom gesture should be false", false, uiSettings.isQuickZoomGesturesEnabled());
|
||||
uiSettings.setQuickZoomGesturesEnabled(true);
|
||||
assertEquals("QuickZoom gesture should be true", true, uiSettings.isQuickZoomGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGesturesEnabled() {
|
||||
uiSettings.setScrollGesturesEnabled(true);
|
||||
assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGesturesDisabled() {
|
||||
uiSettings.setScrollGesturesEnabled(false);
|
||||
assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHorizontalScrollGesturesEnabled() {
|
||||
uiSettings.setHorizontalScrollGesturesEnabled(true);
|
||||
assertEquals("Scroll gesture should be enabled", true, uiSettings.isHorizontalScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHorizontalScrollGesturesDisabled() {
|
||||
uiSettings.setHorizontalScrollGesturesEnabled(false);
|
||||
assertEquals("Scroll gesture should be disabled", false, uiSettings.isHorizontalScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScrollGestureChangeAllowed() {
|
||||
uiSettings.setScrollGesturesEnabled(false);
|
||||
assertEquals("Scroll gesture should be false", false, uiSettings.isScrollGesturesEnabled());
|
||||
uiSettings.setScrollGesturesEnabled(true);
|
||||
assertEquals("Scroll gesture should be true", true, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScaleVelocityAnimationEnabled() {
|
||||
uiSettings.setScaleVelocityAnimationEnabled(true);
|
||||
assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScaleVelocityAnimationDisabled() {
|
||||
uiSettings.setScaleVelocityAnimationEnabled(false);
|
||||
assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateVelocityAnimationEnabled() {
|
||||
uiSettings.setRotateVelocityAnimationEnabled(true);
|
||||
assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotateVelocityAnimationDisabled() {
|
||||
uiSettings.setRotateVelocityAnimationEnabled(false);
|
||||
assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlingVelocityAnimationEnabled() {
|
||||
uiSettings.setFlingVelocityAnimationEnabled(true);
|
||||
assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlingVelocityAnimationDisabled() {
|
||||
uiSettings.setFlingVelocityAnimationEnabled(false);
|
||||
assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllVelocityAnimationsEnabled() {
|
||||
uiSettings.setAllVelocityAnimationsEnabled(true);
|
||||
assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled());
|
||||
assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled());
|
||||
assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllVelocityAnimationsDisabled() {
|
||||
uiSettings.setAllVelocityAnimationsEnabled(false);
|
||||
assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled());
|
||||
assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled());
|
||||
assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableRotateWhenScalingEnabled() {
|
||||
uiSettings.setDisableRotateWhenScaling(true);
|
||||
assertEquals("Rotate disabling should be enabled", true,
|
||||
uiSettings.isDisableRotateWhenScaling());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableRotateWhenScalingDisabled() {
|
||||
uiSettings.setDisableRotateWhenScaling(false);
|
||||
assertEquals("Rotate disabling should be disabled", false,
|
||||
uiSettings.isDisableRotateWhenScaling());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncreaseScaleThresholdWhenRotatingEnabled() {
|
||||
uiSettings.setIncreaseScaleThresholdWhenRotating(true);
|
||||
assertEquals("Scale threshold increase should be enabled", true, uiSettings.isIncreaseScaleThresholdWhenRotating());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncreaseScaleThresholdWhenRotatingDisabled() {
|
||||
uiSettings.setIncreaseScaleThresholdWhenRotating(false);
|
||||
assertEquals("Scale threshold increase should be disabled", false,
|
||||
uiSettings.isIncreaseScaleThresholdWhenRotating());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllGesturesEnabled() {
|
||||
uiSettings.setAllGesturesEnabled(true);
|
||||
assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled());
|
||||
assertEquals("Tilt gesture should be enabled", true, uiSettings.isTiltGesturesEnabled());
|
||||
assertEquals("Zoom gesture should be enabled", true, uiSettings.isZoomGesturesEnabled());
|
||||
assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllGesturesDisabled() {
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
assertEquals("Rotate gesture should be enabled", false, uiSettings.isRotateGesturesEnabled());
|
||||
assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled());
|
||||
assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled());
|
||||
assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAreAllGesturesEnabled() {
|
||||
uiSettings.setAllGesturesEnabled(true);
|
||||
assertEquals("All gestures check should return true", true,
|
||||
uiSettings.areAllGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAreAllGesturesEnabledWithOneGestureDisabled() {
|
||||
uiSettings.setAllGesturesEnabled(true);
|
||||
uiSettings.setScrollGesturesEnabled(false);
|
||||
assertEquals("All gestures check should return false", false,
|
||||
uiSettings.areAllGesturesEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomRateDefaultValue() {
|
||||
assertEquals("Default zoom rate should be 1.0f", 1.0f,
|
||||
uiSettings.getZoomRate(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZoomRate() {
|
||||
uiSettings.setZoomRate(0.83f);
|
||||
assertEquals("Zoom rate should be 0.83f", 0.83f,
|
||||
uiSettings.getZoomRate(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWhenCompassViewNotHidden() {
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT).bearing(24.0f).build();
|
||||
when(compassView.isHidden()).thenReturn(false);
|
||||
uiSettings.update(cameraPosition);
|
||||
verify(compassView).update(-24.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateWhenCompassViewHidden() {
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder(CameraPosition.DEFAULT).bearing(24.0f).build();
|
||||
when(compassView.isHidden()).thenReturn(true);
|
||||
uiSettings.update(cameraPosition);
|
||||
verify(compassView).update(-24.0f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,726 @@
|
||||
package com.mapbox.mapboxsdk.maps
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||
import com.mapbox.mapboxsdk.maps.widgets.CompassView
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mockito
|
||||
|
||||
class UiSettingsTest {
|
||||
@InjectMocks
|
||||
var mapview = Mockito.mock(MapView::class.java)
|
||||
|
||||
@InjectMocks
|
||||
var context = Mockito.mock(
|
||||
Context::class.java
|
||||
)
|
||||
|
||||
@InjectMocks
|
||||
var resources = Mockito.mock(
|
||||
Resources::class.java
|
||||
)
|
||||
|
||||
@InjectMocks
|
||||
var projection = Mockito.mock(
|
||||
Projection::class.java
|
||||
)
|
||||
|
||||
@InjectMocks
|
||||
var focalPointChangeListener = Mockito.mock(
|
||||
FocalPointChangeListener::class.java
|
||||
)
|
||||
|
||||
@InjectMocks
|
||||
var compassView = Mockito.mock(CompassView::class.java)
|
||||
|
||||
@InjectMocks
|
||||
var attributionView = Mockito.mock(
|
||||
ImageView::class.java
|
||||
)
|
||||
|
||||
@InjectMocks
|
||||
var logoView = Mockito.mock(
|
||||
ImageView::class.java
|
||||
)
|
||||
|
||||
@InjectMocks
|
||||
var layoutParams = Mockito.mock(
|
||||
FrameLayout.LayoutParams::class.java
|
||||
)
|
||||
private var uiSettings: UiSettings? = null
|
||||
private val mapboxMapOptions: MapboxMapOptions? = null
|
||||
|
||||
@Before
|
||||
fun beforeTest() {
|
||||
uiSettings = UiSettings(projection, focalPointChangeListener, 1f, mapview)
|
||||
uiSettings!!.compassView = compassView
|
||||
uiSettings!!.attributionsView = attributionView
|
||||
uiSettings!!.logoView = logoView
|
||||
Mockito.`when`(compassView.context).thenReturn(context)
|
||||
Mockito.`when`(attributionView.context).thenReturn(context)
|
||||
Mockito.`when`(logoView.context).thenReturn(context)
|
||||
Mockito.`when`(context.resources).thenReturn(resources)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSanity() {
|
||||
Assert.assertNotNull("uiSettings should not be null", uiSettings)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetCompassEnabled() {
|
||||
Mockito.`when`(compassView.isEnabled).thenReturn(true)
|
||||
Assert.assertEquals("Compass should be enabled", true, uiSettings!!.isCompassEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSetCompassEnabled() {
|
||||
uiSettings!!.isCompassInitialized = true
|
||||
uiSettings!!.isCompassEnabled = true
|
||||
Mockito.verify(compassView).isEnabled = true
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompassDisabled() {
|
||||
uiSettings!!.isCompassEnabled = false
|
||||
Assert.assertEquals("Compass should be disabled", false, uiSettings!!.isCompassEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompassGravity() {
|
||||
Mockito.`when`(compassView.layoutParams).thenReturn(layoutParams)
|
||||
layoutParams.gravity = Gravity.START
|
||||
uiSettings!!.compassGravity = Gravity.START
|
||||
Assert.assertEquals(
|
||||
"Compass gravity should be same",
|
||||
Gravity.START.toLong(),
|
||||
uiSettings!!.compassGravity.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompassMargins() {
|
||||
Mockito.`when`(projection.contentPadding).thenReturn(intArrayOf(0, 0, 0, 0))
|
||||
Mockito.`when`(compassView.layoutParams).thenReturn(layoutParams)
|
||||
layoutParams.leftMargin = 1
|
||||
layoutParams.topMargin = 2
|
||||
layoutParams.rightMargin = 3
|
||||
layoutParams.bottomMargin = 4
|
||||
uiSettings!!.setCompassMargins(1, 2, 3, 4)
|
||||
Assert.assertTrue("Compass margin left should be same", uiSettings!!.compassMarginLeft == 1)
|
||||
Assert.assertTrue("Compass margin top should be same", uiSettings!!.compassMarginTop == 2)
|
||||
Assert.assertTrue(
|
||||
"Compass margin right should be same",
|
||||
uiSettings!!.compassMarginRight == 3
|
||||
)
|
||||
Assert.assertTrue(
|
||||
"Compass margin bottom should be same",
|
||||
uiSettings!!.compassMarginBottom == 4
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompassFadeWhenFacingNorth() {
|
||||
Mockito.`when`(compassView.isFadeCompassViewFacingNorth).thenReturn(true)
|
||||
Assert.assertTrue(
|
||||
"Compass should fade when facing north by default.",
|
||||
uiSettings!!.isCompassFadeWhenFacingNorth
|
||||
)
|
||||
uiSettings!!.setCompassFadeFacingNorth(false)
|
||||
Mockito.`when`(compassView.isFadeCompassViewFacingNorth).thenReturn(false)
|
||||
Assert.assertFalse(
|
||||
"Compass fading should be disabled",
|
||||
uiSettings!!.isCompassFadeWhenFacingNorth
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLogoEnabled() {
|
||||
uiSettings!!.isLogoInitialized = true
|
||||
uiSettings!!.isLogoEnabled = true
|
||||
Assert.assertEquals("Logo should be enabled", true, uiSettings!!.isLogoEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLogoDisabled() {
|
||||
Mockito.`when`(logoView.visibility).thenReturn(View.GONE)
|
||||
uiSettings!!.isLogoEnabled = false
|
||||
Assert.assertEquals("Logo should be disabled", false, uiSettings!!.isLogoEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLogoGravity() {
|
||||
layoutParams.gravity = Gravity.END
|
||||
Mockito.`when`(logoView.layoutParams).thenReturn(layoutParams)
|
||||
uiSettings!!.logoGravity = Gravity.END
|
||||
Assert.assertEquals(
|
||||
"Logo gravity should be same",
|
||||
Gravity.END.toLong(),
|
||||
uiSettings!!.logoGravity.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLogoMargins() {
|
||||
Mockito.`when`(projection.contentPadding).thenReturn(intArrayOf(0, 0, 0, 0))
|
||||
Mockito.`when`(logoView.layoutParams).thenReturn(layoutParams)
|
||||
layoutParams.leftMargin = 1
|
||||
layoutParams.topMargin = 2
|
||||
layoutParams.rightMargin = 3
|
||||
layoutParams.bottomMargin = 4
|
||||
uiSettings!!.setLogoMargins(1, 2, 3, 4)
|
||||
Assert.assertTrue("Compass margin left should be same", uiSettings!!.logoMarginLeft == 1)
|
||||
Assert.assertTrue("Compass margin top should be same", uiSettings!!.logoMarginTop == 2)
|
||||
Assert.assertTrue("Compass margin right should be same", uiSettings!!.logoMarginRight == 3)
|
||||
Assert.assertTrue(
|
||||
"Compass margin bottom should be same",
|
||||
uiSettings!!.logoMarginBottom == 4
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAttributionEnabled() {
|
||||
uiSettings!!.isAttributionInitialized = true
|
||||
Mockito.`when`(attributionView.visibility).thenReturn(View.VISIBLE)
|
||||
uiSettings!!.isAttributionEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Attribution should be enabled",
|
||||
true,
|
||||
uiSettings!!.isAttributionEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAttributionDisabled() {
|
||||
Mockito.`when`(attributionView.visibility).thenReturn(View.GONE)
|
||||
uiSettings!!.isAttributionEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Attribution should be disabled",
|
||||
false,
|
||||
uiSettings!!.isAttributionEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAttributionGravity() {
|
||||
Mockito.`when`(attributionView.layoutParams).thenReturn(layoutParams)
|
||||
layoutParams.gravity = Gravity.END
|
||||
uiSettings!!.attributionGravity = Gravity.END
|
||||
Assert.assertEquals(
|
||||
"Attribution gravity should be same",
|
||||
Gravity.END.toLong(),
|
||||
uiSettings!!.attributionGravity.toLong()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAttributionMargins() {
|
||||
Mockito.`when`(attributionView.layoutParams).thenReturn(layoutParams)
|
||||
Mockito.`when`(projection.contentPadding).thenReturn(intArrayOf(0, 0, 0, 0))
|
||||
layoutParams.leftMargin = 1
|
||||
layoutParams.topMargin = 2
|
||||
layoutParams.rightMargin = 3
|
||||
layoutParams.bottomMargin = 4
|
||||
uiSettings!!.setAttributionMargins(1, 2, 3, 4)
|
||||
Assert.assertTrue(
|
||||
"Attribution margin left should be same",
|
||||
uiSettings!!.attributionMarginLeft == 1
|
||||
)
|
||||
Assert.assertTrue(
|
||||
"Attribution margin top should be same",
|
||||
uiSettings!!.attributionMarginTop == 2
|
||||
)
|
||||
Assert.assertTrue(
|
||||
"Attribution margin right should be same",
|
||||
uiSettings!!.attributionMarginRight == 3
|
||||
)
|
||||
Assert.assertTrue(
|
||||
"Attribution margin bottom should be same",
|
||||
uiSettings!!.attributionMarginBottom == 4
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateGesturesEnabled() {
|
||||
uiSettings!!.isRotateGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Rotate gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isRotateGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateGesturesDisabled() {
|
||||
uiSettings!!.isRotateGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Rotate gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isRotateGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateGestureChangeAllowed() {
|
||||
uiSettings!!.isRotateGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Rotate gesture should be false",
|
||||
false,
|
||||
uiSettings!!.isRotateGesturesEnabled
|
||||
)
|
||||
uiSettings!!.isRotateGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Rotate gesture should be true",
|
||||
true,
|
||||
uiSettings!!.isRotateGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTiltGesturesEnabled() {
|
||||
uiSettings!!.isTiltGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Tilt gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isTiltGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTiltGesturesDisabled() {
|
||||
uiSettings!!.isTiltGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Tilt gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isTiltGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTiltGestureChangeAllowed() {
|
||||
uiSettings!!.isTiltGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Tilt gesture should be false",
|
||||
false,
|
||||
uiSettings!!.isTiltGesturesEnabled
|
||||
)
|
||||
uiSettings!!.isTiltGesturesEnabled = true
|
||||
Assert.assertEquals("Tilt gesture should be true", true, uiSettings!!.isTiltGesturesEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testZoomGesturesEnabled() {
|
||||
uiSettings!!.isZoomGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Zoom gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isZoomGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testZoomGesturesDisabled() {
|
||||
uiSettings!!.isZoomGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Zoom gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isZoomGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testZoomGestureChangeAllowed() {
|
||||
uiSettings!!.isZoomGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Zoom gesture should be false",
|
||||
false,
|
||||
uiSettings!!.isZoomGesturesEnabled
|
||||
)
|
||||
uiSettings!!.isZoomGesturesEnabled = true
|
||||
Assert.assertEquals("Zoom gesture should be true", true, uiSettings!!.isZoomGesturesEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDoubleTapGesturesEnabled() {
|
||||
uiSettings!!.isDoubleTapGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"DoubleTap gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isDoubleTapGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDoubleTapGesturesDisabled() {
|
||||
uiSettings!!.isDoubleTapGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"DoubleTap gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isDoubleTapGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDoubleTapGestureChangeAllowed() {
|
||||
uiSettings!!.isDoubleTapGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"DoubleTap gesture should be false",
|
||||
false,
|
||||
uiSettings!!.isDoubleTapGesturesEnabled
|
||||
)
|
||||
uiSettings!!.isDoubleTapGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"DoubleTap gesture should be true",
|
||||
true,
|
||||
uiSettings!!.isDoubleTapGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testQuickZoomGesturesEnabled() {
|
||||
uiSettings!!.isQuickZoomGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"QuickZoom gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isQuickZoomGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testQuickZoomGesturesDisabled() {
|
||||
uiSettings!!.isQuickZoomGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"QuickZoom gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isQuickZoomGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testQuickZoomGestureChangeAllowed() {
|
||||
uiSettings!!.isQuickZoomGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"QuickZoom gesture should be false",
|
||||
false,
|
||||
uiSettings!!.isQuickZoomGesturesEnabled
|
||||
)
|
||||
uiSettings!!.isQuickZoomGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"QuickZoom gesture should be true",
|
||||
true,
|
||||
uiSettings!!.isQuickZoomGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScrollGesturesEnabled() {
|
||||
uiSettings!!.isScrollGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Scroll gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isScrollGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScrollGesturesDisabled() {
|
||||
uiSettings!!.isScrollGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Scroll gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isScrollGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHorizontalScrollGesturesEnabled() {
|
||||
uiSettings!!.isHorizontalScrollGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Scroll gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isHorizontalScrollGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHorizontalScrollGesturesDisabled() {
|
||||
uiSettings!!.isHorizontalScrollGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Scroll gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isHorizontalScrollGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScrollGestureChangeAllowed() {
|
||||
uiSettings!!.isScrollGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Scroll gesture should be false",
|
||||
false,
|
||||
uiSettings!!.isScrollGesturesEnabled
|
||||
)
|
||||
uiSettings!!.isScrollGesturesEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Scroll gesture should be true",
|
||||
true,
|
||||
uiSettings!!.isScrollGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScaleVelocityAnimationEnabled() {
|
||||
uiSettings!!.isScaleVelocityAnimationEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Scale velocity animation should be enabled",
|
||||
true,
|
||||
uiSettings!!.isScaleVelocityAnimationEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScaleVelocityAnimationDisabled() {
|
||||
uiSettings!!.isScaleVelocityAnimationEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Scale velocity animation should be disabled",
|
||||
false,
|
||||
uiSettings!!.isScaleVelocityAnimationEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateVelocityAnimationEnabled() {
|
||||
uiSettings!!.isRotateVelocityAnimationEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Rotate velocity animation should be enabled",
|
||||
true,
|
||||
uiSettings!!.isRotateVelocityAnimationEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRotateVelocityAnimationDisabled() {
|
||||
uiSettings!!.isRotateVelocityAnimationEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Rotate velocity animation should be disabled",
|
||||
false,
|
||||
uiSettings!!.isRotateVelocityAnimationEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFlingVelocityAnimationEnabled() {
|
||||
uiSettings!!.isFlingVelocityAnimationEnabled = true
|
||||
Assert.assertEquals(
|
||||
"Fling velocity animation should be enabled",
|
||||
true,
|
||||
uiSettings!!.isFlingVelocityAnimationEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFlingVelocityAnimationDisabled() {
|
||||
uiSettings!!.isFlingVelocityAnimationEnabled = false
|
||||
Assert.assertEquals(
|
||||
"Fling velocity animation should be disabled",
|
||||
false,
|
||||
uiSettings!!.isFlingVelocityAnimationEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAllVelocityAnimationsEnabled() {
|
||||
uiSettings!!.setAllVelocityAnimationsEnabled(true)
|
||||
Assert.assertEquals(
|
||||
"Scale velocity animation should be enabled",
|
||||
true,
|
||||
uiSettings!!.isScaleVelocityAnimationEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Rotate velocity animation should be enabled",
|
||||
true,
|
||||
uiSettings!!.isRotateVelocityAnimationEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Fling velocity animation should be enabled",
|
||||
true,
|
||||
uiSettings!!.isFlingVelocityAnimationEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAllVelocityAnimationsDisabled() {
|
||||
uiSettings!!.setAllVelocityAnimationsEnabled(false)
|
||||
Assert.assertEquals(
|
||||
"Scale velocity animation should be disabled",
|
||||
false,
|
||||
uiSettings!!.isScaleVelocityAnimationEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Rotate velocity animation should be disabled",
|
||||
false,
|
||||
uiSettings!!.isRotateVelocityAnimationEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Fling velocity animation should be disabled",
|
||||
false,
|
||||
uiSettings!!.isFlingVelocityAnimationEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDisableRotateWhenScalingEnabled() {
|
||||
uiSettings!!.isDisableRotateWhenScaling = true
|
||||
Assert.assertEquals(
|
||||
"Rotate disabling should be enabled",
|
||||
true,
|
||||
uiSettings!!.isDisableRotateWhenScaling
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDisableRotateWhenScalingDisabled() {
|
||||
uiSettings!!.isDisableRotateWhenScaling = false
|
||||
Assert.assertEquals(
|
||||
"Rotate disabling should be disabled",
|
||||
false,
|
||||
uiSettings!!.isDisableRotateWhenScaling
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncreaseScaleThresholdWhenRotatingEnabled() {
|
||||
uiSettings!!.isIncreaseScaleThresholdWhenRotating = true
|
||||
Assert.assertEquals(
|
||||
"Scale threshold increase should be enabled",
|
||||
true,
|
||||
uiSettings!!.isIncreaseScaleThresholdWhenRotating
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncreaseScaleThresholdWhenRotatingDisabled() {
|
||||
uiSettings!!.isIncreaseScaleThresholdWhenRotating = false
|
||||
Assert.assertEquals(
|
||||
"Scale threshold increase should be disabled",
|
||||
false,
|
||||
uiSettings!!.isIncreaseScaleThresholdWhenRotating
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAllGesturesEnabled() {
|
||||
uiSettings!!.setAllGesturesEnabled(true)
|
||||
Assert.assertEquals(
|
||||
"Rotate gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isRotateGesturesEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Tilt gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isTiltGesturesEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Zoom gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isZoomGesturesEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Scroll gesture should be enabled",
|
||||
true,
|
||||
uiSettings!!.isScrollGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAllGesturesDisabled() {
|
||||
uiSettings!!.setAllGesturesEnabled(false)
|
||||
Assert.assertEquals(
|
||||
"Rotate gesture should be enabled",
|
||||
false,
|
||||
uiSettings!!.isRotateGesturesEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Tilt gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isTiltGesturesEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Zoom gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isZoomGesturesEnabled
|
||||
)
|
||||
Assert.assertEquals(
|
||||
"Scroll gesture should be disabled",
|
||||
false,
|
||||
uiSettings!!.isScrollGesturesEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAreAllGesturesEnabled() {
|
||||
uiSettings!!.setAllGesturesEnabled(true)
|
||||
Assert.assertEquals(
|
||||
"All gestures check should return true",
|
||||
true,
|
||||
uiSettings!!.areAllGesturesEnabled()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAreAllGesturesEnabledWithOneGestureDisabled() {
|
||||
uiSettings!!.setAllGesturesEnabled(true)
|
||||
uiSettings!!.isScrollGesturesEnabled = false
|
||||
Assert.assertEquals(
|
||||
"All gestures check should return false",
|
||||
false,
|
||||
uiSettings!!.areAllGesturesEnabled()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testZoomRateDefaultValue() {
|
||||
Assert.assertEquals(
|
||||
"Default zoom rate should be 1.0f",
|
||||
1.0f,
|
||||
uiSettings!!.zoomRate,
|
||||
0f
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testZoomRate() {
|
||||
uiSettings!!.zoomRate = 0.83f
|
||||
Assert.assertEquals(
|
||||
"Zoom rate should be 0.83f",
|
||||
0.83f,
|
||||
uiSettings!!.zoomRate,
|
||||
0f
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUpdateWhenCompassViewNotHidden() {
|
||||
val cameraPosition = CameraPosition.Builder(CameraPosition.DEFAULT).bearing(24.0).build()
|
||||
Mockito.`when`(compassView.isHidden).thenReturn(false)
|
||||
uiSettings!!.update(cameraPosition)
|
||||
Mockito.verify(compassView).update(-24.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUpdateWhenCompassViewHidden() {
|
||||
val cameraPosition = CameraPosition.Builder(CameraPosition.DEFAULT).bearing(24.0).build()
|
||||
Mockito.`when`(compassView.isHidden).thenReturn(true)
|
||||
uiSettings!!.update(cameraPosition)
|
||||
Mockito.verify(compassView).update(-24.0)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user