@Test public void toJSON_whenSettingTxtExists_deletesFile() throws Exception { File settingsTxtFile = new File(storageDir + "/collect.settings"); writeEmptyObjectSettings(settingsTxtFile); fileReader.toJSON(); assertThat(settingsTxtFile.exists(), is(false)); }
public String toJSON() throws CorruptSettingsFileException { File f = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings"); File j = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings.json"); try { if (j.exists()) { String settings = readJSONFile(j); j.delete(); return settings; } else if (f.exists()) { Pair<Map<String, Object>, Map<String, Object>> settings = readSettingsFile(f); f.delete(); return new JSONObject() .put("general", new JSONObject(settings.first)) .put("admin", new JSONObject(settings.second)) .toString(); } else { return null; } } catch (IOException | JSONException | ClassNotFoundException e) { throw new CorruptSettingsFileException(); } }
LegacySettingsFileReader { public String toJSON() throws CorruptSettingsFileException { File f = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings"); File j = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings.json"); try { if (j.exists()) { String settings = readJSONFile(j); j.delete(); return settings; } else if (f.exists()) { Pair<Map<String, Object>, Map<String, Object>> settings = readSettingsFile(f); f.delete(); return new JSONObject() .put("general", new JSONObject(settings.first)) .put("admin", new JSONObject(settings.second)) .toString(); } else { return null; } } catch (IOException | JSONException | ClassNotFoundException e) { throw new CorruptSettingsFileException(); } } }
LegacySettingsFileReader { public String toJSON() throws CorruptSettingsFileException { File f = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings"); File j = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings.json"); try { if (j.exists()) { String settings = readJSONFile(j); j.delete(); return settings; } else if (f.exists()) { Pair<Map<String, Object>, Map<String, Object>> settings = readSettingsFile(f); f.delete(); return new JSONObject() .put("general", new JSONObject(settings.first)) .put("admin", new JSONObject(settings.second)) .toString(); } else { return null; } } catch (IOException | JSONException | ClassNotFoundException e) { throw new CorruptSettingsFileException(); } } LegacySettingsFileReader(StoragePathProvider storagePathProvider); }
LegacySettingsFileReader { public String toJSON() throws CorruptSettingsFileException { File f = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings"); File j = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings.json"); try { if (j.exists()) { String settings = readJSONFile(j); j.delete(); return settings; } else if (f.exists()) { Pair<Map<String, Object>, Map<String, Object>> settings = readSettingsFile(f); f.delete(); return new JSONObject() .put("general", new JSONObject(settings.first)) .put("admin", new JSONObject(settings.second)) .toString(); } else { return null; } } catch (IOException | JSONException | ClassNotFoundException e) { throw new CorruptSettingsFileException(); } } LegacySettingsFileReader(StoragePathProvider storagePathProvider); String toJSON(); }
LegacySettingsFileReader { public String toJSON() throws CorruptSettingsFileException { File f = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings"); File j = new File(storagePathProvider.getStorageRootDirPath() + "/collect.settings.json"); try { if (j.exists()) { String settings = readJSONFile(j); j.delete(); return settings; } else if (f.exists()) { Pair<Map<String, Object>, Map<String, Object>> settings = readSettingsFile(f); f.delete(); return new JSONObject() .put("general", new JSONObject(settings.first)) .put("admin", new JSONObject(settings.second)) .toString(); } else { return null; } } catch (IOException | JSONException | ClassNotFoundException e) { throw new CorruptSettingsFileException(); } } LegacySettingsFileReader(StoragePathProvider storagePathProvider); String toJSON();  }