### Question:
ContainerDataYaml { public static void createContainerFile(ContainerType containerType, ContainerData containerData, File containerFile) throws IOException { Writer writer = null; FileOutputStream out = null; try { Yaml yaml = getYamlForContainerType(containerType); containerData.computeAndSetChecksum(yaml); out = new FileOutputStream( containerFile); writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); yaml.dump(containerData, writer); } finally { try { if (writer != null) { writer.flush(); out.getFD().sync(); writer.close(); } } catch (IOException ex) { LOG.warn("Error occurred during closing the writer. ContainerID: " + containerData.getContainerID()); } IOUtils.closeQuietly(out); } } private  ContainerDataYaml(); static void createContainerFile(ContainerType containerType,
      ContainerData containerData, File containerFile); static ContainerData readContainerFile(File containerFile); static ContainerData readContainer(byte[] containerFileContent); static ContainerData readContainer(InputStream input); static Yaml getYamlForContainerType(ContainerType containerType);  }### Answer:
@Test public void testCreateContainerFile() throws IOException { long containerID = testContainerID++; File containerFile = createContainerFile(containerID); KeyValueContainerData kvData = (KeyValueContainerData) ContainerDataYaml .readContainerFile(containerFile); assertEquals(containerID, kvData.getContainerID()); assertEquals(ContainerProtos.ContainerType.KeyValueContainer, kvData .getContainerType()); assertEquals(CONTAINER_DB_TYPE, kvData.getContainerDBType()); assertEquals(containerFile.getParent(), kvData.getMetadataPath()); assertEquals(containerFile.getParent(), kvData.getChunksPath()); assertEquals(ContainerProtos.ContainerDataProto.State.OPEN, kvData .getState()); assertEquals(layout, kvData.getLayOutVersion()); assertEquals(0, kvData.getMetadata().size()); assertEquals(MAXSIZE, kvData.getMaxSize()); assertEquals(MAXSIZE, kvData.getMaxSize()); assertTrue(kvData.lastDataScanTime().isPresent()); assertEquals(SCAN_TIME, kvData.lastDataScanTime().get()); assertEquals(SCAN_TIME.toEpochMilli(), kvData.getDataScanTimestamp().longValue()); assertEquals(OzoneConsts.SCHEMA_LATEST, kvData.getSchemaVersion()); kvData.addMetadata(OzoneConsts.VOLUME, VOLUME_OWNER); kvData.addMetadata(OzoneConsts.OWNER, OzoneConsts.OZONE); kvData.setState(ContainerProtos.ContainerDataProto.State.CLOSED); ContainerDataYaml.createContainerFile(ContainerProtos.ContainerType .KeyValueContainer, kvData, containerFile); kvData = (KeyValueContainerData) ContainerDataYaml.readContainerFile( containerFile); assertEquals(containerID, kvData.getContainerID()); assertEquals(ContainerProtos.ContainerType.KeyValueContainer, kvData .getContainerType()); assertEquals(CONTAINER_DB_TYPE, kvData.getContainerDBType()); assertEquals(containerFile.getParent(), kvData.getMetadataPath()); assertEquals(containerFile.getParent(), kvData.getChunksPath()); assertEquals(ContainerProtos.ContainerDataProto.State.CLOSED, kvData .getState()); assertEquals(layout, kvData.getLayOutVersion()); assertEquals(2, kvData.getMetadata().size()); assertEquals(VOLUME_OWNER, kvData.getMetadata().get(OzoneConsts.VOLUME)); assertEquals(OzoneConsts.OZONE, kvData.getMetadata().get(OzoneConsts.OWNER)); assertEquals(MAXSIZE, kvData.getMaxSize()); assertTrue(kvData.lastDataScanTime().isPresent()); assertEquals(SCAN_TIME, kvData.lastDataScanTime().get()); assertEquals(SCAN_TIME.toEpochMilli(), kvData.getDataScanTimestamp().longValue()); }