PrefMigrator { public static void migrateSharedPrefs() { migrate(PrefUtils.getSharedPrefs(), MIGRATIONS); migrate(PrefUtils.getAdminSharedPrefs(), ADMIN_MIGRATIONS); } private  PrefMigrator(); static void migrate(SharedPreferences prefs, Migration... migrations); static void migrateSharedPrefs();  }
@Test public void shouldMigrateGoogleMapSettings() { initPrefs("map_sdk_behavior", "google_maps", "map_basemap_behavior", "streets"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "google", "google_map_style", String.valueOf(GoogleMap.MAP_TYPE_NORMAL)); initPrefs("map_sdk_behavior", "google_maps", "map_basemap_behavior", "satellite"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "google", "google_map_style", String.valueOf(GoogleMap.MAP_TYPE_SATELLITE)); initPrefs("map_sdk_behavior", "google_maps", "map_basemap_behavior", "terrain\u200e"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "google", "google_map_style", String.valueOf(GoogleMap.MAP_TYPE_TERRAIN)); initPrefs("map_sdk_behavior", "google_maps", "map_basemap_behavior", "hybrid"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "google", "google_map_style", String.valueOf(GoogleMap.MAP_TYPE_HYBRID)); }
@Test public void shouldMigrateMapboxMapSettings() { initPrefs("map_sdk_behavior", "mapbox_maps", "map_basemap_behavior", "mapbox_streets"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "mapbox", "mapbox_map_style", Style.MAPBOX_STREETS); initPrefs("map_sdk_behavior", "mapbox_maps", "map_basemap_behavior", "mapbox_light"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "mapbox", "mapbox_map_style", Style.LIGHT); initPrefs("map_sdk_behavior", "mapbox_maps", "map_basemap_behavior", "mapbox_dark"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "mapbox", "mapbox_map_style", Style.DARK); initPrefs("map_sdk_behavior", "mapbox_maps", "map_basemap_behavior", "mapbox_satellite"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "mapbox", "mapbox_map_style", Style.SATELLITE); initPrefs("map_sdk_behavior", "mapbox_maps", "map_basemap_behavior", "mapbox_satellite_streets"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "mapbox", "mapbox_map_style", Style.SATELLITE_STREETS); initPrefs("map_sdk_behavior", "mapbox_maps", "map_basemap_behavior", "mapbox_outdoors"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "mapbox", "mapbox_map_style", Style.OUTDOORS); }
@Test public void shouldMigrateOsmMapSettings() { initPrefs("map_sdk_behavior", "osmdroid", "map_basemap_behavior", "openmap_streets"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "osm"); initPrefs("map_sdk_behavior", "osmdroid", "map_basemap_behavior", "openmap_usgs_topo"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "usgs", "usgs_map_style", "topographic"); initPrefs("map_sdk_behavior", "osmdroid", "map_basemap_behavior", "openmap_usgs_sat"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "usgs", "usgs_map_style", "hybrid"); initPrefs("map_sdk_behavior", "osmdroid", "map_basemap_behavior", "openmap_usgs_img"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "usgs", "usgs_map_style", "satellite"); initPrefs("map_sdk_behavior", "osmdroid", "map_basemap_behavior", "openmap_stamen_terrain"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "stamen"); initPrefs("map_sdk_behavior", "osmdroid", "map_basemap_behavior", "openmap_carto_positron"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "carto", "carto_map_style", "positron"); initPrefs("map_sdk_behavior", "osmdroid", "map_basemap_behavior", "openmap_carto_darkmatter"); PrefMigrator.migrateSharedPrefs(); assertPrefs("basemap_source", "carto", "carto_map_style", "dark_matter"); }
@Test public void shouldMigrateAdminSettings() { prefs = AdminSharedPreferences.getInstance().getSharedPreferences(); initPrefs("unrelated", "value"); PrefMigrator.migrateSharedPrefs(); assertPrefs("unrelated", "value"); initPrefs("show_map_sdk", true); PrefMigrator.migrateSharedPrefs(); assertPrefs("show_map_sdk", true); initPrefs("show_map_sdk", false); PrefMigrator.migrateSharedPrefs(); assertPrefs("maps", false); initPrefs("show_map_basemap", true); PrefMigrator.migrateSharedPrefs(); assertPrefs("show_map_basemap", true); initPrefs("show_map_basemap", false); PrefMigrator.migrateSharedPrefs(); assertPrefs("maps", false); }