### Question:
JarExportStrategy implements ExportStrategy { protected void copyJarEntry(final JarOutputStream jarOS, final JarFile file, final JarEntry entry) { try { log.debug(PreprocessConstants.MESSAGE_PREFIX + "Copying entry: " + entry.getName()); final InputStream entryStream = file.getInputStream(entry); if (entryStream == null) { throw new JarEntryReadException(entry.getName(), null); } jarOS.putNextEntry(entry); final byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = entryStream.read(buffer)) != -1) { jarOS.write(buffer, 0, bytesRead); } jarOS.closeEntry(); } catch (IOException e) { throw new JarEntryReadException(entry.getName(), e); } }  @Override void export(final JarInfo jarInfo, final Map<String, InstrumentedClassState> instrumented, final PreprocessConfig config);  }### Answer:
@Test(expected = JarEntryReadException.class) public void testCopyJarEntryFailsWithNullEntry() throws IOException { Mockito.doReturn(null).when(mockJarFile).getInputStream(Mockito.any()); spyStrategy.copyJarEntry(mockJarOS, mockJarFile, new JarEntry("fff")); }
@Test public void testCopyJarEntryWorksAndWritesToOS() throws IOException { JarEntry entry = Mockito.mock(JarEntry.class); InputStream mockStream = Mockito.mock(InputStream.class); Mockito.when(mockJarFile.getInputStream(entry)).thenReturn(mockStream); Mockito.when(mockStream.read(Mockito.any())).thenReturn(1).thenReturn(-1); spyStrategy.copyJarEntry(mockJarOS, mockJarFile, entry); Mockito.verify(mockJarOS).putNextEntry(entry); Mockito.verify(mockJarOS).write(Mockito.any(), Mockito.eq(0), Mockito.eq(1)); Mockito.verify(mockJarOS).closeEntry(); }