@Test public void serializeErrors() throws Exception { MailStatusResult statusResult = mock(MailStatusResult.class); Date date = new Date(); MailStatus status1 = new MailStatus(); status1.setBatchId("batch1"); status1.setState("prepare_error"); status1.setDate(date); status1.setMessageId("6ys1BeC6gnKA7srO/vs06XBZKZM="); status1.setRecipients("john@doe.com"); status1.setErrorSummary("errorsummary1"); status1.setErrorDescription("errordescription1"); MailStatus status2 = new MailStatus(); status2.setBatchId("batch2"); status2.setState("send_error"); status2.setDate(date); status2.setMessageId("6ys1BeC6gnKA7srO/vs06XBZKZM="); status2.setRecipients("jane@doe.com"); status2.setErrorSummary("errorsummary2"); status2.setErrorDescription("errordescription2"); when(statusResult.getAllErrors()).thenReturn(Arrays.asList(status1, status2).iterator()); assertEquals("Some messages have failed to be sent: " + "[[messageId = [6ys1BeC6gnKA7srO/vs06XBZKZM=], batchId = [batch1], state = [prepare_error], " + "date = [" + date.toString() + "], recipients = [john@doe.com], errorSummary = [errorsummary1], " + "errorDescription = [errordescription1]][messageId = [6ys1BeC6gnKA7srO/vs06XBZKZM=], " + "batchId = [batch2], state = [send_error], date = [" + date.toString() + "], recipients = [jane@doe.com], " + "errorSummary = [errorsummary2], errorDescription = [errordescription2]]]", MailStatusResultSerializer.serializeErrors(statusResult)); }
public static String serializeErrors(MailStatusResult statusResult) { String result; Iterator<MailStatus> statuses = statusResult.getAllErrors(); if (statuses.hasNext()) { StringBuilder builder = new StringBuilder("Some messages have failed to be sent: ["); while (statuses.hasNext()) { MailStatus status = statuses.next(); builder.append('[').append(status.toString()).append(']'); } builder.append(']'); result = builder.toString(); } else { result = null; } return result; }
MailStatusResultSerializer { public static String serializeErrors(MailStatusResult statusResult) { String result; Iterator<MailStatus> statuses = statusResult.getAllErrors(); if (statuses.hasNext()) { StringBuilder builder = new StringBuilder("Some messages have failed to be sent: ["); while (statuses.hasNext()) { MailStatus status = statuses.next(); builder.append('[').append(status.toString()).append(']'); } builder.append(']'); result = builder.toString(); } else { result = null; } return result; } }
MailStatusResultSerializer { public static String serializeErrors(MailStatusResult statusResult) { String result; Iterator<MailStatus> statuses = statusResult.getAllErrors(); if (statuses.hasNext()) { StringBuilder builder = new StringBuilder("Some messages have failed to be sent: ["); while (statuses.hasNext()) { MailStatus status = statuses.next(); builder.append('[').append(status.toString()).append(']'); } builder.append(']'); result = builder.toString(); } else { result = null; } return result; } private  MailStatusResultSerializer(); }
MailStatusResultSerializer { public static String serializeErrors(MailStatusResult statusResult) { String result; Iterator<MailStatus> statuses = statusResult.getAllErrors(); if (statuses.hasNext()) { StringBuilder builder = new StringBuilder("Some messages have failed to be sent: ["); while (statuses.hasNext()) { MailStatus status = statuses.next(); builder.append('[').append(status.toString()).append(']'); } builder.append(']'); result = builder.toString(); } else { result = null; } return result; } private  MailStatusResultSerializer(); static String serializeErrors(MailStatusResult statusResult); }
MailStatusResultSerializer { public static String serializeErrors(MailStatusResult statusResult) { String result; Iterator<MailStatus> statuses = statusResult.getAllErrors(); if (statuses.hasNext()) { StringBuilder builder = new StringBuilder("Some messages have failed to be sent: ["); while (statuses.hasNext()) { MailStatus status = statuses.next(); builder.append('[').append(status.toString()).append(']'); } builder.append(']'); result = builder.toString(); } else { result = null; } return result; } private  MailStatusResultSerializer(); static String serializeErrors(MailStatusResult statusResult);  }