Make MailSenderIT.outgoingMailWithACommentsInUnchangedFile less fragile The assertion of the expected full body of the e-mail, including the username, can be flakey for newer releases of Gerrit where the way the user is formatted can vary. Restrict the asserted text so that it can be more easily merged up without breaking tests. Release-Notes: skip Change-Id: Id43b6ebf1efdaf083552ba4b17e02178554e5797
diff --git a/javatests/com/google/gerrit/acceptance/server/mail/MailSenderIT.java b/javatests/com/google/gerrit/acceptance/server/mail/MailSenderIT.java index f774aa3..9322502 100644 --- a/javatests/com/google/gerrit/acceptance/server/mail/MailSenderIT.java +++ b/javatests/com/google/gerrit/acceptance/server/mail/MailSenderIT.java
@@ -79,11 +79,12 @@ String lastCommentId = Iterables.getLast(comments).id; ChangeInfo changeInfo = gApi.changes().id(changeId).get(); String expectedBodyAsString = - emailBodyWithCommentsInUnchangeFile( - getChangeUrl(changeInfo), lastCommentId, adminInlineComment, userInlineComment); + "PS1, Line 1: this is line 1 \n" + "> " + adminInlineComment + "\n" + userInlineComment; assertThat(sender.getMessages()).hasSize(1); String bodyAsString = sender.getMessages().iterator().next().body(); assertThat(bodyAsString).contains(expectedBodyAsString); + assertThat(bodyAsString).contains(getChangeUrl(changeInfo) + "/comment/" + lastCommentId); + assertThat(bodyAsString).contains("File gerrit-server/test.txt:\n"); } private String headerString(Map<String, EmailHeader> headers, String name) { @@ -92,34 +93,6 @@ return ((StringEmailHeader) header).getString(); } - private String emailBodyWithCommentsInUnchangeFile( - String changeURL, String commentId, String adminInlineComment, String userInlineComment) { - return "Attention is currently required from: Administrator.\n" - + "User has posted comments on this change. ( " - + changeURL - + " )\n" - + "\n" - + "Change subject: Second Change\n" - + "......................................................................\n" - + "\n" - + "\n" - + "Patch Set 1:\n" - + "\n" - + "(1 comment)\n" - + "\n" - + "File gerrit-server/test.txt:\n" - + "\n" - + changeURL - + "/comment/" - + commentId - + " \n" - + "PS1, Line 1: this is line 1 \n" - + "> " - + adminInlineComment - + "\n" - + userInlineComment; - } - private String getChangeUrl(ChangeInfo changeInfo) { return canonicalWebUrl.get() + "c/" + changeInfo.project + "/+/" + changeInfo._number; }