Migration { public void migrate(A artifact) { if (artifact.getDesignerVersion() == null || version.isGreaterThan(artifact.getDesignerVersion())) { logger.info(format("[MIGRATION] %s <%s> with id <%s> is being migrated from version <%s> to <%s>...", artifact.getClass().getSimpleName(), artifact.getName(), artifact.getId(), artifact.getDesignerVersion(), version)); for (MigrationStep<A> migrationStep : migrationSteps) { migrationStep.migrate(artifact); } artifact.setDesignerVersion(version.toString()); logger.info(format("[MIGRATION] %s <%s> version is now <%s>", artifact.getClass().getSimpleName(), artifact.getName(), version)); } } Migration(String version, MigrationStep<A>... migrationSteps); void migrate(A artifact);  }
@Test public void should_migrate_a_page_with_a_version_lower_than_migration() throws Exception { page.setDesignerVersion("1.0.0"); migration.migrate(page); verify(migrationStep).migrate(page); }
@Test public void should_not_migrate_a_page_with_a_version_greater_than_migration() throws Exception { page.setDesignerVersion("1.0.2"); migration.migrate(page); verify(migrationStep, never()).migrate(page); }
@Test public void should_not_migrate_a_page_with_a_version_equal_to_migration() throws Exception { page.setDesignerVersion("1.0.1"); migration.migrate(page); verify(migrationStep, never()).migrate(page); }