DefaultFromAddresParser implements FromAddressParser { @Override public Address parse(String addresses, DirectDocuments documents) { Address address = null; String replyEmail = null; if (StringUtils.isNotBlank(addresses)) { try { replyEmail = (new URI(addresses)).getSchemeSpecificPart(); } catch (URISyntaxException e) { LOG.error("Unable to parse Direct From header, attempting to parse XDR author telecom: " + e.getLocalizedMessage(), e); } } else if (null != documents && null != documents.getSubmissionSet()) { replyEmail = documents.getSubmissionSet().getAuthorTelecommunication(); replyEmail = ParserHL7.parseXTN(replyEmail); } try { if (replyEmail != null) { address = new InternetAddress(replyEmail); } } catch (AddressException e) { String errorMesssage = "Unable to create InternetAddress from direct from address."; throw new DirectException(errorMesssage, e); } return address; }  @Override Address parse(String addresses, DirectDocuments documents);  }
@Test public void testParse_Positive1() { String addresses = "test@connectopensource.org"; DirectDocuments oDocuments = null; DefaultFromAddresParser instance = new DefaultFromAddresParser(); InternetAddress result = (InternetAddress) instance.parse(addresses, oDocuments); assertEquals(addresses, result.getAddress()); }
@Test public void testParse_Positive2() { String addresses = null; DefaultFromAddresParser instance = new DefaultFromAddresParser(); DirectDocuments oDocuments = new DirectDocuments(); DirectDocuments.SubmissionSet oSubmissionSet = new DirectDocuments.SubmissionSet(); oSubmissionSet.setAuthorTelecommunication("^^^test@connectopensource.org"); oDocuments.setSubmissionSet(oSubmissionSet); InternetAddress result = (InternetAddress) instance.parse(addresses, oDocuments); assertEquals("test@connectopensource.org", result.getAddress()); }
@Test public void testParse_Negative() throws Exception { String addresses = null; InternetAddress result = null; DirectDocuments oDirectDocuments = null; DefaultFromAddresParser instance = new DefaultFromAddresParser(); try { result = (InternetAddress) instance.parse(addresses, oDirectDocuments); } catch (DirectException exp) { assertNotNull(exp.getMessage()); } assertNull(result); }