### Question:
LocalFileCheckpointHandler implements CheckpointHandler { @Override public void saveCheckpoint(String checkpointName, byte[] checkpoint) throws IOException { writeCheckpoint(getCheckpointFilePath(checkpointName), checkpoint); } @VisibleForTesting  LocalFileCheckpointHandler(String directory, FileHelper fileHelper); @Override byte[] readCheckpoint(String checkpointName); @Override void saveCheckpoint(String checkpointName, byte[] checkpoint); static final String CONNECTOR_CHECKPOINT_DIRECTORY; }### Answer:
@Test public void testSaveCheckpointNotFile() throws IOException { LocalFileCheckpointHandler handler = new LocalFileCheckpointHandler("checkpointpath", mockFileHelper); when(mockCheckpointFile.isFile()).thenReturn(false); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("checkpoint file is not pointing to file"); handler.saveCheckpoint("test_checkpoint", golden); }
@Test public void testSaveCheckpointNullPayloadDeleteFile() throws IOException { LocalFileCheckpointHandler handler = new LocalFileCheckpointHandler("checkpointpath", mockFileHelper); handler.saveCheckpoint("test_checkpoint", null); verify(mockCheckpointFile).delete(); }
@Test public void testSaveCheckpointNullPayloadFileNotExist() throws IOException { LocalFileCheckpointHandler handler = new LocalFileCheckpointHandler("checkpointpath", mockFileHelper); when(mockCheckpointFile.exists()).thenReturn(false); handler.saveCheckpoint("test_checkpoint", null); InOrder inOrder = Mockito.inOrder(mockCheckpointFile); inOrder.verify(mockCheckpointFile).exists(); verifyNoMoreInteractions(mockCheckpointFile); }
@Test public void testSaveCheckpointGolden() throws IOException { LocalFileCheckpointHandler handler = new LocalFileCheckpointHandler("checkpointpath", mockFileHelper); when(mockCheckpointFile.exists()).thenReturn(false); handler.saveCheckpoint("test_checkpoint", golden); verify(mockFileHelper).writeFile(mockCheckpointFile, golden); }