EmailConfigurationApiResource implements Resource, EmailConfigurationApiResourceDoc { @POST @Path("/verify") @RequiresAuthentication @RequiresPermissions("nexus:settings:update") public ApiEmailValidation testEmailConfiguration(@NotNull String verificationAddress) { EmailConfiguration emailConfiguration = emailManager.getConfiguration(); if (emailConfiguration == null) { return new ApiEmailValidation(false, "Email Settings are not yet configured"); } try { emailManager.sendVerification(emailConfiguration, verificationAddress); return new ApiEmailValidation(true); } catch (EmailException e) { log.debug("Unable to send verification", e); String exceptionMessage = e.getMessage().replace(e.getCause().getClass().getName() + ": ", ""); if (e.getCause() instanceof AddressException) { throw new WebApplicationMessageException(BAD_REQUEST, '"' + exceptionMessage + '"', APPLICATION_JSON); } else { return new ApiEmailValidation(false, exceptionMessage); } } } @Inject  EmailConfigurationApiResource(EmailManager emailManager); @GET @RequiresPermissions("nexus:settings:read") ApiEmailConfiguration getEmailConfiguration(); @PUT @Validate @RequiresAuthentication @RequiresPermissions("nexus:settings:update") void setEmailConfiguration(@NotNull @Valid final ApiEmailConfiguration apiEmailConfiguration); @POST @Path("/verify") @RequiresAuthentication @RequiresPermissions("nexus:settings:update") ApiEmailValidation testEmailConfiguration(@NotNull String verificationAddress); @DELETE @RequiresAuthentication @RequiresPermissions("nexus:settings:update") void deleteEmailConfiguration();  }
@Test public void testEmailConfigurationSendsTestEmail() throws EmailException { when(emailConfiguration.isEnabled()).thenReturn(true); when(emailManager.getConfiguration()).thenReturn(emailConfiguration); String destinationAddress = "test@example.com"; underTest.testEmailConfiguration(destinationAddress); verify(emailManager).sendVerification(emailConfiguration, destinationAddress); }