### Question:
LinkerDOI implements IndexerNeo4j { public static void linkStudy(DOIResolver doiResolver, StudyNode study) { if (shouldResolve(study)) { try { DOI doiResolved = doiResolver.resolveDoiFor(study.getCitation()); setDOIForStudy(study, doiResolved); } catch (IOException e) { LOG.warn("failed to lookup doi for citation [" + study.getCitation() + "] with id [" + study.getTitle() + "]", e); } } } LinkerDOI();  LinkerDOI(DOIResolver resolver); @Override void index(GraphServiceFactory factory); void resolveBatch(DOIResolver doiResolver, Map<String, StudyNode> batch); void resolve(DOIResolver doiResolver, Map<String, StudyNode> batch, Collection<String> citations); String logProgress(int counter, StopWatch stopWatch); static void linkStudy(DOIResolver doiResolver, StudyNode study); static boolean shouldResolve(Study study); static final int BATCH_SIZE; }### Answer:
@Test public void createStudyDOIlookup() throws NodeFactoryException { StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", null, "some citation")); LinkerDOI.linkStudy(new DOIResolverThatExplodes(), study); assertThat(study.getCitation(), is("some citation")); assertThat(study.getTitle(), is("title")); }
@Test public void createStudyDOIlookupCitationWithURL() throws NodeFactoryException { StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("title", null, "http: LinkerDOI.linkStudy(new DOIResolverThatFails(), study); assertThat(study.getTitle(), is("title")); }
@Test public void createStudyDOIlookupCitationEnabled() throws NodeFactoryException { StudyImpl title = new StudyImpl("title", null, "some citation"); DatasetImpl originatingDataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put(DatasetConstant.SHOULD_RESOLVE_REFERENCES, true); originatingDataset.setConfig(objectNode); title.setOriginatingDataset(originatingDataset); StudyNode study = getNodeFactory().getOrCreateStudy(title); LinkerDOI.linkStudy(new TestDOIResolver(), study); assertThat(study.getDOI().toString(), is("10.some/some citation")); assertThat(study.getExternalId(), is("https: assertThat(study.getCitation(), is("some citation")); assertThat(study.getTitle(), is("title")); }
@Test public void addDOIToStudy() throws NodeFactoryException { DOIResolver doiResolver = new DOIResolver() { @Override public Map<String, DOI> resolveDoiFor(Collection<String> references) throws IOException { Map<String, DOI> doiMap = new HashMap<>(); for (String reference : references) { doiMap.put(reference, resolveDoiFor(reference)); } return doiMap; } @Override public DOI resolveDoiFor(String reference) throws IOException { return new DOI("1234", "567"); } }; StudyNode study = getNodeFactory().getOrCreateStudy(new StudyImpl("my title", null, ExternalIdUtil.toCitation("my contr", "some description", null))); LinkerDOI.linkStudy(doiResolver, study); assertThat(study.getDOI().toString(), is("10.1234/567")); assertThat(study.getExternalId(), is("https: assertThat(study.getCitation(), is("my contr. some description")); StudyImpl study1 = new StudyImpl("my other title", null, ExternalIdUtil.toCitation("my contr", "some description", null)); assertThat(study1.getExternalId(), nullValue()); study = getNodeFactory().getOrCreateStudy(study1); assertThat(study.getExternalId(), nullValue()); LinkerDOI.linkStudy(new DOIResolverThatExplodes(), study); assertThat(study.getDOI(), nullValue()); assertThat(study.getExternalId(), nullValue()); assertThat(study.getCitation(), is("my contr. some description")); }