BodyPartIterator extends MultipartIterator implements Iterator<MimeBodyPart> { public MimeBodyPart getBodyPart(String id) { MimeBodyPart result = null; MimePartHolder tmp = new MimePartHolder(id); if (bodyParts.contains(tmp)) { result = bodyParts.get(bodyParts.indexOf(tmp)).getPart(); } return result; } BodyPartIterator(InputStream in);  BodyPartIterator(byte[] bytes); protected  BodyPartIterator(DataSource ds); MimeBodyPart getBodyPart(String id); MimeBodyPart getBodyPart(int partNumber); @Override boolean hasNext(); @Override MimeBodyPart next(); @Override void close(); int size();  }
@Test public void testGetById() throws Exception { try (BodyPartIterator mimeInput = new BodyPartIterator(generateByteArrayInput(true))) { MimeBodyPart part = mimeInput.getBodyPart("payload2"); assertEquals(PAYLOAD_2, toString(part)); assertNull(mimeInput.getBodyPart("hello")); } }
@Test public void testGetByPosition() throws Exception { try (BodyPartIterator mimeInput = new BodyPartIterator(new ByteArrayInputStream(generateByteArrayInput(false)))) { MimeBodyPart part = mimeInput.getBodyPart(1); assertEquals(PAYLOAD_2, toString(part)); assertNull(mimeInput.getBodyPart(6)); } }