@Test public void shouldShowLocationMarker() throws Exception { mapFragment.getMap().layers().remove(mapFragment.getLocationMarkerLayer()); mapFragment.showLocationMarker(); assertThat(mapFragment.getMap().layers().contains(mapFragment.getLocationMarkerLayer())) .isTrue(); }
@Test public void hideProgress_shouldHideProgressView() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.showProgress(); mapFragment.hideProgress(); assertThat(mapFragment.getView().findViewById(R.id.progress)).isNotVisible(); }
@Test public void showProgress_shouldDisableMap() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.getView().findViewById(R.id.map).setClickable(true); mapFragment.showProgress(); assertThat(mapFragment.getView().findViewById(R.id.map)).isNotClickable(); }
@Test public void onPause_shouldEmptyMeMarkers() throws Exception { ItemizedLayer<MarkerItem> meMarkerLayer = mapFragment.getLocationMarkerLayer(); meMarkerLayer.addItem(new MarkerItem("Title", "Description", new GeoPoint(0, 0))); mapFragment.onPause(); assertThat(meMarkerLayer.size()).isEqualTo(0); }
@Test public void hideProgress_shouldEnableMap() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.getView().findViewById(R.id.map).setClickable(false); mapFragment.hideProgress(); assertThat(mapFragment.getView().findViewById(R.id.map)).isClickable(); }
@Test public void clearMarkers_shouldEmptyMapPois() throws Exception { mapFragment.addPoi(getTestSimpleFeature()); mapFragment.addPoi(getTestSimpleFeature()); ItemizedLayer<MarkerItem> poiMarkerLayer = mapFragment.getPoiLayer(); mapFragment.clearMarkers(); assertThat(poiMarkerLayer.size()).isZero(); }
@Test public void onPause_shouldEmptyPoiMarkers() throws Exception { mapFragment.addPoi(getTestSimpleFeature()); mapFragment.addPoi(getTestSimpleFeature()); ItemizedLayer<MarkerItem> poiMarkerLayer = mapFragment.getPoiLayer(); mapFragment.onPause(); assertThat(poiMarkerLayer.size()).isEqualTo(0); }
@Test public void shouldPointToDefaultTileService() throws Exception { assertThat(mapFragment.getTileBaseSource()) .isEqualTo( mapFragment .getActivity() .getResources() .getString(R.string.settings_default_mapsource)); }
@Test public void findMe_shouldNotResetZoomAndPointNorthAfterMapPositionEvent() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.findMe(); MapPosition mapPosition = new MapPosition(); mapPosition.setZoomLevel(10); activity.getMap().events.fire(Map.POSITION_EVENT, mapPosition); mapFragment.findMe(); assertThat(mapFragment.mapController.getZoomLevel()).isEqualTo(10); }
@Test public void onPause_shouldUnregisterFindMeReceiver() { mapFragment.onPause(); Intent expectedIntent = new Intent(COM_MAPZEN_FIND_ME); List<BroadcastReceiver> findMeReceivers = Robolectric.getShadowApplication().getReceiversForIntent(expectedIntent); assertThat(findMeReceivers).isEmpty(); }
@Test public void onItemSingleTapUp_shouldNotifyListener() throws Exception { ItemizedLayer<MarkerItem> poiLayer = mapFragment.getPoiLayer(); poiLayer.addItem(new MarkerItem("Title", "Description", new GeoPoint(0, 0))); poiLayer.onGesture(Gesture.TAP, new FakeMotionEvent(0, 0)); assertThat(listener.getIndex()).isEqualTo(0); assertThat(listener.getItem().getTitle()).isEqualTo("Title"); }
@Before public void setUp() throws Exception { ((TestMapzenApplication) Robolectric.application).inject(this); activity = initBaseActivity(); listener = new TestPoiClickListener(); mapFragment = activity.getMapFragment(); mapFragment.setOnPoiClickListener(listener); }
@Test public void shouldUseOkHttp() throws Exception { Map map = mapFragment.getMap(); TileLayer baseLayer = field("mBaseLayer").ofType(TileLayer.class).in(map).get(); TileSource tileSource = field("mTileSource").ofType(TileSource.class).in(baseLayer).get(); HttpEngine.Factory factory = field("mHttpFactory").ofType(HttpEngine.Factory.class).in(tileSource).get(); assertThat(factory).isInstanceOf(OkHttpEngine.OkHttpFactory.class); }
@Test public void shouldUse10MegResponseCache() throws Exception { Map map = mapFragment.getMap(); TileLayer baseLayer = field("mBaseLayer").ofType(TileLayer.class).in(map).get(); UrlTileSource tileSource = (UrlTileSource) field("mTileSource").ofType(TileSource.class).in(baseLayer).get(); HttpEngine.Factory engine = field("mHttpFactory").ofType(HttpEngine.Factory.class).in(tileSource).get(); OkHttpClient client = field("mClient").ofType(OkHttpClient.class).in(engine).get(); HttpResponseCache cache = (HttpResponseCache) field("responseCache").ofType(OkResponseCache.class).in(client).get(); assertThat(cache.getMaxSize()).isEqualTo(MapFragment.CACHE_SIZE); }
@Test public void shouldUseResponseCacheStoredOnFile() throws Exception { Map map = mapFragment.getMap(); TileLayer baseLayer = field("mBaseLayer").ofType(TileLayer.class).in(map).get(); UrlTileSource tileSource = (UrlTileSource) field("mTileSource").ofType(TileSource.class).in(baseLayer).get(); HttpEngine.Factory engine = field("mHttpFactory").ofType(HttpEngine.Factory.class).in(tileSource).get(); OkHttpClient client = field("mClient").ofType(OkHttpClient.class).in(engine).get(); HttpResponseCache cache = (HttpResponseCache) field("responseCache").ofType(OkResponseCache.class).in(client).get(); assertThat(cache.getDirectory().getAbsolutePath()) .isEqualTo(activity.getExternalCacheDir().getAbsolutePath() + "/tile-cache"); }
@Test public void shouldHideLocationMarker() throws Exception { mapFragment.hideLocationMarker(); assertThat(mapFragment.getMap().layers().contains(mapFragment.getLocationMarkerLayer())) .isFalse(); }
@Test public void shouldHaveMeMarkerLayer() throws Exception { assertThat(mapFragment.getLocationMarkerLayer()).isNotNull(); }
@Test public void shouldHavePoiLayer() throws Exception { assertThat(mapFragment.getPoiLayer()).isNotNull(); }
@Test public void showLocationMarker_shouldNotCrashIfLayersIsNull() throws Exception { mapFragment.setAct(new BaseActivityWithNullLayers()); mapFragment.showLocationMarker(); }
@Test public void onActivityCreated_shouldVerifyTileCacheDirectoryIsAvailable() throws Exception { BaseActivityWithNullCache baseActivityWithNullCache = new BaseActivityWithNullCache(); mapFragment.setAct(baseActivityWithNullCache); mapFragment.onActivityCreated(null); }
@Test(expected = IllegalArgumentException.class) public void onPause_shouldUnregisterLocationUpdatesSubscriber() { mapFragment.onPause(); bus.unregister(mapFragment); }
@Test public void shouldPointToConfiguredTileService() throws Exception { String expected = "http://test.com"; setTileSourceConfiguration(expected); assertThat(mapFragment.getTileBaseSource()).isEqualTo(expected); }
@Test public void shouldSetupLocationMarker() throws Exception { assertThat(mapFragment.getMap().layers().contains(mapFragment.getLocationMarkerLayer())) .isTrue(); }