### Question:
AttachmentProcessingHelper { public static void setDataToFileResourcesList(List<ResourceReference> references, Map<String, InputStream> parts, String partNamePrefix) throws MandatoryParameterNotFoundException, IllegalParameterValueException { if (references != null) { for (int i = 0; i < references.size(); i++) { final ResourceReference currentReference = references.get(i); final String attachmentName = String.format(partNamePrefix + "[%d]", i); if (currentReference.isLocal() || parts.get(attachmentName) != null) { setDataToFileResourceWithValidation(parts != null ? parts.get(attachmentName) : null, currentReference, attachmentName); } } } }  static void setDataToFileResourceWithValidation(InputStream inputStream, ResourceReference fileReference, String partName); static void setDataToFileResourcesList(List<ResourceReference> references, Map<String, InputStream> parts, String partNamePrefix);  }### Answer:
@Test public void setDataToFileResourcesList() throws IllegalParameterValueException, MandatoryParameterNotFoundException { byte[] expectedByteArray0 = new byte[]{1, 2, 3}; byte[] expectedByteArray1 = new byte[]{4, 5, 6}; byte[] expectedByteArray3 = new byte[]{7, 8, 9}; List<ResourceReference> references = new ArrayList<ResourceReference>(); references.add(new ResourceReference(new FileResourceImpl())); references.add(new ResourceReference(new FileResourceImpl())); references.add(new ResourceReference("/some/uri")); references.add(new ResourceReference(new FileResourceImpl())); final String prefix = "somePrefix"; final HashMap<String, InputStream> parts = new HashMap<String, InputStream>(); parts.put(prefix + "[0]", new ByteArrayInputStream(expectedByteArray0)); parts.put(prefix + "[1]", new ByteArrayInputStream(expectedByteArray1)); parts.put(prefix + "[3]", new ByteArrayInputStream(expectedByteArray3)); AttachmentProcessingHelper.setDataToFileResourcesList(references, parts, prefix); assertEquals(references.size(), 4); assertTrue(references.get(0).getLocalResource() instanceof FileResource); assertEquals(((FileResource) references.get(0).getLocalResource()).getData(), expectedByteArray0); assertTrue(references.get(1).getLocalResource() instanceof FileResource); assertEquals(((FileResource) references.get(1).getLocalResource()).getData(), expectedByteArray1); assertFalse(references.get(2).isLocal()); assertTrue(references.get(3).getLocalResource() instanceof FileResource); assertEquals(((FileResource) references.get(3).getLocalResource()).getData(), expectedByteArray3); }
@Test(expectedExceptions = MandatoryParameterNotFoundException.class) public void setDataToFileResourcesList_partsIsNull_exception() throws IllegalParameterValueException, MandatoryParameterNotFoundException { List<ResourceReference> references = new ArrayList<ResourceReference>(); references.add(new ResourceReference(new FileResourceImpl())); AttachmentProcessingHelper.setDataToFileResourcesList(references, null, "somePrefix"); }
@Test(expectedExceptions = MandatoryParameterNotFoundException.class) public void setDataToFileResourcesList_partsIsEmpty_exception() throws IllegalParameterValueException, MandatoryParameterNotFoundException { List<ResourceReference> references = new ArrayList<ResourceReference>(); references.add(new ResourceReference(new FileResourceImpl())); AttachmentProcessingHelper.setDataToFileResourcesList(references, new HashMap<String, InputStream>(), "somePrefix"); }
@Test(expectedExceptions = IllegalParameterValueException.class) public void setDataToFileResourcesList_partExists_resourceIsReference_exception() throws IllegalParameterValueException, MandatoryParameterNotFoundException { List<ResourceReference> references = new ArrayList<ResourceReference>(); references.add(new ResourceReference("/some/uri")); final String prefix = "somePrefix"; final HashMap<String, InputStream> parts = new HashMap<String, InputStream>(); parts.put(prefix + "[0]", mock(InputStream.class)); AttachmentProcessingHelper.setDataToFileResourcesList(references, parts, prefix); }