MapSettingsReader { @Nullable public MapSettings readMapSettings(@Nullable final String json) { if (TextUtils.isEmpty(json)) { return null; } try { return readMapSettings(new StringReader(json)); } catch (IOException ioe) { Log.w(TAG, ioe.getMessage()); } return null; }  @Nullable MapSettings readMapSettings(@Nullable final String json); @NonNull MapSettings readMapSettings(@NonNull final Reader in); @NonNull MapSettings readMapSettings(@NonNull final JsonReader reader);  }
@Test public void testReadMapSettingsFromJsonString() throws Exception { final String json = TestHelper.getFixture("map_settings.json"); final MapSettings mapSettings = mapSettingsReader.readMapSettings(json); assertNotNull(mapSettings); assertFalse(mapSettings.isDisplayScale()); assertTrue(mapSettings.isShowUnitiesLayer()); assertNotNull(mapSettings.getCRSSettings()); assertEquals("EPSG:2154", mapSettings.getCRSSettings() .getCode()); assertEquals("+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs", mapSettings.getCRSSettings() .getDef()); assertEquals(Arrays.asList(914987, 6372012, 994987, 6460012), mapSettings.getCRSSettings() .getBbox()); assertNotNull(mapSettings.getMaxBounds()); assertEquals(Arrays.asList(new GeoPoint(44.024060d, 5.31056d), new GeoPoint(45.576247d, 7.146750d)), mapSettings.getMaxBounds()); assertNotNull(mapSettings.getPolygonBounds()); assertEquals(new GeometryFactory().toGeometry(new Envelope(mapSettings.getMaxBounds() .get(0) .getPoint() .getCoordinate(), mapSettings.getMaxBounds() .get(1) .getPoint() .getCoordinate())), mapSettings.getPolygonBounds()); assertNotNull(mapSettings.getCenter()); assertEquals(new GeoPoint(44.795154d, 6.228655d), mapSettings.getCenter()); assertEquals(2, mapSettings.getZoom()); assertEquals(1, mapSettings.getMinZoom()); assertEquals(10, mapSettings.getMaxZoom()); assertEquals(7, mapSettings.getMinimumZoomPointing()); assertEquals(2, mapSettings.getLayers() .size()); assertEquals("scan.mbtiles", mapSettings.getLayers() .get(0) .getName()); assertEquals("Scan", mapSettings.getLayers() .get(0) .getLabel()); assertEquals(LayerSettings.SOURCE_MBTILES, mapSettings.getLayers() .get(0) .getSource()); assertEquals("ortho", mapSettings.getLayers() .get(1) .getName()); assertEquals("Ortho", mapSettings.getLayers() .get(1) .getLabel()); assertEquals(LayerSettings.SOURCE_MBTILES_SPLIT, mapSettings.getLayers() .get(1) .getSource()); assertNotNull(mapSettings.getUnityLayer()); assertEquals("unities.mbtiles", mapSettings.getUnityLayer() .getName()); assertEquals("Unities", mapSettings.getUnityLayer() .getLabel()); assertEquals(LayerSettings.SOURCE_MBTILES, mapSettings.getUnityLayer() .getSource()); }
@Test public void testReadMapSettingsFromInvalidJsonString() throws Exception { final MapSettings mapSettings = mapSettingsReader.readMapSettings(""); assertNull(mapSettings); }