### Question:
RemitSyncToDBHelper { void endAndEnsureToDB(int id) { executor.removePostWithId(id); try { if (executor.isFreeToDatabase(id)) return; executor.postSync(id); } finally { executor.postRemoveFreeId(id); } } RemitSyncToDBHelper(@NonNull final RemitSyncExecutor.RemitAgent agent);   RemitSyncToDBHelper(@NonNull final RemitSyncExecutor executor);   }### Answer:
@Test public void endAndEnsureToDB() { when(executor.isFreeToDatabase(1)).thenReturn(true); helper.endAndEnsureToDB(1); verify(executor).removePostWithId(eq(1)); verify(executor).postRemoveFreeId(eq(1)); verify(executor, never()).postSync(eq(1)); when(executor.isFreeToDatabase(2)).thenReturn(false); helper.endAndEnsureToDB(2); verify(executor).postSync(eq(2)); verify(executor).postRemoveFreeId(eq(2)); }