CreationNotificationSender { public void sendNotification(String userName, String userEmail, boolean withPassword) throws IOException, ApiException { final URL urlEndpoint = new URL(apiEndpoint); final String masterEndpoint = urlEndpoint.getProtocol() + ": final Template template = withPassword ? templateWithPassword(masterEndpoint, userEmail, userName) : templateWithoutPassword(masterEndpoint, userName); final EmailBean emailBean = new EmailBean() .withBody(doProcessTemplate(template)) .withFrom(mailFrom) .withTo(userEmail) .withReplyTo(null) .withMimeType(TEXT_HTML); if (withPassword) { emailBean.setSubject(accountCreatedWithPasswordMailSubject); } else { emailBean.setSubject(accountCreatedWithoutPasswordMailSubject); } try { mailSender.sendMail(resourceResolver.resolve(emailBean)); } catch (SendMailException e) { throw new ServerException(e.getMessage(), e); } } @Inject  CreationNotificationSender(
      @Named("che.api") String apiEndpoint,
      @Named("che.mail.from_email_address") String mailFrom,
      RecoveryStorage recoveryStorage,
      MailSender mailSender,
      TemplateProcessor templateProcessor,
      DefaultEmailResourceResolver resourceResolver,
      @Named("account.created.byuser.mail.subject") String accountCreatedWithoutPasswordMailSubject,
      @Named("account.created.byadmin.mail.subject") String accountCreatedWithPasswordMailSubject); void sendNotification(String userName, String userEmail, boolean withPassword);  }
@Test public void shouldSendEmailWhenUserWasCreatedByUserServiceWithDescriptor() throws Throwable { when(templateProcessor.process(any())).thenReturn("body"); when(resourceResolver.resolve(any())).thenAnswer(answer -> answer.getArguments()[0]); notificationSender.sendNotification("user123", "test@user.com", true); verify(mailSender).sendMail(argumentCaptor.capture()); verify(resourceResolver, times(1)).resolve(any(EmailBean.class)); verify(templateProcessor, times(1)).process(any()); final EmailBean emailBean = argumentCaptor.getValue(); assertTrue(!emailBean.getBody().isEmpty()); assertEquals(emailBean.getTo(), "test@user.com"); assertEquals(emailBean.getMimeType(), TEXT_HTML); assertEquals(emailBean.getFrom(), "noreply@host"); assertEquals(emailBean.getSubject(), "Subject with password"); }