DefaultSampleService implements SampleService, PaginatedDataSource<Sample> { public boolean isValidRelationship(Sample parent, Sample child) throws IOException { if (parent == null && !isDetailedSample(child)) { return true; } if (!isDetailedSample(child) || !isDetailedSample(parent)) { return false; } SampleClass parentClass = ((DetailedSample) parent).getSampleClass(); SampleClass childClass = ((DetailedSample) child).getSampleClass(); return sampleValidRelationshipService.getByClasses(parentClass, childClass) != null; }  void setSampleStore(SampleStore sampleStore); void setAuthorizationManager(AuthorizationManager authorizationManager); void setSampleClassService(SampleClassService sampleClassService); void setSampleValidRelationshipService(SampleValidRelationshipService sampleValidRelationshipService); void setProjectStore(ProjectStore projectStore); void setTissueOriginDao(TissueOriginDao tissueOriginDao); void setTissueTypeDao(TissueTypeDao tissueTypeDao); void setDetailedQcStatusService(DetailedQcStatusService detailedQcStatusService); void setSubprojectService(SubprojectService subprojectService); void setSamplePurposeDao(SamplePurposeDao samplePurposeDao); void setTissueMaterialDao(TissueMaterialDao tissueMaterialDao); void setLabService(LabService labService); void setBoxService(BoxService boxService); void setWorksetService(WorksetService worksetService); void setFileAttachmentService(FileAttachmentService fileAttachmentService); void setNamingSchemeHolder(NamingSchemeHolder namingSchemeHolder); @CoverageIgnore Boolean getAutoGenerateIdBarcodes(); @CoverageIgnore void setAutoGenerateIdBarcodes(Boolean autoGenerateIdBarcodes); @CoverageIgnore Boolean isUniqueExternalNameWithinProjectRequired(); @CoverageIgnore void setUniqueExternalNameWithinProjectRequired(Boolean uniqueExternalNameWithinProjectRequired); @Override Sample get(long sampleId); @Override long create(Sample sample); @Override void confirmExternalNameUniqueForProjectIfRequired(String newExternalName, Sample sample); boolean isValidRelationship(Sample parent, Sample child); @Override long update(Sample sample); @Override List<Sample> list(); @Override Long countAll(); @Override Collection<Sample> listByProjectId(long projectId); @Override List<Sample> listByIdList(List<Long> idList); @Override @Transactional(propagation = Propagation.REQUIRED) Collection<SampleIdentity> getIdentitiesByExternalNameOrAliasAndProject(String externalName, Long projectId, boolean exactMatch); @Override List<Sample> getByAlias(String alias); @Override Sample getByBarcode(String barcode); @Override void addNote(Sample sample, Note note); @Override void deleteNote(Sample sample, Long noteId); @Override AuthorizationManager getAuthorizationManager(); @Override DeletionStore getDeletionStore(); void setDeletionStore(DeletionStore deletionStore); @Override void authorizeDeletion(Sample object); @Override ValidationResult validateDeletion(Sample object); @Override void beforeDelete(Sample object); @Override void afterDelete(Sample object); @Override Sample save(Sample sample); @Override long count(Consumer<String> errorHandler, PaginationFilter... filter); @Override List<Sample> list(Consumer<String> errorHandler, int offset, int limit, boolean sortDir, String sortCol,
      PaginationFilter... filter); @Override EntityReference getNextInProject(Sample sample); @Override EntityReference getPreviousInProject(Sample sample); @Override TransactionTemplate getTransactionTemplate();  }
@Test public void testValidateRelationshipForSimpleSample() throws Exception { Sample child = new SampleImpl(); Sample parent = null; assertTrue( "Simple sample with a null parent and null DetailedSample is a valid relationship", sut.isValidRelationship(parent, child)); }