### Question:
AbstractTransport extends Transport { void validateAndPrepare(Message message, Address[] addresses) throws MessagingException { if (message.getFrom() == null || message.getFrom().length == 0) { fail(message, addresses, "No or empty FROM address set!"); } if (addresses.length == 0) { fail(message, addresses, "No RECIPIENTS set!"); } Address[] messageAddresses = message.getAllRecipients(); if (messageAddresses == null) { for(Address address : addresses) { message.addRecipient(Message.RecipientType.TO, address); } } else { out: for(Address address : addresses) { for(Address a : messageAddresses) { if (a == null) { continue; } if (a.equals(address)) { continue out; } } message.addRecipient(Message.RecipientType.TO, address); } } } AbstractTransport(Session session, URLName urlname); @Override void connect(String host, int port, String user, String password); @Override boolean isConnected(); @Override void close();  }### Answer:
@Test(expected = MessagingException.class) public void testValidateAndPrepareEmptyNoAdd() throws Exception { transport.validateAndPrepare(message, new Address[0]); }
@Test public void testValidateAndPrepareEmptyAdd() throws Exception { transport.validateAndPrepare(message, new Address[] {new InternetAddress("abc@test.com")}); Assert.assertEquals(1, message.getRecipients(Message.RecipientType.TO).length); }
@Test public void testValidateAndPrepareDuplicate() throws Exception { InternetAddress internetAddress = new InternetAddress("abc@test.com"); message.addRecipient(Message.RecipientType.CC, internetAddress); transport.validateAndPrepare(message, new Address[] {internetAddress, new InternetAddress("abc@jsoftware.org") }); Assert.assertEquals(1, message.getRecipients(Message.RecipientType.TO).length); Assert.assertEquals(1, message.getRecipients(Message.RecipientType.CC).length); }
@Test(expected = MessagingException.class) public void testNoFromNull() throws Exception { try { message.setFrom((String) null); transport.validateAndPrepare(message, new Address[]{}); } finally { waitForListeners(); verify(transportListener).messageNotDelivered(any(TransportEvent.class)); } }