WidgetMigrationApplyer { public Widget migrate(Widget widget) { long startTime = System.currentTimeMillis(); String formerArtifactVersion = widget.getDesignerVersion(); for (Migration<Widget> migration : migrationList) { migration.migrate(widget); } if (!StringUtils.equals(formerArtifactVersion, widget.getDesignerVersion())) { widget.setPreviousDesignerVersion(formerArtifactVersion); logger.info(format("[MIGRATION] Widget %s has been terminated in %s seconds !", widget.getName(),(System.currentTimeMillis() - startTime)/ 1000.0f)); } return widget; } WidgetMigrationApplyer(List<Migration<Widget>> widgetMigrationStepsList); Widget migrate(Widget widget);  }
@Test public void should_migrate_a_widget(){ Migration<Widget> migrations = new Migration("1.2.0", mock(MigrationStep.class)); WidgetMigrationApplyer widgetMigrationApplyer = new WidgetMigrationApplyer(Collections.singletonList(migrations)); Widget widget = WidgetBuilder.aWidget().id("customWidget").version("1.0.1").previousDesignerVersion("1.0.1").build(); widgetMigrationApplyer.migrate(widget); Assert.assertEquals(widget.getPreviousDesignerVersion(),"1.0.1"); Assert.assertEquals(widget.getDesignerVersion(),"1.2.0"); Assert.assertEquals(widget.getDesignerVersion(),"1.2.0"); }
@Test public void should_not_modify_previous_designer_version_when_no_migration_done_on_widget(){ Migration<Widget> migrations = new Migration("1.0.2", mock(MigrationStep.class)); WidgetMigrationApplyer widgetMigrationApplyer = new WidgetMigrationApplyer(Collections.singletonList(migrations)); Widget widget = WidgetBuilder.aWidget().id("customWidget").version("1.0.2").previousDesignerVersion("1.0.2").build(); widgetMigrationApplyer.migrate(widget); Assert.assertEquals(widget.getPreviousDesignerVersion(),"1.0.2"); Assert.assertEquals(widget.getDesignerVersion(),"1.0.2"); }