### Question:
Migrator { public void migrate(ConfigurationProvider provider, PreferencesRegistry registry) { Preferences newPreferences = registry.getPreferences(MantleConstants.USER_DATE_FORMAT_CONFIG_FILE_TOPIC); boolean alreadyMigrated = newPreferences.getBoolean(ourMigratedKey, false); if (!alreadyMigrated) { Preferences preferences = registry.getPreferences("DateFormatConfiguration"); DateFormatsConfig oldConfig = preferences.getJAXBObject(DateFormatsConfig.class, MantleConstants.USER_DATE_FORMAT_CONFIG_FILE_KEY, null); DateFormatsConfig newConfig = provider.getDateFormats(); List<DateFormat> formatsToAdd = New.list(); if (oldConfig != null) { Map<String, DateFormat> formats = mapFormats(newConfig); for (DateFormat format : oldConfig.getFormats()) { if (!formats.containsKey(format.getSdf())) { boolean isValid = isFormatValid(format); if (isValid) { formatsToAdd.add(format); } } } if (!formatsToAdd.isEmpty()) { provider.saveFormats(formatsToAdd); } } newPreferences.putBoolean(ourMigratedKey, true, this); } }  void migrate(ConfigurationProvider provider, PreferencesRegistry registry);  }### Answer:
@Test public void testMigrateNewInstall() { EasyMockSupport support = new EasyMockSupport(); ConfigurationProvider provider = createProvider(support, createNewFormats()); PreferencesRegistry registry = createRegistry(support, null, false); support.replayAll(); Migrator migrator = new Migrator(); migrator.migrate(provider, registry); support.verifyAll(); }
@SuppressWarnings("unchecked") @Test public void testMigrate() { EasyMockSupport support = new EasyMockSupport(); ConfigurationProvider provider = createProvider(support, createNewFormats()); provider.saveFormats(EasyMock.isA(Collection.class)); EasyMock.expectLastCall().andAnswer(new IAnswer<Void>() { @Override public Void answer() { Collection<DateFormat> savedFormats = (Collection<DateFormat>)EasyMock.getCurrentArguments()[0]; assertSavedFormats(savedFormats); return null; } }); PreferencesRegistry registry = createRegistry(support, createOldFormats(), false); support.replayAll(); Migrator migrator = new Migrator(); migrator.migrate(provider, registry); support.verifyAll(); }
@Test public void testAlreadyMigrated() { EasyMockSupport support = new EasyMockSupport(); ConfigurationProvider provider = support.createMock(ConfigurationProvider.class); PreferencesRegistry registry = createRegistry(support, null, true); support.replayAll(); Migrator migrator = new Migrator(); migrator.migrate(provider, registry); support.verifyAll(); }