### Question:
DataStoreHelper { public static <T extends DataObject> Optional<T> removeIfExists(LogicalDatastoreType store, InstanceIdentifier<T> path, ReadWriteTransaction rwTx) { Optional<T> potentialResult = readFromDs(store, path, rwTx); if (potentialResult.isPresent()) { rwTx.delete(store, path); } return potentialResult; }  static Optional<T> readFromDs(LogicalDatastoreType store, InstanceIdentifier<T> path, ReadTransaction rTx); static boolean submitToDs(WriteTransaction wTx); static Optional<T> removeIfExists(LogicalDatastoreType store, InstanceIdentifier<T> path,
            ReadWriteTransaction rwTx);  }### Answer:
@Test public void testRemoveIfExists() throws Exception { Optional<?> optional = mock(Optional.class); when(optional.isPresent()).thenReturn(true); when(readFuture.checkedGet()).thenReturn((Optional) optional); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, mock(InstanceIdentifier.class), readWriteTransaction); verify(readWriteTransaction).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)); }
@Test public void testRemoveIfExists_NotExisting() throws Exception { Optional<?> optional = mock(Optional.class); when(optional.isPresent()).thenReturn(false); when(readFuture.checkedGet()).thenReturn((Optional) optional); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, mock(InstanceIdentifier.class), readWriteTransaction); verify(readWriteTransaction, never()).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)); }