### Question:
DataMigrationManagerImpl implements DataMigrationManager { @Override public void resetToVersion( final String pluginName, final int version ) { Preconditions.checkNotNull( pluginName, "pluginName cannot be null" ); final MigrationPlugin plugin = migrationPlugins.get( pluginName ); Preconditions.checkArgument( plugin != null, "Plugin " + pluginName + " could not be found" ); final int highestAllowed = plugin.getMaxVersion(); Preconditions.checkArgument( version <= highestAllowed, "You cannot set a version higher than the max of " + highestAllowed + " for plugin " + pluginName ); Preconditions.checkArgument( version >= 0, "You must specify a version of 0 or greater" ); migrationInfoSerialization.setVersion( pluginName, version ); migrationInfoCache.invalidateAll(); } @Inject  DataMigrationManagerImpl( final Set<MigrationPlugin> plugins,
                                     final MigrationInfoSerialization migrationInfoSerialization,
                                     final MigrationInfoCache migrationInfoCache
    ); @Override boolean pluginExists(final String name); @Override void migrate(final String name); @Override void migrate(); @Override boolean isRunning(); @Override int getCurrentVersion( final String pluginName ); @Override void resetToVersion( final String pluginName, final int version ); @Override String getLastStatus( final String pluginName ); @Override Set<String> getPluginNames(); List<MigrationPlugin> getExecutionOrder();  }### Answer:
@Test public void testResetToVersion() { final String name = "plugin1"; final int version = 10; final Set<MigrationPlugin> plugins = new LinkedHashSet<>(); MigrationPlugin plugin1 = mock( MigrationPlugin.class ); when( plugin1.getPhase() ).thenReturn( PluginPhase.MIGRATE ); when( plugin1.getName() ).thenReturn( name ); when( plugin1.getMaxVersion() ).thenReturn( version ); plugins.add( plugin1 ); final MigrationInfoSerialization migrationInfoSerialization = mock( MigrationInfoSerialization.class ); final MigrationInfoCache migrationInfoCache = mock(MigrationInfoCache.class); DataMigrationManagerImpl migrationManager = new DataMigrationManagerImpl( plugins, migrationInfoSerialization, migrationInfoCache ); migrationManager.resetToVersion( name, 0 ); verify( migrationInfoSerialization ).setVersion( name, 0 ); migrationManager.resetToVersion( name, version ); verify( migrationInfoSerialization ).setVersion( name, version ); }
@Test( expected = IllegalArgumentException.class ) public void testResetToInvalidVersions() { final String name = "plugin1"; final int version = 10; final Set<MigrationPlugin> plugins = new LinkedHashSet<>(); MigrationPlugin plugin1 = mock( MigrationPlugin.class ); when( plugin1.getPhase() ).thenReturn( PluginPhase.MIGRATE ); when( plugin1.getName() ).thenReturn( name ); when( plugin1.getMaxVersion() ).thenReturn( version ); plugins.add( plugin1 ); final MigrationInfoSerialization migrationInfoSerialization = mock( MigrationInfoSerialization.class ); final MigrationInfoCache migrationInfoCache = mock(MigrationInfoCache.class); DataMigrationManagerImpl migrationManager = new DataMigrationManagerImpl( plugins, migrationInfoSerialization, migrationInfoCache ); migrationManager.resetToVersion( name, version + 1 ); }
@Test( expected = IllegalArgumentException.class ) public void testResetInvalidName() { final String name = "plugin1"; final int version = 10; final Set<MigrationPlugin> plugins = new LinkedHashSet<>(); MigrationPlugin plugin1 = mock( MigrationPlugin.class ); when( plugin1.getPhase() ).thenReturn( PluginPhase.MIGRATE ); when( plugin1.getName() ).thenReturn( name ); when( plugin1.getMaxVersion() ).thenReturn( version ); plugins.add( plugin1 ); final MigrationInfoSerialization migrationInfoSerialization = mock( MigrationInfoSerialization.class ); final MigrationInfoCache migrationInfoCache = mock(MigrationInfoCache.class); DataMigrationManagerImpl migrationManager = new DataMigrationManagerImpl( plugins, migrationInfoSerialization, migrationInfoCache ); migrationManager.resetToVersion( name + "foo", version ); }