ContainerSignatureMatch { public void matchBinaryContent(String entryName, ByteReader content) { boolean matched = true; if (unmatchedFiles.contains(entryName)) { Map<String, ContainerFile> sigFiles = signature.getFiles(); InternalSignatureCollection binSigs = sigFiles.get(entryName).getCompiledBinarySignatures(); if (binSigs != null) { matched = binSigs.getMatchingSignatures(content, maxBytesToScan).size() > 0; } if (matched) { unmatchedFiles.remove(entryName); } } } ContainerSignatureMatch(ContainerSignature sig, long maxBytesToScan); Set<String> getUnmatchedFiles(); boolean isMatch(); void matchFileEntry(String entryName); boolean needsBinaryMatch(String entryName); void matchBinaryContent(String entryName, ByteReader content); ContainerSignature getSignature();  }
@Test public void shouldDelegateToBinarySignatureMatcherWhenBinarySignatureExists() { ByteReader mockBinaryContent = mock(ByteReader.class); ContainerFile containerFile = mock(ContainerFile.class); Map<String, ContainerFile> files = new HashMap<String, ContainerFile>(); files.put("header/siardversion/2.1/", containerFile); ContainerSignature sig = mock(ContainerSignature.class); when(sig.getFiles()).thenReturn(files); InternalSignatureCollection mockSignatures = mock(InternalSignatureCollection.class); when(containerFile.getCompiledBinarySignatures()).thenReturn(mockSignatures); ContainerSignatureMatch match = new ContainerSignatureMatch(sig, -1L); match.matchBinaryContent("header/siardversion/2.1/", mockBinaryContent); verify(mockSignatures, times(1)).getMatchingSignatures(mockBinaryContent, -1L); }