### Question:
RawDataMigrator extends AbstractMigrationWorker implements CallableMigrationWorker { public void migrate() throws Exception { performMigration(Task.Migrate); } RawDataMigrator(DataMigratorConfiguration config); long estimate(); void migrate();  }### Answer:
@Test public void testMigrateTask() throws Exception { DatabaseType databaseType = DatabaseType.Oracle; DataMigratorConfiguration mockConfig = mock(DataMigratorConfiguration.class); when(mockConfig.getDatabaseType()).thenReturn(databaseType); Session mockCassandraSession = mock(Session.class); when(mockConfig.getSession()).thenReturn(mockCassandraSession); MetricsIndexMigrator mockMetricsIndexUpdateAccumulator = mock(MetricsIndexMigrator.class); PowerMockito.whenNew(MetricsIndexMigrator.class).withArguments(eq(MigrationTable.RAW), eq(mockConfig)) .thenReturn(mockMetricsIndexUpdateAccumulator); EntityManager mockEntityManager = mock(EntityManager.class); when(mockConfig.getEntityManager()).thenReturn(mockEntityManager); org.hibernate.Session mockHibernateSession = mock(org.hibernate.Session.class); when(mockEntityManager.getDelegate()).thenReturn(mockHibernateSession); SessionFactory mockSessionFactory = mock(SessionFactory.class); when(mockHibernateSession.getSessionFactory()).thenReturn(mockSessionFactory); StatelessSession mockStatelessSession = mock(StatelessSession.class); when(mockSessionFactory.openStatelessSession()).thenReturn(mockStatelessSession); org.hibernate.SQLQuery mockQuery = mock(org.hibernate.SQLQuery.class); when(mockStatelessSession.createSQLQuery(any(String.class))).thenReturn(mockQuery); when(mockQuery.uniqueResult()).thenReturn("1000"); ScrollableDataSource mockDataSource = mock(ScrollableDataSource.class); PowerMockito.whenNew(ScrollableDataSource.class).withArguments(eq(mockEntityManager), eq(databaseType), any()) .thenReturn(mockDataSource); List<Object[]> resultList = new ArrayList<Object[]>(); resultList.add(new Object[] { 100, 100, 100 }); resultList.add(new Object[] { 100, System.currentTimeMillis() - 100l, 100 }); for (int index = 0; index < 15; index++) { when(mockDataSource.getData(eq(0), anyInt())).thenReturn(resultList); when(mockDataSource.getData(eq(2), anyInt())).thenReturn(new ArrayList<Object[]>()); } ResultSetFuture mockResultSetFuture = mock(ResultSetFuture.class); when(mockCassandraSession.executeAsync(any(Query.class))).thenReturn(mockResultSetFuture); RawDataMigrator objectUnderTest = new RawDataMigrator(mockConfig); objectUnderTest.migrate(); PowerMockito.verifyNew(MetricsIndexMigrator.class).withArguments(eq(MigrationTable.RAW), eq(mockConfig)); PowerMockito.verifyNew(ScrollableDataSource.class, times(15)).withArguments(eq(mockEntityManager), eq(databaseType), any()); verify(mockDataSource, times(15)).initialize(); verify(mockDataSource, times(15)).getData(eq(0), anyInt()); verify(mockDataSource, times(15)).getData(eq(2), anyInt()); verify(mockDataSource, times(15)).close(); verify(mockMetricsIndexUpdateAccumulator, times(15)).add(eq(100), anyInt()); verify(mockMetricsIndexUpdateAccumulator, times(1)).drain(); verify(mockCassandraSession, times(15)).executeAsync(any(Query.class)); verify(mockResultSetFuture, times(15)).get(); verifyNoMoreInteractions(mockDataSource); verifyNoMoreInteractions(mockCassandraSession); verifyNoMoreInteractions(mockResultSetFuture); verifyNoMoreInteractions(mockMetricsIndexUpdateAccumulator); }