### Question:
AggregateDataMigrator extends AbstractMigrationWorker implements CallableMigrationWorker { @Override public long estimate() throws Exception { long recordCount = this.getRowCount(this.countQuery); log.debug("Retrieved record count for table " + migrationTable.toString() + " -- " + recordCount); Telemetry telemetry = this.performMigration(Task.Estimate); long estimatedTimeToMigrate = telemetry.getMigrationTime(); long estimation = (recordCount / MAX_RECORDS_TO_LOAD_FROM_SQL / NUMBER_OF_BATCHES_FOR_ESTIMATION) * estimatedTimeToMigrate; estimation += telemetry.getNonMigrationTime(); return estimation; } AggregateDataMigrator(MigrationTable migrationTable, DataMigratorConfiguration config); @Override long estimate(); void migrate();  }### Answer:
@Test public void testEstimateTask() throws Exception { DatabaseType databaseType = DatabaseType.Oracle; DataMigratorConfiguration mockConfig = mock(DataMigratorConfiguration.class); when(mockConfig.getDatabaseType()).thenReturn(databaseType); MetricsIndexMigrator mockMetricsIndexUpdateAccumulator = mock(MetricsIndexMigrator.class); PowerMockito.whenNew(MetricsIndexMigrator.class) .withArguments(eq(MigrationTable.ONE_HOUR), 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(), anyInt()).thenReturn(mockDataSource); when(mockDataSource.getData(eq(0), anyInt())).thenReturn(new ArrayList<Object[]>()); AggregateDataMigrator objectUnderTest = new AggregateDataMigrator(MigrationTable.ONE_HOUR, mockConfig); long estimateActual = objectUnderTest.estimate(); PowerMockito.verifyNew(MetricsIndexMigrator.class).withArguments(eq(MigrationTable.ONE_HOUR), eq(mockConfig)); PowerMockito.verifyNew(ScrollableDataSource.class, times(1)).withArguments(eq(mockEntityManager), eq(databaseType), any(), anyInt()); verify(mockStatelessSession, times(1)).createSQLQuery(any(String.class)); verify(mockDataSource, times(1)).initialize(); verify(mockDataSource, times(1)).getData(eq(0), anyInt()); verify(mockDataSource, times(1)).close(); verify(mockMetricsIndexUpdateAccumulator, times(1)).drain(); verifyNoMoreInteractions(mockDataSource); verifyNoMoreInteractions(mockMetricsIndexUpdateAccumulator); Assert.assertNotEquals(estimateActual, 0); }