### Question:
MigraterYamlFileResource extends YamlFileResource { @Override public void exportProperties(ConfigurationData configurationData) { try (FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter writer = new OutputStreamWriter(fos, CHARSET)) { PropertyPathTraverser pathTraverser = new PropertyPathTraverser(configurationData); for (Property<?> property : convertPropertiesToExportableTypes(configurationData.getProperties())) { List<PropertyPathTraverser.PathElement> pathElements = pathTraverser.getPathElements(property); for (PropertyPathTraverser.PathElement pathElement : pathElements) { writeComments(writer, pathElement.indentationLevel, pathElement.comments); writer.append("\n") .append(indent(pathElement.indentationLevel)) .append(pathElement.name) .append(":"); } writer.append(" ") .append(toYaml(property, pathElements.get(pathElements.size() - 1).indentationLevel)); } writer.flush(); writer.close(); } catch (IOException e) { throw new ConfigMeException("Could not save config to '" + file.getPath() + "'", e); } finally { singleQuoteYaml = null; } } MigraterYamlFileResource(File file); @Override void exportProperties(ConfigurationData configurationData);  }### Answer:
@Test public void shouldWriteWithCorrectCharset() throws IOException { File file = temporaryFolder.newFile(); Files.copy(TestHelper.getJarFile(CHINESE_MESSAGES_FILE), file); MigraterYamlFileResource resource = new MigraterYamlFileResource(file); String newMessage = "您当前并没有任何邮箱与该账号绑定"; resource.setValue("third", newMessage); resource.exportProperties(buildConfigurationData()); resource = new MigraterYamlFileResource(file); assertThat(resource.getString("first"), equalTo("错误的密码")); assertThat(resource.getString("second"), equalTo("为了验证您的身份，您需要将一个电子邮件地址与您的帐户绑定！")); assertThat(resource.getString("third"), equalTo(newMessage)); }