[android] #4800 - default location view from start: introduced attributes, update MapboxMapOptions, added tests. updated MockParcel

This commit is contained in:
Tobrun
2016-04-25 12:31:07 +02:00
parent ba9703351d
commit e2510fce79
18 changed files with 528 additions and 288 deletions

View File

@@ -7,6 +7,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.MockParcel;
import org.junit.Test;
@@ -167,6 +168,23 @@ public class MapboxMapOptionsTest {
assertNull(new MapboxMapOptions().getCamera());
}
@Test
public void testMyLocationForegroundTint() {
assertEquals(Color.BLUE, new MapboxMapOptions().myLocationForegroundTintColor(Color.BLUE).getMyLocationForegroundTintColor());
}
@Test
public void testMyLocationBackgroundTint() {
assertEquals(Color.BLUE, new MapboxMapOptions().myLocationBackgroundTintColor(Color.BLUE).getMyLocationBackgroundTintColor());
}
@Test
public void testParceable() {
MapboxMapOptions options = new MapboxMapOptions().camera(new CameraPosition.Builder().build()).styleUrl("s").accessToken("a").debugActive(true).compassMargins(new int[]{0, 1, 2, 3});
MapboxMapOptions parceled = (MapboxMapOptions) MockParcel.obtain(options);
assertEquals(options, parceled);
}
@Test
public void testAccessToken() {
assertNull(new MapboxMapOptions().getAccessToken());

View File

@@ -23,13 +23,13 @@ public class MyLocationViewSettingsTest {
MapView mMapView = mock(MapView.class);
@InjectMocks
UserLocationView userLocationView = mock(UserLocationView.class);
MyLocationView myLocationView = mock(MyLocationView.class);
MyLocationViewSettings locationViewSettings;
@Before
public void beforeTest() {
locationViewSettings = new MyLocationViewSettings(mMapView, userLocationView);
locationViewSettings = new MyLocationViewSettings(mMapView, myLocationView);
}
@Test

View File

@@ -18,6 +18,7 @@ import static org.junit.Assert.assertArrayEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyByte;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.anyFloat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
@@ -51,9 +52,8 @@ public class MockParcel {
Method myMethod = creatorClass.getDeclaredMethod("createFromParcel", Parcel.class);
return (Parcelable) myMethod.invoke(fieldValue, parcel);
} catch (Exception e) {
assertNotNull("Exception occurred:" + e.getLocalizedMessage(), null);
return null;
}
return null;
}
public static void testParcelableArray(@NonNull Parcelable object) {
@@ -139,15 +139,39 @@ public class MockParcel {
return null;
}
};
Answer<Void> writeIntArrayAnswer = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
int[] parameters = (int[]) invocation.getArguments()[0];
if (parameters != null) {
objects.add(parameters.length);
for (Object o : parameters) {
objects.add(o);
}
} else {
objects.add(-1);
}
return null;
}
};
doAnswer(writeValueAnswer).when(mockedParcel).writeByte(anyByte());
doAnswer(writeValueAnswer).when(mockedParcel).writeLong(anyLong());
doAnswer(writeValueAnswer).when(mockedParcel).writeString(anyString());
doAnswer(writeValueAnswer).when(mockedParcel).writeInt(anyInt());
doAnswer(writeIntArrayAnswer).when(mockedParcel).writeIntArray(any(int[].class));
doAnswer(writeValueAnswer).when(mockedParcel).writeDouble(anyDouble());
doAnswer(writeValueAnswer).when(mockedParcel).writeFloat(anyFloat());
doAnswer(writeValueAnswer).when(mockedParcel).writeParcelable(any(Parcelable.class), eq(0));
doAnswer(writeArrayAnswer).when(mockedParcel).writeParcelableArray(any(Parcelable[].class), eq(0));
}
private void setupReads() {
when(mockedParcel.readInt()).then(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return (Integer) objects.get(position++);
}
});
when(mockedParcel.readByte()).thenAnswer(new Answer<Byte>() {
@Override
public Byte answer(InvocationOnMock invocation) throws Throwable {
@@ -172,6 +196,12 @@ public class MockParcel {
return (Double) objects.get(position++);
}
});
when(mockedParcel.readFloat()).thenAnswer(new Answer<Float>() {
@Override
public Float answer(InvocationOnMock invocation) throws Throwable {
return (Float) objects.get(position++);
}
});
when(mockedParcel.readParcelable(Parcelable.class.getClassLoader())).thenAnswer(new Answer<Parcelable>() {
@Override
public Parcelable answer(InvocationOnMock invocation) throws Throwable {
@@ -194,6 +224,22 @@ public class MockParcel {
return array;
}
});
when(mockedParcel.createIntArray()).then(new Answer<int[]>() {
@Override
public int[] answer(InvocationOnMock invocation) throws Throwable {
int size = (Integer) objects.get(position++);
if (size == -1) {
return null;
}
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = (Integer) objects.get(position++);
}
return array;
}
});
}
private void setupOthers() {