### Question:
HdfsOperations { public void uploadActionDataToHDFS(final Configuration launcherJobConf, final Path actionDir, final Map<String, String> actionData) throws IOException, InterruptedException { Path finalPath = new Path(actionDir, LauncherAM.ACTION_DATA_SEQUENCE_FILE); System.out.println("Oozie Launcher, uploading action data to HDFS sequence file: " + finalPath.toUri()); try (SequenceFile.Writer wr = seqFileWriterFactory.createSequenceFileWriter(launcherJobConf, finalPath, Text.class, Text.class)) { if (wr != null) { for (Entry<String, String> entry : actionData.entrySet()) { wr.append(new Text(entry.getKey()), new Text(entry.getValue())); } } else { throw new IOException("SequenceFile.Writer is null for " + finalPath); } } } HdfsOperations(SequenceFileWriterFactory seqFileWriterFactory); void uploadActionDataToHDFS(final Configuration launcherJobConf, final Path actionDir,
                                       final Map<String, String> actionData); boolean fileExists(final Path path, final Configuration launcherJobConf); void writeStringToFile(final Path path, final Configuration conf, final String contents); String readFileContents(final Path path, final Configuration conf);  }### Answer:
@Test public void testActionDataUploadToHdfsSucceeds() throws Exception { hdfsOperations.uploadActionDataToHDFS(configurationMock, path, actionData); verify(seqFileWriterFactoryMock).createSequenceFileWriter(eq(configurationMock), any(Path.class), eq(Text.class), eq(Text.class)); ArgumentCaptor<Text> keyCaptor = ArgumentCaptor.forClass(Text.class); ArgumentCaptor<Text> valueCaptor = ArgumentCaptor.forClass(Text.class); verify(writerMock).append(keyCaptor.capture(), valueCaptor.capture()); assertEquals("testKey", keyCaptor.getValue().toString()); assertEquals("testValue", valueCaptor.getValue().toString()); }
@Test(expected = IOException.class) public void testActionDataUploadToHdfsFailsWhenAppendingToWriter() throws Exception { willThrow(new IOException()).given(writerMock).append(any(Text.class), any(Text.class)); hdfsOperations.uploadActionDataToHDFS(configurationMock, path, actionData); }
@Test(expected = IOException.class) public void testActionDataUploadToHdfsFailsWhenWriterIsNull() throws Exception { given(seqFileWriterFactoryMock.createSequenceFileWriter(eq(configurationMock), any(Path.class), eq(Text.class), eq(Text.class))).willReturn(null); hdfsOperations.uploadActionDataToHDFS(configurationMock, path, actionData); }