@Test
public void testWriteCommandToTempFile() throws Exception {

  String absRoot = TEST_ROOT_DIR.getAbsolutePath();
  ApplicationId appId = ApplicationId.newInstance(1, 1);
  ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1);
  ContainerId cid = ContainerId.newContainerId(attemptId, 1);
  DockerCommand dockerCmd = new DockerInspectCommand(cid.toString());
  Configuration conf = new Configuration();
  conf.set("hadoop.tmp.dir", absRoot);
  conf.set(YarnConfiguration.NM_LOCAL_DIRS, absRoot);
  conf.set(YarnConfiguration.NM_LOG_DIRS, absRoot);
  LocalDirsHandlerService dirsHandler = new LocalDirsHandlerService();
  Context mockContext = mock(Context.class);
  doReturn(conf).when(mockContext).getConf();
  doReturn(dirsHandler).when(mockContext).getLocalDirsHandler();
  DockerClient dockerClient = new DockerClient();
  dirsHandler.init(conf);
  dirsHandler.start();
  String tmpPath = dockerClient.writeCommandToTempFile(dockerCmd, cid,
      mockContext);
  dirsHandler.stop();
  File tmpFile = new File(tmpPath);
  assertTrue(tmpFile + " was not created", tmpFile.exists());
}