WootricCustomThankYou implements Parcelable { public static WootricCustomThankYou fromJson(JSONObject customThankYouJson) throws JSONException { if(customThankYouJson == null) return null; WootricCustomThankYou wootricCustomThankYou = new WootricCustomThankYou(); JSONObject thankYouMessagesJson = customThankYouJson.optJSONObject("thank_you_messages"); JSONObject thankYouLinksJson = customThankYouJson.optJSONObject("thank_you_links"); if (thankYouMessagesJson != null) { JSONObject thankYouMainList = thankYouMessagesJson.optJSONObject("thank_you_main_list"); JSONObject thankYouSetupList = thankYouMessagesJson.optJSONObject("thank_you_setup_list"); wootricCustomThankYou.finalThankYou = thankYouMessagesJson.optString("thank_you_main"); wootricCustomThankYou.setText(thankYouMessagesJson.optString("thank_you_setup")); if (thankYouMainList != null) { wootricCustomThankYou.uniqueByScore = true; wootricCustomThankYou.detractorFinalThankYou = thankYouMainList.optString("detractor_thank_you_main"); wootricCustomThankYou.passiveFinalThankYou = thankYouMainList.optString("passive_thank_you_main"); wootricCustomThankYou.promoterFinalThankYou = thankYouMainList.optString("promoter_thank_you_main"); } if (thankYouSetupList != null) { wootricCustomThankYou.uniqueByScore = true; wootricCustomThankYou.setDetractorText(thankYouSetupList.optString("detractor_thank_you_setup")); wootricCustomThankYou.setPassiveText(thankYouSetupList.optString("passive_thank_you_setup")); wootricCustomThankYou.setPromoterText(thankYouSetupList.optString("promoter_thank_you_setup")); } } if (thankYouLinksJson != null) { JSONObject thankYouLinkTextList = thankYouLinksJson.optJSONObject("thank_you_link_text_list"); JSONObject thankYouLinkUrlList = thankYouLinksJson.optJSONObject("thank_you_link_url_list"); JSONObject thankYouLinkUrlSettingsList = thankYouLinksJson.optJSONObject("thank_you_link_url_settings_list"); JSONObject thankYouLinkUrlSettings = thankYouLinksJson.optJSONObject("thank_you_link_url_settings"); wootricCustomThankYou.setLinkText(thankYouLinksJson.optString("thank_you_link_text", null)); wootricCustomThankYou.setLinkUri(Uri.parse(thankYouLinksJson.optString("thank_you_link_url"))); if (thankYouLinkUrlSettings != null) { wootricCustomThankYou.setEmailInUrl(thankYouLinkUrlSettings.getBoolean("add_email_param_to_url")); wootricCustomThankYou.setScoreInUrl(thankYouLinkUrlSettings.getBoolean("add_score_param_to_url")); wootricCustomThankYou.setCommentInUrl(thankYouLinkUrlSettings.getBoolean("add_comment_param_to_url")); } if (thankYouLinkTextList != null) { wootricCustomThankYou.uniqueByScore = true; wootricCustomThankYou.setDetractorLinkText(thankYouLinkTextList.optString("detractor_thank_you_link_text", null)); wootricCustomThankYou.setPassiveLinkText(thankYouLinkTextList.optString("passive_thank_you_link_text", null)); wootricCustomThankYou.setPromoterLinkText(thankYouLinkTextList.optString("promoter_thank_you_link_text", null)); } if (thankYouLinkUrlList != null) { wootricCustomThankYou.uniqueByScore = true; wootricCustomThankYou.setDetractorLinkUri(Uri.parse(thankYouLinkUrlList.optString("detractor_thank_you_link_url"))); wootricCustomThankYou.setPassiveLinkUri(Uri.parse(thankYouLinkUrlList.optString("passive_thank_you_link_url"))); wootricCustomThankYou.setPromoterLinkUri(Uri.parse(thankYouLinkUrlList.optString("promoter_thank_you_link_url"))); } if (thankYouLinkUrlSettingsList != null) { JSONObject detractorThankYouLinkUrlSettingsList = thankYouLinkUrlSettingsList.optJSONObject("detractor_thank_you_link_url_settings"); JSONObject passiveThankYouLinkUrlSettingsList = thankYouLinkUrlSettingsList.optJSONObject("passive_thank_you_link_url_settings"); JSONObject promoterThankYouLinkUrlSettingsList = thankYouLinkUrlSettingsList.optJSONObject("promoter_thank_you_link_url_settings"); if (detractorThankYouLinkUrlSettingsList != null) { wootricCustomThankYou.setDetractorEmailInUrl(detractorThankYouLinkUrlSettingsList.getBoolean("add_email_param_to_url")); wootricCustomThankYou.setDetractorScoreInUrl(detractorThankYouLinkUrlSettingsList.getBoolean("add_score_param_to_url")); wootricCustomThankYou.setDetractorCommentInUrl(detractorThankYouLinkUrlSettingsList.getBoolean("add_comment_param_to_url")); } if (passiveThankYouLinkUrlSettingsList != null) { wootricCustomThankYou.setPassiveEmailInUrl(passiveThankYouLinkUrlSettingsList.getBoolean("add_email_param_to_url")); wootricCustomThankYou.setPassiveScoreInUrl(passiveThankYouLinkUrlSettingsList.getBoolean("add_score_param_to_url")); wootricCustomThankYou.setPassiveCommentInUrl(passiveThankYouLinkUrlSettingsList.getBoolean("add_comment_param_to_url")); } if (promoterThankYouLinkUrlSettingsList != null) { wootricCustomThankYou.setPromoterEmailInUrl(promoterThankYouLinkUrlSettingsList.getBoolean("add_email_param_to_url")); wootricCustomThankYou.setPromoterScoreInUrl(promoterThankYouLinkUrlSettingsList.getBoolean("add_score_param_to_url")); wootricCustomThankYou.setPromoterCommentInUrl(promoterThankYouLinkUrlSettingsList.getBoolean("add_comment_param_to_url")); } } } return wootricCustomThankYou; } WootricCustomThankYou();  WootricCustomThankYou(WootricCustomThankYou wootricCustomThankYou); private  WootricCustomThankYou(Parcel in); String getFinalThankYouForScore(int scoreValue, String surveyType, int surveyTypeScale); String getTextForScore(int scoreValue, String surveyType, int surveyTypeScale); String getLinkTextForScore(int scoreValue, String surveyType, int surveyTypeScale); Uri getLinkUri(int score, String surveyType, int surveyTypeScale); Boolean getEmailInUri(int score, String surveyType, int surveyTypeScale); Boolean getScoreInUri(int score, String surveyType, int surveyTypeScale); Boolean getCommentInUri(int score, String surveyType, int surveyTypeScale); boolean getUniqueByScore(); void setFinalThankYou(String finalThankYou); void setDetractorFinalThankYou(String detractorFinalThankYou); void setPassiveFinalThankYou(String passiveFinalThankYou); void setPromoterFinalThankYou(String promoterFinalThankYou); void setText(String text); void setDetractorText(String detractorText); void setPassiveText(String passiveText); void setPromoterText(String promoterText); void setLinkText(String linkText); void setLinkUri(Uri linkUri); void setDetractorLinkText(String detractorLinkText); void setDetractorLinkUri(Uri detractorLinkUri); void setPassiveLinkText(String passiveLinkText); void setPassiveLinkUri(Uri passiveLinkUrl); void setPromoterLinkText(String promoterLinkText); void setPromoterLinkUri(Uri promoterLinkUrl); void setEmailInUrl(boolean emailInUrl); void setDetractorEmailInUrl(boolean detractorEmailInUrl); void setPassiveEmailInUrl(boolean passiveEmailInUrl); void setPromoterEmailInUrl(boolean promoterEmailInUrl); void setScoreInUrl(boolean scoreInUrl); void setDetractorScoreInUrl(boolean detractorScoreInUrl); void setPassiveScoreInUrl(boolean passiveScoreInUrl); void setPromoterScoreInUrl(boolean promoterScoreInUrl); void setCommentInUrl(boolean commentInUrl); void setDetractorCommentInUrl(boolean detractorCommentInUrl); void setPassiveCommentInUrl(boolean passiveCommentInUrl); void setPromoterCommentInUrl(boolean promoterCommentInUrl); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static WootricCustomThankYou fromJson(JSONObject customThankYouJson); static final Creator<WootricCustomThankYou> CREATOR; }
@Test public void testWootricCustomThankYouFromJsonWhenThankYouLinkUrlSettingsIsNull() throws IOException, JSONException { TestHelper helper = new TestHelper(); JSONObject customThankYouJson = new JSONObject(helper.loadJSONFromAsset("custom_thank_you.json")); customThankYouJson.getJSONObject("thank_you_links").remove("thank_you_link_url_settings"); WootricCustomThankYou customThankYou = WootricCustomThankYou.fromJson(customThankYouJson); assertThat(customThankYou).isNotNull(); assertThat(customThankYouJson.optJSONObject("thank_you_links").optString("thank_you_link_url_settings")).isNullOrEmpty(); }