MapInitializer { public void init(final MapView mapView, final OnMapReadyCallback callback) { loadMap(mapView, null, new BubbleWrapStyle(), false, callback); } @Inject  MapInitializer(Context context, MapzenMapHttpHandler mapzenMapHttpHandler,
      PersistDataManagers persistDataManagers, SceneUpdateManager sceneUpdateManager,
      BitmapMarkerManager bitmapMarkerManager, ImportYamlGenerator yamlGenerator); void init(final MapView mapView, final OnMapReadyCallback callback); void init(final MapView mapView, String mapId, final OnMapReadyCallback callback); void init(final MapView mapView, MapStyle mapStyle, final OnMapReadyCallback callback); void init(final MapView mapView, String mapId, MapStyle mapStyle,
      final OnMapReadyCallback callback); void init(final MapView mapView, MapStyle mapStyle, Locale locale,
      final OnMapReadyCallback callback); void init(final MapView mapView, String mapId, MapStyle mapStyle, Locale locale,
      final OnMapReadyCallback callback); void takeDown();  }
@Test public void init_shouldReturnMapzenMap() throws Exception { final TestCallback callback = new TestCallback(); final TestMapView mapView = new TestMapView(callback); MapzenManager.instance(getMockContext()).setApiKey("fake-mapzen-api-key"); mapInitializer.init(mapView, callback); assertThat(callback.map).isInstanceOf(MapzenMap.class); }
@Test public void init_shouldSetDefaultMapLocale() throws Exception { TestCallback callback = mock(TestCallback.class); TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); tangramMapView.mapView = mapView; tangramMapView.callback = callback; when(mapView.getTangramMapView()).thenReturn(tangramMapView); MapzenManager.instance(getMockContext()).setApiKey("fake-mapzen-api-key"); mapInitializer.init(mapView, new BubbleWrapStyle(), null); ArrayList<SceneUpdate> expected = new ArrayList<>(); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "fake-mapzen-api-key")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, Locale.getDefault().getLanguage())); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); verify(tangramMapView).getMap(any(MapController.SceneLoadListener.class)); verify(mapController).loadSceneYamlAsync(anyString(), anyString(), argThat( new SceneUpdatesMatcher(expected))); }
@Test public void init_shouldSetGivenMapLocale() throws Exception { TestCallback callback = mock(TestCallback.class); TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); tangramMapView.mapView = mapView; tangramMapView.callback = callback; when(mapView.getTangramMapView()).thenReturn(tangramMapView); MapzenManager.instance(getMockContext()).setApiKey("fake-mapzen-api-key"); mapInitializer.init(mapView, new BubbleWrapStyle(), Locale.FRENCH, null); ArrayList<SceneUpdate> expected = new ArrayList<>(); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "fake-mapzen-api-key")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, Locale.FRENCH.getLanguage())); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); verify(tangramMapView).getMap(any(MapController.SceneLoadListener.class)); verify(mapController).loadSceneYamlAsync(anyString(), anyString(), argThat( new SceneUpdatesMatcher(expected))); }
@Test public void init_shouldDefaultToOverlaysDisabledExceptPath() throws Exception { TestCallback callback = mock(TestCallback.class); TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); tangramMapView.mapView = mapView; tangramMapView.callback = callback; when(mapView.getTangramMapView()).thenReturn(tangramMapView); MapzenManager.instance(getMockContext()).setApiKey("fake-mapzen-api-key"); mapInitializer.init(mapView, new BubbleWrapStyle(), null); ArrayList<SceneUpdate> expected = new ArrayList<>(); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "fake-mapzen-api-key")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, Locale.getDefault().getLanguage())); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); verify(tangramMapView).getMap(any(MapController.SceneLoadListener.class)); verify(mapController).loadSceneYamlAsync(anyString(), anyString(), argThat( new SceneUpdatesMatcher(expected))); }
@Test public void init_shouldCallLoadSceneYamlAsync() throws Exception { TestCallback callback = mock(TestCallback.class); TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); tangramMapView.mapView = mapView; tangramMapView.callback = callback; when(mapView.getTangramMapView()).thenReturn(tangramMapView); MapzenManager.instance(getMockContext()).setApiKey("fake-mapzen-api-key"); RefillStyle refillStyle = new RefillStyle(); mapInitializer.init(mapView, refillStyle, null); ArrayList<SceneUpdate> expected = new ArrayList<>(); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_API_KEY, "fake-mapzen-api-key")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_LANGUAGE, Locale.getDefault().getLanguage())); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_TRANSIT_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_BIKE_OVERLAY, "false")); expected.add(new SceneUpdate(STYLE_GLOBAL_VAR_PATH_OVERLAY, "true")); String yaml = "{ import: [ refill-style.yaml, themes/label-5.yaml, " + "themes/detail-10.yaml, themes/color-black.yaml ] }"; verify(mapController).loadSceneYamlAsync(eq(yaml), eq(refillStyle.getStyleRootPath()), argThat(new SceneUpdatesMatcher(expected))); }
@Test public void init_shouldSetDefaultLodForThemedStyle() throws Exception { TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); when(mapView.getTangramMapView()).thenReturn(tangramMapView); ThemedMapStyle style = new RefillStyle(); mapStateManager.setLod(-1); mapInitializer.init(mapView, style, new TestCallback()); assertThat(mapStateManager.getLod()).isEqualTo(style.getDefaultLod()); }
@Test public void init_shouldSetDefaultLabelLevelForThemedStyle() throws Exception { TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); when(mapView.getTangramMapView()).thenReturn(tangramMapView); ThemedMapStyle style = new RefillStyle(); mapStateManager.setLabelLevel(-1); mapInitializer.init(mapView, style, new TestCallback()); assertThat(mapStateManager.getLabelLevel()).isEqualTo(style.getDefaultLabelLevel()); }
@Test public void init_shouldSetDefaultColorForThemedStyle() throws Exception { TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); when(mapView.getTangramMapView()).thenReturn(tangramMapView); ThemedMapStyle style = new RefillStyle(); mapStateManager.setThemeColor(ThemeColor.NONE); mapInitializer.init(mapView, style, new TestCallback()); assertThat(mapStateManager.getThemeColor()).isEqualTo(style.getDefaultColor()); }
@Test public void init_shouldUseCorrectMapStateManager() throws Exception { PersistDataManagers persistManagers = mock(PersistDataManagers.class); MapInitializer initializer = new MapInitializer(mock(Context.class), mock(MapzenMapHttpHandler.class), persistManagers, new SceneUpdateManager(), new BitmapMarkerManager(null, null), new ImportYamlGenerator()); String mapId = "mapId"; when(persistManagers.getMapStateManager(mapId)).thenReturn(mock(MapStateManager.class)); TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); when(mapView.getTangramMapView()).thenReturn(tangramMapView); initializer.init(mapView, mapId, new TestCallback()); verify(persistManagers, times(2)).getMapStateManager(mapId); }
@Test public void init_shouldUseCorrectMapDataManager() throws Exception { PersistDataManagers persistManagers = mock(PersistDataManagers.class); MapInitializer initializer = new MapInitializer(mock(Context.class), mock(MapzenMapHttpHandler.class), persistManagers, new SceneUpdateManager(), new BitmapMarkerManager(null, null), new ImportYamlGenerator()); String mapId = "mapId"; when(persistManagers.getMapStateManager(mapId)).thenReturn(mock(MapStateManager.class)); TestMapView mapView = mock(TestMapView.class); TestTangramMapView tangramMapView = mock(TestTangramMapView.class); MapController mapController = mock(MapController.class); when(tangramMapView.getMap(any(MapController.SceneLoadListener.class))).thenReturn( mapController); when(mapView.getTangramMapView()).thenReturn(tangramMapView); initializer.init(mapView, mapId, new TestCallback()); verify(persistManagers).getMapDataManager(mapId); }