### Question:
BaseMigrationTasks { void validate(Collection<BaseTask> theTasks) { for (BaseTask task: theTasks) { task.validateVersion(); String version = task.getFlywayVersion(); MigrationVersion migrationVersion = MigrationVersion.fromVersion(version); if (lastVersion != null) { if (migrationVersion.compareTo(lastVersion) <= 0) { throw new IllegalStateException("Migration version " + migrationVersion + " found after migration version " + lastVersion + ". Migrations need to be in order by version number."); } } lastVersion = migrationVersion; } }  @SuppressWarnings("unchecked") List<BaseTask> getTasks(@Nonnull T theFrom, @Nonnull T theTo); Builder forVersion(T theRelease); List<BaseTask> getAllTasks(T[] theVersionEnumValues);  }### Answer:
@Test public void testValidateCorrectOrder() { MyMigrationTasks migrationTasks = new MyMigrationTasks(); List<BaseTask> tasks = new ArrayList<>(); tasks.add(new DropTableTask("1", "20191029.1")); tasks.add(new DropTableTask("1", "20191029.2")); migrationTasks.validate(tasks); }
@Test public void testValidateVersionWrongOrder() { MyMigrationTasks migrationTasks = new MyMigrationTasks(); List<BaseTask> tasks = new ArrayList<>(); tasks.add(new DropTableTask("1", "20191029.2")); tasks.add(new DropTableTask("1", "20191029.1")); try { migrationTasks.validate(tasks); fail(); } catch (IllegalStateException e) { assertEquals("Migration version 1.20191029.1 found after migration version 1.20191029.2. Migrations need to be in order by version number.", e.getMessage()); } }
@Test public void testValidateSameVersion() { MyMigrationTasks migrationTasks = new MyMigrationTasks(); List<BaseTask> tasks = new ArrayList<>(); tasks.add(new DropTableTask("1", "20191029.1")); tasks.add(new DropTableTask("1", "20191029.1")); try { migrationTasks.validate(tasks); fail(); } catch (IllegalStateException e) { assertEquals("Migration version 1.20191029.1 found after migration version 1.20191029.1. Migrations need to be in order by version number.", e.getMessage()); } }
@Test public void testValidateWrongDateOrder() { MyMigrationTasks migrationTasks = new MyMigrationTasks(); List<BaseTask> tasks = new ArrayList<>(); tasks.add(new DropTableTask("1", "20191029.1")); tasks.add(new DropTableTask("1", "20191028.1")); try { migrationTasks.validate(tasks); fail(); } catch (IllegalStateException e) { assertEquals("Migration version 1.20191028.1 found after migration version 1.20191029.1. Migrations need to be in order by version number.", e.getMessage()); } }