### Question:
EmailReporter { public String generatePayload(String name, String email, String message, String category) throws Exception { if (email == null) email = ""; if (name == null) name = ""; String userEmail = email; String userName = name; if (userEmail.isEmpty()) { userEmail = helpDeskEmail; userName = "Help Desk"; } else if (userName.isEmpty()) { userName = userEmail; } JSONObject fromContact = new JSONObject(); fromContact.put("email", userEmail); fromContact.put("name", userName); JSONObject toContact = new JSONObject(); toContact.put("email", helpDeskEmail); toContact.put("name", "Help Desk"); JSONObject json = new JSONObject(); json.put("from", fromContact); json.put("reply_to", fromContact); JSONArray content = new JSONArray(); JSONObject textMessage = new JSONObject(); textMessage.put("type", "text/plain"); textMessage.put("value", message); content.put(textMessage); JSONObject htmlMessage = new JSONObject(); htmlMessage.put("type", "text/html"); htmlMessage.put("value", message.replaceAll("\n", "<br>")); content.put(htmlMessage); json.put("content", content); JSONObject personalization = new JSONObject(); personalization.put("to", new JSONArray().put(toContact)); personalization.put("subject", "tS Android: " + category); json.put("personalizations", new JSONArray().put(personalization)); return json.toString(); } EmailReporter(String helpDeskToken, String helpDeskEmail); Request reportCrash(String name, String email, String notes, File stacktraceFile, Context context); Request reportCrash(String name, String email, String notes, File stacktraceFile, File logFile, Context context); Request reportCrash(String name, String email, String notes, String stacktrace, String log, Context context); Request reportBug(String name, String email, String notes, Context context); Request reportBug(String name, String email, String notes, File logFile, Context context); Request reportBug(String name, String email, String notes, String log, Context context); String generatePayload(String name, String email, String message, String category);  }### Answer:
@Test public void generatePayloadWithUserEmail() throws Exception { EmailReporter reporter = new EmailReporter("token", "helpdeskemail"); String payload = reporter.generatePayload("name", "email", "hello\nworld", "General Feedback"); assertEquals("{\"personalizations\":[{\"subject\":\"tS Android: General Feedback\",\"to\":[{\"name\":\"Help Desk\",\"email\":\"helpdeskemail\"}]}],\"reply_to\":{\"name\":\"name\",\"email\":\"email\"},\"from\":{\"name\":\"name\",\"email\":\"email\"},\"content\":[{\"type\":\"text/plain\",\"value\":\"hello\\nworld\"},{\"type\":\"text/html\",\"value\":\"hello<br>world\"}]}", payload); }
@Test public void generatePayloadWithoutUserEmail() throws Exception { EmailReporter reporter = new EmailReporter("token", "helpdeskemail"); String payload = reporter.generatePayload("name", null, "message", "General Feedback"); assertEquals("{\"personalizations\":[{\"subject\":\"tS Android: General Feedback\",\"to\":[{\"name\":\"Help Desk\",\"email\":\"helpdeskemail\"}]}],\"reply_to\":{\"name\":\"Help Desk\",\"email\":\"helpdeskemail\"},\"from\":{\"name\":\"Help Desk\",\"email\":\"helpdeskemail\"},\"content\":[{\"type\":\"text/plain\",\"value\":\"message\"},{\"type\":\"text/html\",\"value\":\"message\"}]}", payload); }