### Question:
SettingsIO { public void write( Settings settings, File settingsFile ) throws ManipulationException { try { LineSeparator ls; String intro = ""; String outtro = ""; if ( settingsFile.length() > 0 ) { ls = FileIO.determineEOL( settingsFile ); ModelETLRequest request = new ModelETLRequest(); request.setLineSeparator( ls.value() ); ModelETL etl = modelETLFactories.newInstance( request ); etl.extract( settingsFile ); intro = (String) FieldUtils.getDeclaredField( JDomModelETL.class, "intro", true ).get( etl ); outtro = (String) FieldUtils.getDeclaredField( JDomModelETL.class, "outtro", true ).get( etl ); } else { ls = LineSeparator.NL; } jdomSettingsConverter.setLineSeparator( ls.value() ); jdomSettingsConverter.write( settings, settingsFile, intro, outtro); } catch ( IOException | JDOMException | ReleaseExecutionException | IllegalAccessException e ) { throw new ManipulationException( "Failed to create repo removal backup settings.xml file: {}", settingsFile, e ); } } @Inject  SettingsIO(SettingsBuilder settingsBuilder); void write( Settings settings, File settingsFile ); void update( Settings settings, File settingsFile );  }### Answer:
@Test public void verifyRoundTrip() throws IOException, ManipulationException { URL resource = SettingsIOTest.class.getResource( "settings.xml" ); assertNotNull( resource ); File originalSettingsFile = new File( resource.getFile() ); assertTrue( originalSettingsFile.exists() ); Settings settings = new DefaultSettingsReader().read( originalSettingsFile, Collections.emptyMap() ); assertNull( settings.getModelEncoding() ); File targetFile = folder.newFile( "settings.xml" ); FileUtils.copyFile( originalSettingsFile, targetFile ); new SettingsIO( null ).write( settings, targetFile ); assertTrue( FileUtils.contentEqualsIgnoreEOL( originalSettingsFile, targetFile, StandardCharsets.UTF_8.toString() ) ); assertTrue( FileUtils.contentEquals( targetFile, originalSettingsFile ) ); }
@Test(expected = ManipulationException.class) public void verifyErroneousSettings() throws IOException, ManipulationException { File targetFile = folder.newFile( "settings.xml" ); FileOutputStream saveFile = new FileOutputStream(targetFile); try ( DataOutputStream save = new DataOutputStream( saveFile) ) { save.writeByte( 0 ); } new SettingsIO( null ).write( null, targetFile ); }
@Test public void verifyWriteSettngs() throws IOException, ManipulationException { URL resource = SettingsIOTest.class.getResource( "settings.xml" ); assertNotNull( resource ); File originalSettingsFile = new File( resource.getFile() ); assertTrue( originalSettingsFile.exists() ); Settings settings = new DefaultSettingsReader().read( originalSettingsFile, Collections.emptyMap() ); assertNull( settings.getModelEncoding() ); File targetFile = folder.newFile( "settings.xml" ); new SettingsIO( null ).write( settings, targetFile ); assertFalse( FileUtils.contentEquals( targetFile, originalSettingsFile ) ); }