AmazonNotificationFactory implements NotificationFactory { @Override public Emailer getEmailer(String fromAddress) { if (null == fromAddress || !EmailValidator.getInstance().isValid(fromAddress)) { String msg = "fromAddress not valid notification: " + fromAddress; log.error(msg); throw new IllegalArgumentException(msg); } if (null == emailService) { String msg = "Emailer service !initialized."; log.error(msg); throw new DuraCloudRuntimeException(msg); } Emailer emailer = emailerMap.get(fromAddress); if (null == emailer) { emailer = new AmazonEmailer(emailService, fromAddress); emailerMap.put(fromAddress, emailer); } return emailer; }  @Override void initialize(String accessKey, String secretKey); @Override Emailer getEmailer(String fromAddress);  }
@Test public void testCreateMultipleEmailers() throws Exception { Emailer emailer0 = factory.getEmailer("a@g.com"); Assert.assertNotNull(emailer0); Emailer emailer1 = factory.getEmailer("x@y.org"); Assert.assertNotNull(emailer1); Assert.assertNotSame(emailer0, emailer1); Emailer emailer2 = factory.getEmailer("a@g.com"); Assert.assertNotNull(emailer2); Assert.assertEquals(emailer0, emailer2); }