### Question:
ResourceUtil { public Response createAttachment( Map<String, InputStream> fileData, String domainId ) { String quotedFileName = null; final InputStream is; if ( fileData.size() > 1 ) { File zipFile = null; try { zipFile = createTempFile( "datasourceExport", ".zip" ); zipFile.deleteOnExit(); ZipOutputStream zos = createZipOutputStream( zipFile ); for ( String fileName : fileData.keySet() ) { InputStream zipEntryIs = null; try { ZipEntry entry = createZipEntry( fileName ); zos.putNextEntry( entry ); zipEntryIs = fileData.get( fileName ); copy( zipEntryIs, zos ); } catch ( Exception e ) { continue; } finally { zos.closeEntry(); if ( zipEntryIs != null ) { zipEntryIs.close(); } } } zos.close(); is = createFileInputStream( zipFile ); } catch ( IOException ioe ) { return buildServerErrorResponse( ioe ); } StreamingOutput streamingOutput = createStreamingOutput( is ); final int xmiIndex = domainId.lastIndexOf( ".xmi" ); quotedFileName = "\"" + ( xmiIndex > 0 ? domainId.substring( 0, xmiIndex ) : domainId ) + ".zip\""; return buildOkResponse( streamingOutput, APPLICATION_ZIP, quotedFileName ); } else if ( fileData.size() == 1 ) { String fileName = (String) fileData.keySet().toArray()[ 0 ]; quotedFileName = "\"" + fileName + "\""; is = fileData.get( fileName ); String mimeType = getMimeType( is ); StreamingOutput streamingOutput = getStreamingOutput( is ); return buildOkResponse( streamingOutput, mimeType, quotedFileName ); } return buildServerErrorResponse(); }  Response createAttachment( Map<String, InputStream> fileData, String domainId ); static final String APPLICATION_ZIP; }### Answer:
@Test public void testCreateAttachment() throws Exception { Map<String, InputStream> fileData = new TreeMap<String, InputStream>(); InputStream mockInputStream = mock( InputStream.class ); InputStream mockInputStream2 = mock( InputStream.class ); fileData.put( "file1", mockInputStream ); String domainId = "domainId"; StreamingOutput mockStreamingOutput = mock( StreamingOutput.class ); Response mockResponse = mock( Response.class ); File mockFile = mock( File.class ); ZipOutputStream mockZipOutputStream = mock( ZipOutputStream.class ); ZipEntry mockZipEntry = mock( ZipEntry.class ); ZipEntry mockZipEntry2 = mock( ZipEntry.class ); FileInputStream mockFileInputStream = mock( FileInputStream.class ); doReturn( MediaType.TEXT_PLAIN ).when( resourceUtil ).getMimeType( fileData.get( "file1" ) ); doReturn( mockStreamingOutput ).when( resourceUtil ).getStreamingOutput( fileData.get( "file1" ) ); doReturn( mockResponse ).when( resourceUtil ).buildOkResponse( mockStreamingOutput, "text/plain", "\"file1\"" ); Response response = resourceUtil.createAttachment( fileData, domainId ); assertEquals( mockResponse, response ); fileData.put( "file2", mockInputStream2 ); doReturn( mockFile ).when( resourceUtil ).createTempFile( "datasourceExport", ".zip" ); doReturn( mockZipOutputStream ).when( resourceUtil ).createZipOutputStream( mockFile ); doReturn( mockZipEntry ).when( resourceUtil ).createZipEntry( "file1" ); doReturn( mockZipEntry2 ).when( resourceUtil ).createZipEntry( "file2" ); doNothing().when( resourceUtil ).copy( mockInputStream, mockZipOutputStream ); doNothing().when( resourceUtil ).copy( mockInputStream2, mockZipOutputStream ); doReturn( mockFileInputStream ).when( resourceUtil ).createFileInputStream( mockFile ); doReturn( mockStreamingOutput ).when( resourceUtil ).createStreamingOutput( mockFileInputStream ); doReturn( mockResponse ).when( resourceUtil ).buildOkResponse( mockStreamingOutput, resourceUtil.APPLICATION_ZIP, "\"domainId.zip\"" ); response = resourceUtil.createAttachment( fileData, domainId ); assertEquals( mockResponse, response ); verify( resourceUtil, times( 2 ) ).createAttachment( fileData, domainId ); }