### Question:
XWikiAuthenticator extends Authenticator { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(this.username, this.password); } XWikiAuthenticator(MailSenderConfiguration configuration);   }### Answer:
@Test public void testJavaMailPasswordAuthentication() throws Exception { MailSenderConfiguration mailSenderConfiguration = mock(MailSenderConfiguration.class); when(mailSenderConfiguration.getUsername()).thenReturn(MAIL_USER); when(mailSenderConfiguration.getPassword()).thenReturn(MAIL_PASSWORD); XWikiAuthenticator xWikiAuthenticator = new XWikiAuthenticator(mailSenderConfiguration); PasswordAuthentication passwordAuthentication = xWikiAuthenticator.getPasswordAuthentication(); assertThat(passwordAuthentication.getUserName(), equalTo(MAIL_USER)); assertThat(passwordAuthentication.getPassword(), equalTo(MAIL_PASSWORD)); }