### Question:
Source extends HiveEndpoint { @Override public PartitionsAndStatistics getPartitions(Table sourceTable, String partitionPredicate, int maxPartitions) throws TException { PartitionsAndStatistics sourcePartitions = super.getPartitions(sourceTable, partitionPredicate, maxPartitions); sourceCatalogListener .resolvedSourcePartitions(EventUtils.toEventPartitions(sourceTable, sourcePartitions.getPartitions())); return sourcePartitions; } Source(
      SourceCatalog sourceCatalog,
      HiveConf sourceHiveConf,
      Supplier<CloseableMetaStoreClient> sourceMetaStoreClientSupplier,
      SourceCatalogListener sourceCatalogListener,
      boolean snapshotsDisabled,
      String sourceTableLocation); @Override TableAndStatistics getTableAndStatistics(String database, String table); @Override PartitionsAndStatistics getPartitions(Table sourceTable, String partitionPredicate, int maxPartitions); SourceLocationManager getLocationManager(Table table, String eventId); SourceLocationManager getLocationManager(
      Table table,
      List<Partition> partitions,
      String eventId,
      Map<String, Object> copierOptions); @Override TableAndStatistics getTableAndStatistics(TableReplication tableReplication);  }### Answer:
@Test public void getPartitions() throws Exception { when(metaStoreClient.listPartitionsByFilter(DATABASE, TABLE, PARTITION_PREDICATE, (short) MAX_PARTITIONS)) .thenReturn(partitions); when(metaStoreClient.getPartitionColumnStatistics(DATABASE, TABLE, PARTITION_NAMES, COLUMN_NAMES)) .thenReturn(partitionStatsMap); PartitionsAndStatistics partitionsAndStatistics = source.getPartitions(table, PARTITION_PREDICATE, MAX_PARTITIONS); assertThat(partitionsAndStatistics.getPartitions(), is(partitions)); assertThat(partitionsAndStatistics.getStatisticsForPartition(partition), is(partitionColumnStatistics)); }
@Test public void getPartitionsNoStats() throws Exception { when(metaStoreClient.listPartitionsByFilter(DATABASE, TABLE, PARTITION_PREDICATE, (short) MAX_PARTITIONS)) .thenReturn(partitions); when(metaStoreClient.getPartitionColumnStatistics(DATABASE, TABLE, PARTITION_NAMES, COLUMN_NAMES)) .thenReturn(Collections.<String, List<ColumnStatisticsObj>> emptyMap()); PartitionsAndStatistics partitionsAndStatistics = source.getPartitions(table, PARTITION_PREDICATE, MAX_PARTITIONS); assertThat(partitionsAndStatistics.getPartitions(), is(partitions)); assertThat(partitionsAndStatistics.getStatisticsForPartition(partition), is(nullValue())); }