### Question:
OptionsAccessor { public Placemark getDefaultPlacemark() { PreferencesRegistry registry = myToolbox.getPreferencesRegistry(); Preferences preferences = registry.getPreferences(OptionsAccessor.class); Placemark placemark = new Placemark(); String kmlString = preferences.getString(DEFAULT_PLACES_PROP, null); if (kmlString != null) { Kml kml = KmlMarshaller.getInstance().unmarshal(kmlString); Feature feature = kml.getFeature(); if (feature instanceof Document) { Document document = (Document)feature; List<Feature> features = document.getFeature(); if (!features.isEmpty()) { Feature aFeature = features.get(0); if (aFeature instanceof Folder) { Folder folder = (Folder)aFeature; List<Feature> folderFeatures = folder.getFeature(); if (!folderFeatures.isEmpty()) { Feature firstFeature = folderFeatures.get(0); if (firstFeature instanceof Placemark) { placemark = (Placemark)firstFeature; } } } } } } Color color = PlacemarkUtils.getPlacemarkTextColor(placemark); if (color == null) { PlacemarkUtils.setPlacemarkTextColor(placemark, Color.white); } color = PlacemarkUtils.getPlacemarkColor(placemark, null); if (color == null) { PlacemarkUtils.setPlacemarkColor(placemark, Color.gray); } if (placemark.getExtendedData() == null) { ExtendedData extendedData = placemark.createAndSetExtendedData(); ExtendedDataUtils.putBoolean(extendedData, Constants.IS_TITLE, true); Font defaultFont = PlacemarkUtils.DEFAULT_FONT; PlacemarkUtils.setPlacemarkFont(placemark, defaultFont); } ensureExists(placemark.getExtendedData(), Constants.IS_BUBBLE_FILLED_ID); ExtendedDataUtils.putBoolean(placemark.getExtendedData(), Constants.IS_FEATURE_ON_ID, true); Placemark newPoint = new Placemark(); PlacemarkUtils.copyPlacemark(placemark, newPoint); newPoint.setId(UUID.randomUUID().toString()); return newPoint; } OptionsAccessor(Toolbox toolbox); Placemark getDefaultPlacemark(); void saveDefaultPlacemark(Placemark placemark); static final String DEFAULT_PLACES_PROP; }### Answer:
@Test public void testDefault() { EasyMockSupport support = new EasyMockSupport(); Toolbox toolbox = createToolbox(support, ""); support.replayAll(); OptionsAccessor accessor = new OptionsAccessor(toolbox); Placemark placemark = accessor.getDefaultPlacemark(); IconStyle iconStyle = null; for (StyleSelector selector : placemark.getStyleSelector()) { if (selector instanceof Style) { Style style = (Style)selector; iconStyle = style.getIconStyle(); break; } } assertNotNull(iconStyle); assertNotNull(ExtendedDataUtils.getString(placemark.getExtendedData(), Constants.IS_BUBBLE_FILLED_ID)); assertTrue(Boolean.parseBoolean(ExtendedDataUtils.getString(placemark.getExtendedData(), Constants.IS_FEATURE_ON_ID))); support.verifyAll(); }
@Test public void testDotOff() { EasyMockSupport support = new EasyMockSupport(); Toolbox toolbox = createToolbox(support, "<Data name=\"isDotOn\"><value>false</value></Data>"); support.replayAll(); OptionsAccessor accessor = new OptionsAccessor(toolbox); Placemark placemark = accessor.getDefaultPlacemark(); IconStyle iconStyle = null; for (StyleSelector selector : placemark.getStyleSelector()) { if (selector instanceof Style) { Style style = (Style)selector; iconStyle = style.getIconStyle(); break; } } assertNotNull(iconStyle); assertNotNull(ExtendedDataUtils.getString(placemark.getExtendedData(), Constants.IS_BUBBLE_FILLED_ID)); assertTrue(Boolean.parseBoolean(ExtendedDataUtils.getString(placemark.getExtendedData(), Constants.IS_FEATURE_ON_ID))); support.verifyAll(); }