class CameraUpdateHandler {

	public void moveCamera(CameraUpdate cameraUpdate) {
		final OsmCameraUpdate osmCameraUpdate = (OsmCameraUpdate) cameraUpdate;

		final IMapController controller = map.getController();

		if (osmCameraUpdate.bounds != null) {
			final LatLng center = osmCameraUpdate.bounds.getCenter();

			controller.setZoom(map.getMaxZoomLevel());

			controller.zoomToSpan(
					(int) ((osmCameraUpdate.bounds.northeast.latitude - osmCameraUpdate.bounds.southwest.latitude) * 1e6),
					(int) ((osmCameraUpdate.bounds.northeast.longitude - osmCameraUpdate.bounds.southwest.longitude) * 1e6)
			);

			controller.setCenter(
					toGeoPoint(center)
			);

			return;
		}

		if (osmCameraUpdate.zoom != null) {
			controller.setZoom(osmCameraUpdate.zoom.intValue());
		}

		if (osmCameraUpdate.center != null) {
			controller.setCenter(
					toGeoPoint(osmCameraUpdate.center)
			);
		}
	}

}

class CameraUpdateHandlerTest {

	@Mock org.osmdroid.views.MapView map;
	@Mock IMapController mapController;

	@Test
	public void testMoveCameraToPositionWithZoom() throws Exception {

		// Given
		CameraUpdateHandler handler = new CameraUpdateHandler(map);

		final LatLng center = new LatLng(10, 10);
		final int zoomLevel = 10;

		OsmCameraUpdate cameraUpdate = new OsmCameraUpdate.Builder()
				.center(center)
				.zoom((float) zoomLevel)
				.build();

		// When
		handler.moveCamera(cameraUpdate);

		// Then
		verify(mapController).setCenter(eq(toGeoPoint(center)));
		verify(mapController).setZoom(zoomLevel);
		verifyNoMoreInteractions(mapController);
	}

}