TxcExportUtility { protected void addAudioFilesToZip(Map<String, Boolean> filePaths, ZipOutputStream zipOutputStream) throws ExportException { try { for (Map.Entry<String, Boolean> entry : filePaths.entrySet()) { String baseFilename = new File(entry.getKey()).getName(); zipOutputStream.putNextEntry(new ZipEntry(baseFilename)); FileInputStream translationAudioInput = getFileInputStream(entry); byte[] buffer = new byte[BUFFER_SIZE]; int read; while ((read = translationAudioInput.read(buffer)) != -1) { zipOutputStream.write(buffer, 0, read); } translationAudioInput.close(); zipOutputStream.closeEntry(); } } catch (IOException e) { throw new ExportException(ExportException.ExportProblem.WRITE_ERROR, e); } } TxcExportUtility(InputStreamBuilder inputStreamBuilder); void exportDeck(Deck deck, String exportedDeckName, File file);  }
@Test public void shouldRetrieveAssetAudioFilesFromAssetStream() throws Exception { String assetName = "anAssetName"; when(fileInputStream.read(any(byte[].class))).thenReturn(-1); when(inputStreamBuilder.getAssetInputStream(assetName)).thenReturn(fileInputStream); HashMap<String, Boolean> filePaths = new HashMap<>(); filePaths.put(assetName, true); txcExportUtility.addAudioFilesToZip(filePaths, zipOutputStream); verify(inputStreamBuilder).getAssetInputStream(assetName); }
@Test public void shouldWriteAssetTranslationAudioToZipOutputStream() throws Exception { String assetName = "anAssetName"; when(fileInputStream.read(any(byte[].class))).thenReturn(15).thenReturn(-1); when(inputStreamBuilder.getAssetInputStream(assetName)).thenReturn(fileInputStream); HashMap<String, Boolean> filePaths = new HashMap<>(); filePaths.put(assetName, true); txcExportUtility.addAudioFilesToZip(filePaths, zipOutputStream); ArgumentCaptor<byte[]> bufferCaptor = ArgumentCaptor.forClass(byte[].class); ArgumentCaptor<ZipEntry> zipEntryCaptor = ArgumentCaptor.forClass(ZipEntry.class); verify(fileInputStream, times(2)).read(bufferCaptor.capture()); verify(zipOutputStream).putNextEntry(zipEntryCaptor.capture()); assertEquals(assetName, zipEntryCaptor.getValue().getName()); verify(zipOutputStream).write(bufferCaptor.getValue(), 0, 15); }