while ((entry = tarIn.getNextEntry()) != null) {
URI expectedUri = ArchiveFileUtils.toTarUri(file.toURI(), entry.getName());
IdentificationRequest mockRequest = mock(IdentificationRequest.class);
when(mockRequest.toString()).thenReturn(expectedUri.toString());
RequestIdentifier expectedIdentifier = new RequestIdentifier(expectedUri);
expectedIdentifier.setParentResourceId(expectedParentId);
expectedIdentifier.setAncestorId(10L);
when(mockRequest.getIdentifier()).thenReturn(expectedIdentifier);
mockRequests.add(mockRequest);
when(factory.newRequest(any(RequestMetaData.class), eq(expectedIdentifier)))
.thenReturn(mockRequests.get(count));
count++;
}
AsynchDroid droidCore = mock(AsynchDroid.class);
TarArchiveHandler handler = new TarArchiveHandler();
handler.setFactory(factory);
handler.setDroidCore(droidCore);
ResultHandler resultHandler = mock(ResultHandler.class);
when(resultHandler.handleDirectory(any(IdentificationResult.class),
any(ResourceId.class), anyBoolean())).thenReturn(expectedParentId);
handler.setResultHandler(resultHandler);
IdentificationRequest originalRequest = mock(IdentificationRequest.class);
RequestIdentifier originalIdentifier = new RequestIdentifier(file.toURI());
originalIdentifier.setAncestorId(10L);
originalIdentifier.setParentId(20L);
originalIdentifier.setNodeId(30L);
when(originalRequest.getIdentifier()).thenReturn(originalIdentifier);
when(originalRequest.getSourceInputStream()).thenReturn(new FileInputStream(file));
handler.handle(originalRequest);