use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchKeyword.
@Test
public void watchKeyword() throws Exception {
String watchedProject = projectOperations.newProject().create().get();
requestScopeOperations.setApiUser(user.id());
// watch keyword in project as user
watch(watchedProject, "multiprimary");
// push a change with keyword -> should trigger email notification
requestScopeOperations.setApiUser(admin.id());
TestRepository<InMemoryRepository> watchedRepo = cloneProject(Project.nameKey(watchedProject), admin);
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), watchedRepo, "Document multiprimary setup", "a.txt", "a1").to("refs/for/master");
r.assertOkStatus();
// assert email notification for user
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
assertThat(m.body()).contains("Change subject: Document multiprimary setup\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
sender.clear();
// push a change without keyword -> should not trigger email notification
r = pushFactory.create(admin.newIdent(), watchedRepo, "Cleanup cache implementation", "b.txt", "b1").to("refs/for/master");
r.assertOkStatus();
// assert email notification
assertThat(sender.getMessages()).isEmpty();
}
Aggregations