Source:
public void testCheckin1_ExistingContentWithChildAndParentRels_NullRels_ShouldKeepExistingRels() throws DotDataException, DotSecurityException { Contentlet blogContent = null; List<Contentlet> relatedContent = null; try { blogContent = getBlogContent(); final ContentletRelationships relationships = getACoupleOfParentAndChildrenSelfJoinRelationships(blogContent); final Relationship relationship = relationships.getRelationshipsRecords().get(0).getRelationship(); relatedContent = relationships.getRelationshipsRecords().get(0).getRecords(); final List<Category> categories = getACoupleOfCategories(); blogContent = contentletAPI.checkin(blogContent, relationships, categories, null, user, false); contentletAPI.isInodeIndexed(blogContent.getInode()); List<Contentlet> relatedContentFromDB = relationshipAPI.dbRelatedContent(relationship, blogContent); assertTrue(relatedContentFromDB.containsAll(relatedContent)); Contentlet checkedoutBlogContent = contentletAPI.checkout(blogContent.getInode(), user, false); Contentlet reCheckedinContent = contentletAPI.checkin(checkedoutBlogContent, (ContentletRelationships) null, null, null, user, false); List<Contentlet> existingRelationships = relationshipAPI.dbRelatedContent(relationship, reCheckedinContent); assertTrue(existingRelationships.containsAll(relatedContent)); } finally { contentletAPI.archive(blogContent, user, false); contentletAPI.delete(blogContent, user, false); for(Contentlet c : relatedContent){ contentletAPI.archive(c, user, false); contentletAPI.delete(c, user, false); } } }

Target:
public void testCheckin1_ExistingContentWithChildAndParentRels_NullRels_ShouldKeepExistingRels() throws DotDataException, DotSecurityException { Contentlet blogContent = null; List<Contentlet> relatedContent = null; try { blogContent = getBlogContent(); final ContentletRelationships relationships = getACoupleOfParentAndChildrenSelfJoinRelationships(blogContent); final Relationship relationship = relationships.getRelationshipsRecords().get(0).getRelationship(); relatedContent = relationships.getRelationshipsRecords().get(0).getRecords(); final List<Category> categories = getACoupleOfCategories(); blogContent = contentletAPI.checkin(blogContent, relationships, categories, null, user, false); contentletAPI.isInodeIndexed(blogContent.getInode()); List<Contentlet> relatedContentFromDB = relationshipAPI.dbRelatedContent(relationship, blogContent); assertTrue(relatedContentFromDB.containsAll(relatedContent)); Contentlet checkedoutBlogContent = contentletAPI.checkout(blogContent.getInode(), user, false); Contentlet reCheckedinContent = contentletAPI.checkin(checkedoutBlogContent, (ContentletRelationships) null, null, null, user, false); List<Contentlet> existingRelationships = relationshipAPI.dbRelatedContent(relationship, reCheckedinContent); assertTrue(existingRelationships.containsAll(relatedContent)); } finally { contentletAPI.archive(blogContent, user, false); contentletAPI.delete(blogContent, user, false); if(UtilMethods.isSet(relatedContent)) { relatedContent.forEach(content -> { try { contentletAPI.archive(content, user, false); contentletAPI.delete(content, user, false); } catch (DotDataException | DotSecurityException e) { throw new RuntimeException(e); } }); } } }