test_class.file: collect_app/src/test/java/org/odk/collect/android/preferences/PreferenceSaverTest.java
test_class.identifier: PreferenceSaverTest
test_case.body: @Test
      public void fromJSON_whenPreferencesAreValid_savesIncludedGeneralKeys_andResetsMissingGeneralKeys() throws Exception {
          JSONObject content = new JSONObject();
          JSONObject general = new JSONObject();
          content.put("general", general);
          content.put("admin", new JSONObject());
          general.put(KEY_PASSWORD, "password");
  
          GeneralSharedPreferences generalSharedPreferences = mock(GeneralSharedPreferences.class);
          new PreferenceSaver(generalSharedPreferences, AdminSharedPreferences.getInstance()).fromJSON(content.toString(), mock(ActionListener.class));
  
          verify(generalSharedPreferences).save(KEY_PASSWORD, "password");
          verify(generalSharedPreferences).reset(KEY_SERVER_URL);
      }
test_case.class_method_signature: PreferenceSaverTest.fromJSON_whenPreferencesAreValid_savesIncludedGeneralKeys_andResetsMissingGeneralKeys()
test_case.full_signature: @Test public void fromJSON_whenPreferencesAreValid_savesIncludedGeneralKeys_andResetsMissingGeneralKeys()
test_case.identifier: fromJSON_whenPreferencesAreValid_savesIncludedGeneralKeys_andResetsMissingGeneralKeys
test_case.invocations: put put put mock fromJSON getInstance toString mock save verify reset verify
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void fromJSON_whenPreferencesAreValid_savesIncludedGeneralKeys_andResetsMissingGeneralKeys()
focal_class.declarator: generalSharedPreferences
focal_class.modifier: private final
focal_class.original_string: private final GeneralSharedPreferences generalSharedPreferences;
focal_class.type: GeneralSharedPreferences
focal_class.var_name: generalSharedPreferences
focal_class.declarator: adminSharedPreferences
focal_class.modifier: private final
focal_class.original_string: private final AdminSharedPreferences adminSharedPreferences;
focal_class.type: AdminSharedPreferences
focal_class.var_name: adminSharedPreferences
focal_class.file: collect_app/src/main/java/org/odk/collect/android/preferences/PreferenceSaver.java
focal_class.identifier: PreferenceSaver
focal_class.class_method_signature: PreferenceSaver.PreferenceSaver(GeneralSharedPreferences generalSharedPreferences, AdminSharedPreferences adminSharedPreferences)
focal_class.full_signature: public  PreferenceSaver(GeneralSharedPreferences generalSharedPreferences, AdminSharedPreferences adminSharedPreferences)
focal_class.identifier: PreferenceSaver
focal_class.modifiers: public
focal_class.parameters: (GeneralSharedPreferences generalSharedPreferences, AdminSharedPreferences adminSharedPreferences)
focal_class.signature:  PreferenceSaver(GeneralSharedPreferences generalSharedPreferences, AdminSharedPreferences adminSharedPreferences)
focal_class.class_method_signature: PreferenceSaver.fromJSON(String content, @Nullable ActionListener listener)
focal_class.full_signature: public void fromJSON(String content, @Nullable ActionListener listener)
focal_class.identifier: fromJSON
focal_class.modifiers: public
focal_class.parameters: (String content, @Nullable ActionListener listener)
focal_class.return: void
focal_class.signature: void fromJSON(String content, @Nullable ActionListener listener)
focal_class.class_method_signature: PreferenceSaver.saveGeneralPrefs(GeneralSharedPreferences generalSharedPreferences, Map<String, Object> generalPrefs)
focal_class.full_signature: public static void saveGeneralPrefs(GeneralSharedPreferences generalSharedPreferences, Map<String, Object> generalPrefs)
focal_class.identifier: saveGeneralPrefs
focal_class.modifiers: public static
focal_class.parameters: (GeneralSharedPreferences generalSharedPreferences, Map<String, Object> generalPrefs)
focal_class.return: void
focal_class.signature: void saveGeneralPrefs(GeneralSharedPreferences generalSharedPreferences, Map<String, Object> generalPrefs)
focal_class.class_method_signature: PreferenceSaver.saveAdminPrefs(AdminSharedPreferences adminSharedPreferences, Map<String, Object> adminPrefsJson)
focal_class.full_signature: public static void saveAdminPrefs(AdminSharedPreferences adminSharedPreferences, Map<String, Object> adminPrefsJson)
focal_class.identifier: saveAdminPrefs
focal_class.modifiers: public static
focal_class.parameters: (AdminSharedPreferences adminSharedPreferences, Map<String, Object> adminPrefsJson)
focal_class.return: void
focal_class.signature: void saveAdminPrefs(AdminSharedPreferences adminSharedPreferences, Map<String, Object> adminPrefsJson)
focal_class.class_method_signature: PreferenceSaver.convertJSONToMap(JSONObject json)
focal_class.full_signature: private static Map<String, Object> convertJSONToMap(JSONObject json)
focal_class.identifier: convertJSONToMap
focal_class.modifiers: private static
focal_class.parameters: (JSONObject json)
focal_class.return: Map<String, Object>
focal_class.signature: Map<String, Object> convertJSONToMap(JSONObject json)
focal_class.class_method_signature: PreferenceSaver.getAllGeneralKeys()
focal_class.full_signature: private static Collection<String> getAllGeneralKeys()
focal_class.identifier: getAllGeneralKeys
focal_class.modifiers: private static
focal_class.parameters: ()
focal_class.return: Collection<String>
focal_class.signature: Collection<String> getAllGeneralKeys()
focal_class.class_method_signature: PreferenceSaver.getAllAdminKeys()
focal_class.full_signature: private static Collection<String> getAllAdminKeys()
focal_class.identifier: getAllAdminKeys
focal_class.modifiers: private static
focal_class.parameters: ()
focal_class.return: Collection<String>
focal_class.signature: Collection<String> getAllAdminKeys()
focal_method.body: public void fromJSON(String content, @Nullable ActionListener listener) {
          try {
              JSONObject settingsJson = new JSONObject(content);
              Map<String, Object> generalPrefs = convertJSONToMap(settingsJson.getJSONObject("general"));
              Map<String, Object> adminPrefsJson = convertJSONToMap(settingsJson.getJSONObject("admin"));
  
              if (!(new PreferenceValidator(GENERAL_KEYS).isValid(generalPrefs))) {
                  if (listener != null) {
                      listener.onFailure(new GeneralSharedPreferences.ValidationException());
                  }
  
                  return;
              }
  
              saveGeneralPrefs(generalSharedPreferences, generalPrefs);
              saveAdminPrefs(adminSharedPreferences, adminPrefsJson);
  
              AutoSendPreferenceMigrator.migrate(settingsJson.getJSONObject("general"));
  
              if (listener != null) {
                  listener.onSuccess();
              }
          } catch (JSONException exception) {
              if (listener != null) {
                  listener.onFailure(exception);
              }
          }
      }
focal_method.class_method_signature: PreferenceSaver.fromJSON(String content, @Nullable ActionListener listener)
focal_method.full_signature: public void fromJSON(String content, @Nullable ActionListener listener)
focal_method.identifier: fromJSON
focal_method.invocations: convertJSONToMap getJSONObject convertJSONToMap getJSONObject isValid onFailure saveGeneralPrefs saveAdminPrefs migrate getJSONObject onSuccess onFailure
focal_method.modifiers: public
focal_method.parameters: (String content, @Nullable ActionListener listener)
focal_method.return: void
focal_method.signature: void fromJSON(String content, @Nullable ActionListener listener)