### Question:
CommonOptions { private void handleAdditionalBuildCommands() throws IOException { if (additionalBuildCommandsPath != null) { if (!Files.isRegularFile(additionalBuildCommandsPath)) { throw new FileNotFoundException(Utils.getMessage("IMG-0030", additionalBuildCommandsPath)); } AdditionalBuildCommands additionalBuildCommands = AdditionalBuildCommands.load(additionalBuildCommandsPath); dockerfileOptions.setAdditionalBuildCommands(additionalBuildCommands.getContents()); } if (additionalBuildFiles != null) { Files.createDirectory(Paths.get(getTempDirectory(), FILESFOLDER)); for (Path additionalFile : additionalBuildFiles) { if (!Files.isReadable(additionalFile)) { throw new FileNotFoundException(Utils.getMessage("IMG-0030", additionalFile)); } Path targetFile = Paths.get(getTempDirectory(), FILESFOLDER, additionalFile.getFileName().toString()); logger.info("IMG-0043", additionalFile); if (Files.isDirectory(additionalFile)) { Utils.copyLocalDirectory(additionalFile, targetFile, false); } else { Utils.copyLocalFile(additionalFile, targetFile, false); } } } }  void copyOptionsFromImage(String fromImage, String tmpDir);  }### Answer:
@Test void handleAdditionalBuildCommands(@TempDir File buildDir) throws Exception { CreateImage createImage = new CreateImage(); createImage.setTempDirectory(buildDir.getAbsolutePath()); Field optionsField = CommonOptions.class.getDeclaredField("dockerfileOptions"); optionsField.setAccessible(true); DockerfileOptions dockerfile = new DockerfileOptions("testbuildid"); optionsField.set(createImage, dockerfile); Field commandsField = CommonOptions.class.getDeclaredField("additionalBuildCommandsPath"); commandsField.setAccessible(true); Path additionalBuildCommandsFile = Paths.get("./src/test/resources/additionalBuildCommands/two-sections.txt"); commandsField.set(createImage, additionalBuildCommandsFile); Field buildFiles = CommonOptions.class.getDeclaredField("additionalBuildFiles"); buildFiles.setAccessible(true); List<Path> buildFilesList = new ArrayList<>(); buildFilesList.add(Paths.get("./src/test/resources/buildFilesDir")); buildFiles.set(createImage, buildFilesList); LoggingFacade logger = LoggingFactory.getLogger(CachedFile.class); Level oldLevel = logger.getLevel(); logger.setLevel(Level.WARNING); try { Method chownMethod = CommonOptions.class.getDeclaredMethod("handleAdditionalBuildCommands"); chownMethod.setAccessible(true); chownMethod.invoke(createImage); } finally { logger.setLevel(oldLevel); } List<String> additionalCommands = dockerfile.beforeJdkInstall(); assertEquals(2, additionalCommands.size(), "There should be 2 additional build commands"); assertEquals("RUN ls -al /u01", additionalCommands.get(1), "The 2nd additional command that was loaded did not match expected value."); try (Stream<Path> walk = Files.walk(Paths.get(buildDir + "/files"))) { List<String> fileList = walk.filter(Files::isRegularFile) .map(Path::toString).collect(Collectors.toList()); assertEquals(4, fileList.size(), "Should have copied 4 files: " + fileList); } catch (IOException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } try (Stream<Path> walk = Files.walk(Paths.get(buildDir + "/files"))) { List<String> dirList = walk.filter(Files::isDirectory) .map(Path::toString).collect(Collectors.toList()); assertEquals(4, dirList.size(), "There should be 4 directories: " + dirList); } catch (IOException e) { e.printStackTrace(); fail(e.getLocalizedMessage()); } }