LiquibaseMigrationWatcher implements ChangeExecListener { public ChangeSet getCurrentVersion() { return lastVersion; } LiquibaseMigrationWatcher(final List<ChangeSetStatus> changesets); @Override void willRun(final ChangeSet changeSet,
                        final DatabaseChangeLog databaseChangeLog,
                        final Database database,
                        final RunStatus runStatus); @Override void ran(final ChangeSet changeSet,
                    final DatabaseChangeLog databaseChangeLog,
                    final Database database,
                    final ExecType execType); @Override void rolledBack(final ChangeSet changeSet,
                           final DatabaseChangeLog databaseChangeLog,
                           final Database database); @Override void preconditionFailed(final PreconditionFailedException error,
                                   final FailOption onFail); @Override void preconditionErrored(final PreconditionErrorException error,
                                    final ErrorOption onError); @Override void willRun(final Change change,
                        final ChangeSet changeSet,
                        final DatabaseChangeLog changeLog,
                        final Database database); @Override void ran(final Change change,
                    final ChangeSet changeSet,
                    final DatabaseChangeLog changeLog,
                    final Database database); @Override void runFailed(final ChangeSet changeSet,
                          final DatabaseChangeLog databaseChangeLog,
                          final Database database,
                          final Exception exception); Boolean isMigrated(); ChangeSet getCurrentVersion();  }
@Test public void testConstructorWithNoChangesets() { List<ChangeSetStatus> changeSets = new ArrayList<>(); LiquibaseMigrationWatcher w = new LiquibaseMigrationWatcher(changeSets); assertNull(w.getCurrentVersion()); }
@Test public void testConstructorWithRunChangesets() { ChangeSet mockSet = Mockito.mock(ChangeSet.class); ChangeSetStatus mockStatus = Mockito.mock(ChangeSetStatus.class); Mockito.doReturn(true).when(mockStatus).getPreviouslyRan(); Mockito.doReturn(mockSet).when(mockStatus).getChangeSet(); List<ChangeSetStatus> changeSets = new ArrayList<>(); changeSets.add(mockStatus); LiquibaseMigrationWatcher w = new LiquibaseMigrationWatcher(changeSets); assertSame(mockSet, w.getCurrentVersion()); }
@Test public void testConstructorWithUnrunChangesets() { ChangeSet mockSet = Mockito.mock(ChangeSet.class); ChangeSetStatus mockStatus = Mockito.mock(ChangeSetStatus.class); Mockito.doReturn(false).when(mockStatus).getPreviouslyRan(); Mockito.doReturn(mockSet).when(mockStatus).getChangeSet(); List<ChangeSetStatus> changeSets = new ArrayList<>(); changeSets.add(mockStatus); LiquibaseMigrationWatcher w = new LiquibaseMigrationWatcher(changeSets); assertNull(w.getCurrentVersion()); }
@Test public void testConstructorReturnsLastRunChangSet() { List<ChangeSetStatus> changeSets = new ArrayList<>(); for (int i = 0; i < 10; i++) { ChangeSet mockSet = Mockito.mock(ChangeSet.class); ChangeSetStatus mockStatus = Mockito.mock(ChangeSetStatus.class); Mockito.doReturn(true).when(mockStatus).getPreviouslyRan(); Mockito.doReturn(mockSet).when(mockStatus).getChangeSet(); changeSets.add(mockStatus); } ChangeSet lastSet = changeSets.get(changeSets.size() - 1) .getChangeSet(); for (int i = 0; i < 10; i++) { ChangeSet mockSet = Mockito.mock(ChangeSet.class); ChangeSetStatus mockStatus = Mockito.mock(ChangeSetStatus.class); Mockito.doReturn(false).when(mockStatus).getPreviouslyRan(); Mockito.doReturn(mockSet).when(mockStatus).getChangeSet(); changeSets.add(mockStatus); } LiquibaseMigrationWatcher w = new LiquibaseMigrationWatcher(changeSets); assertSame(lastSet, w.getCurrentVersion()); }