MessagePartCreators { public static void addAllPartsTo(final SMTPMessageAdaptor smtpMessage, final IObject context, final List<IObject> parts) throws Exception { for (IObject part : parts) { try { creatorsMap .get(partType_Part_F.in(part)) .addPartTo(smtpMessage, context, part); } catch (NullPointerException e) { throw new PartCreatorException("Part type not found.", e); } catch (ChangeValueException | ReadValueException | MessagingException e) { throw new PartCreatorException("Failed to create message part.", e); } catch (InvalidArgumentException e) { throw new Exception("Failed to extract type", e); } } }  static void addAllPartsTo(final SMTPMessageAdaptor smtpMessage, final IObject context, final List<IObject> parts); static void add(String name, MessagePartCreator creator);  }
@Test public void Should_MessagePartCreatorsCreateTextAndFileParts() throws Exception { IObject context = new DSObject(); SMTPMessageAdaptor messageAdaptor = mock(SMTPMessageAdaptor.class); List<IObject> partsParameters = Collections.singletonList( new DSObject("{\"type\":\"text\",\"mime\":\"text/html\",\"text\":\"TeXt\"}")); ArgumentMatcher<MimeBodyPart> partMatcher = new ArgumentMatcher<MimeBodyPart>() { @Override public boolean matches(Object o) { MimeBodyPart part = (MimeBodyPart)o; try { return part.getDataHandler().getContentType().equals("text/html") && part.getContent().equals("TeXt"); } catch (MessagingException | IOException e) { return false; } } }; MessagePartCreators.addAllPartsTo(messageAdaptor, context, partsParameters); verify(messageAdaptor).addPart(argThat(partMatcher)); }