DummyDocEmitter implements DocEmitter { @Override public void emit(SinkFactory factory, Doc doc) { if (testDoc != doc) { throw new RuntimeException("testDoc and doc argument were not the same"); } final Sink sink = factory.createSink(className); try { sink.write(doc.srcInfo); } finally { sink.close(); } } DummyDocEmitter(Doc testDoc, String className); @Override void emit(SinkFactory factory, Doc doc);  }
@Test public void testHappy() { final Doc testDoc = new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()); final DocEmitter dummyDocEmitter = new DummyDocEmitter(testDoc, "SomeClass"); final StringSinkFactory factory = new StringSinkFactory("baseDir"); dummyDocEmitter.emit(factory, testDoc); assertEquals("some source", factory.getResults().get("SomeClass")); }
@Test public void testWrongDoc() { final Doc testDoc = new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()); final Doc doc = new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()); final DocEmitter dummyDocEmitter = new DummyDocEmitter(testDoc, "SomeClass"); final StringSinkFactory factory = new StringSinkFactory("baseDir"); try { dummyDocEmitter.emit(factory, doc); fail("Did not get an exception with the wrong doc, got " + factory.getResults().get("SomeClass")); } catch (RuntimeException e) { } }