@Test
public void testWriteToCache() throws Throwable {

	final Path simple = Paths.get(this.simple.toURI());
	Writer writer = new StringWriter();
	final AtomicInteger hit = new AtomicInteger(), miss = new AtomicInteger();
	final Parser parser = new CachingTesseractOCRParser(tmpDir) {
		private static final long serialVersionUID = 6551690243986921730L;
		@Override
		public void cacheHit() {
			hit.incrementAndGet();
		}
		@Override
		public void cacheMiss() {
			miss.incrementAndGet();
		}
	};
	try (final InputStream in = Files.newInputStream(simple)) {
		parser.parse(in, new WriteOutContentHandler(writer), new Metadata(), new ParseContext());
	}
	Assert.assertEquals("HEAVY\nMETAL", writer.toString().trim());
	Assert.assertEquals(0, hit.get());
	Assert.assertEquals(1, miss.get());
	// Try again from the cache.
	writer = new StringWriter();
	try (final InputStream in = Files.newInputStream(simple)) {
		parser.parse(in, new WriteOutContentHandler(writer), new Metadata(), new ParseContext());
	}
	Assert.assertEquals("HEAVY\nMETAL", writer.toString().trim());
	Assert.assertEquals(1, hit.get());
	Assert.assertEquals(1, miss.get());
}