use of com.google.gerrit.extensions.api.accounts.EmailApi in project gerrit by GerritCodeReview.
the class EmailIT method emailApi.
@Test
public void emailApi() throws Exception {
String email = "foo@example.com";
assertThat(getEmails()).doesNotContain(email);
// Create email
EmailInput emailInput = new EmailInput();
emailInput.email = email;
emailInput.noConfirmation = true;
gApi.accounts().self().createEmail(emailInput);
assertThat(getEmails()).contains(email);
assertThat(gApi.accounts().self().get().email).isNotEqualTo(email);
// Get email
requestScopeOperations.resetCurrentApiUser();
EmailApi emailApi = gApi.accounts().self().email(email);
EmailInfo emailInfo = emailApi.get();
assertThat(emailInfo.email).isEqualTo(email);
assertThat(emailInfo.preferred).isNull();
assertThat(emailInfo.pendingConfirmation).isNull();
// Set as preferred email
emailApi.setPreferred();
assertThat(gApi.accounts().self().get().email).isEqualTo(email);
// Get email again (now it's the preferred email)
requestScopeOperations.resetCurrentApiUser();
emailApi = gApi.accounts().self().email(email);
emailInfo = emailApi.get();
assertThat(emailInfo.email).isEqualTo(email);
assertThat(emailInfo.preferred).isTrue();
assertThat(emailInfo.pendingConfirmation).isNull();
// Delete email
emailApi.delete();
assertThat(getEmails()).doesNotContain(email);
// Now the email is no longer found
requestScopeOperations.resetCurrentApiUser();
assertThrows(ResourceNotFoundException.class, () -> gApi.accounts().self().email(email).get());
}
Aggregations