### Question:
DestructiveReplication implements Replication { @Override public void replicate() throws CircusTrainException { try { if (!destructiveReplica.tableIsUnderCircusTrainControl()) { throw new CircusTrainException("Replica table '" + tableReplication.getQualifiedReplicaName() + "' is not controlled by circus train aborting replication, check configuration for correct replica name"); } if (destructiveSource.tableExists()) { destructiveReplica.dropDeletedPartitions(destructiveSource.getPartitionNames()); Replication replication = upsertReplicationFactory.newInstance(tableReplication); replication.replicate(); } else { destructiveReplica.dropTable(); } } catch (TException e) { throw new CircusTrainException(e); } } DestructiveReplication(
      ReplicationFactoryImpl upsertReplicationFactory,
      TableReplication tableReplication,
      String eventId,
      DestructiveSource destructiveSource,
      DestructiveReplica destructiveReplica); @Override void replicate(); @Override String name(); @Override String getEventId();  }### Answer:
@Test public void replicateTableExists() throws Exception { when(destructiveReplica.tableIsUnderCircusTrainControl()).thenReturn(true); when(destructiveSource.tableExists()).thenReturn(true); when(upsertReplicationFactory.newInstance(tableReplication)).thenReturn(normalReplication); when(destructiveSource.getPartitionNames()).thenReturn(sourcePartitionNames); replication.replicate(); verify(destructiveReplica).dropDeletedPartitions(sourcePartitionNames); verify(normalReplication).replicate(); }
@Test public void replicateTableDoesNotExists() throws Exception { when(destructiveReplica.tableIsUnderCircusTrainControl()).thenReturn(true); when(destructiveSource.tableExists()).thenReturn(false); replication.replicate(); verifyZeroInteractions(upsertReplicationFactory); verify(destructiveReplica).dropTable(); }
@Test(expected = CircusTrainException.class) public void replicateNotCircusTrainTable() throws Exception { when(destructiveReplica.tableIsUnderCircusTrainControl()).thenReturn(false); replication.replicate(); }
@Test(expected = CircusTrainException.class) public void replicateExceptionsWrapped() throws Exception { when(destructiveReplica.tableIsUnderCircusTrainControl()).thenThrow(new TException()); replication.replicate(); }