EmailServiceImpl extends Authenticator implements EmailService, InitializedService { @Override protected PasswordAuthentication getPasswordAuthentication() { if (null == cfg) { cfg = DSpaceServicesFactory.getInstance().getConfigurationService(); } return new PasswordAuthentication( cfg.getProperty("mail.server.username"), cfg.getProperty("mail.server.password")); }  @Autowired @Required void setCfg(ConfigurationService cfg); @Override Session getSession(); @Override void init();  }
@Test public void testGetPasswordAuthentication() { System.out.println("getPasswordAuthentication"); ConfigurationService cfg = getKernel().getConfigurationService(); String oldUsername = cfg.getProperty(CFG_USERNAME); String oldPassword = cfg.getProperty(CFG_PASSWORD); cfg.setProperty(CFG_USERNAME, USERNAME); cfg.setProperty(CFG_PASSWORD, PASSWORD); EmailServiceImpl instance = (EmailServiceImpl) getService(EmailServiceImpl.class); PasswordAuthentication result = instance.getPasswordAuthentication(); assertNotNull(" null returned", result); assertEquals(" username does not match configuration", result.getUserName(), USERNAME); assertEquals(" password does not match configuration", result.getPassword(), PASSWORD); cfg.setProperty(CFG_USERNAME, oldUsername); cfg.setProperty(CFG_PASSWORD, oldPassword); }