### Question:
NodeFactoryWithDatasetContext implements NodeFactory { @Override public Study getOrCreateStudy(Study study) throws NodeFactoryException { return factory.getOrCreateStudy(studyForDataset(study)); } NodeFactoryWithDatasetContext(NodeFactory factory, Dataset dataset); @Override Location findLocation(Location location); @Override Season createSeason(String seasonNameLower); @Override Specimen createSpecimen(Interaction interaction, Taxon taxon); @Override Specimen createSpecimen(Study study, Taxon taxon); @Override Specimen createSpecimen(Study study, Taxon taxon, RelTypes... relTypes); @Override Study createStudy(Study study); @Override Study getOrCreateStudy(Study study); @Override Study findStudy(String title); @Override Season findSeason(String seasonName); @Override Location getOrCreateLocation(Location location); @Override void setUnixEpochProperty(Specimen specimen, Date date); @Override Date getUnixEpochProperty(Specimen specimen); @Override List<Environment> getOrCreateEnvironments(Location location, String externalId, String name); @Override List<Environment> addEnvironmentToLocation(Location location, List<Term> terms); @Override Term getOrCreateBodyPart(String externalId, String name); @Override Term getOrCreatePhysiologicalState(String externalId, String name); @Override Term getOrCreateLifeStage(String externalId, String name); @Override TermLookupService getTermLookupService(); @Override AuthorIdResolver getAuthorResolver(); @Override Term getOrCreateBasisOfRecord(String externalId, String name); @Override Dataset getOrCreateDataset(Dataset dataset); @Override Interaction createInteraction(Study study); Dataset getDataset();  }### Answer:
@Test public void getOrCreateStudy() throws NodeFactoryException { NodeFactory factory = Mockito.mock(NodeFactory.class); Dataset dataset = new DatasetImpl( "some/namespace", URI.create("some:uri"), inStream -> inStream); NodeFactoryWithDatasetContext factoryWithDS = new NodeFactoryWithDatasetContext(factory, dataset); factoryWithDS.getOrCreateStudy(new StudyImpl("some title")); ArgumentCaptor<Study> argument = ArgumentCaptor.forClass(Study.class); verify(factory).getOrCreateStudy(argument.capture()); assertEquals("some title", argument.getValue().getTitle()); String sourceCitation = CitationUtil.sourceCitationLastAccessed(dataset); assertThat(StringUtils.contains(sourceCitation,"<some:uri>. Accessed at <some:uri> on"), Is.is(true)); }
@Test public void getOrCreateStudyEmptyStudySource() throws NodeFactoryException { NodeFactory factory = Mockito.mock(NodeFactory.class); Dataset dataset = new DatasetImpl("some/namespace", URI.create("some:uri"), inStream -> inStream); NodeFactoryWithDatasetContext factoryWithDS = new NodeFactoryWithDatasetContext(factory, dataset); factoryWithDS.getOrCreateStudy(new StudyImpl("some title")); ArgumentCaptor<Study> argument = ArgumentCaptor.forClass(Study.class); verify(factory).getOrCreateStudy(argument.capture()); assertEquals("some title", argument.getValue().getTitle()); }