RelationshipServiceImpl implements RelationshipService { @Override public void delete(Context context, Relationship relationship) throws SQLException, AuthorizeException { delete(context, relationship, relationship.getRelationshipType().isCopyToLeft(), relationship.getRelationshipType().isCopyToRight()); }  @Override Relationship create(Context context); @Override Relationship create(Context c, Item leftItem, Item rightItem, RelationshipType relationshipType,
                               int leftPlace, int rightPlace); @Override Relationship create(Context c, Item leftItem, Item rightItem, RelationshipType relationshipType,
                               int leftPlace, int rightPlace, String leftwardValue, String rightwardValue); @Override Relationship create(Context context, Relationship relationship); @Override void updatePlaceInRelationship(Context context, Relationship relationship); @Override void updateItem(Context context, Item relatedItem); @Override int findNextLeftPlaceByLeftItem(Context context, Item item); @Override int findNextRightPlaceByRightItem(Context context, Item item); Relationship find(Context context, int id); @Override List<Relationship> findByItem(Context context, Item item); @Override List<Relationship> findByItem(Context context, Item item, Integer limit, Integer offset); @Override List<Relationship> findAll(Context context); @Override List<Relationship> findAll(Context context, Integer limit, Integer offset); @Override void update(Context context, Relationship relationship); @Override void update(Context context, List<Relationship> relationships); @Override void delete(Context context, Relationship relationship); @Override void delete(Context context, Relationship relationship, boolean copyToLeftItem, boolean copyToRightItem); List<Relationship> findByItemAndRelationshipType(Context context, Item item,
                                                            RelationshipType relationshipType, boolean isLeft); @Override List<Relationship> findByItemAndRelationshipType(Context context, Item item,
                                                            RelationshipType relationshipType); @Override List<Relationship> findByItemAndRelationshipType(Context context, Item item,
                                                            RelationshipType relationshipType, int limit, int offset); @Override List<Relationship> findByItemAndRelationshipType(Context context, Item item,
                                                            RelationshipType relationshipType, boolean isLeft,
                                                            int limit, int offset); @Override List<Relationship> findByRelationshipType(Context context, RelationshipType relationshipType); @Override List<Relationship> findByRelationshipType(Context context, RelationshipType relationshipType, Integer limit,
                                                     Integer offset); @Override List<Relationship> findByTypeName(Context context, String typeName); @Override List<Relationship> findByTypeName(Context context, String typeName, Integer limit, Integer offset); @Override int countTotal(Context context); @Override int countByItem(Context context, Item item); @Override int countByRelationshipType(Context context, RelationshipType relationshipType); @Override int countByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType); @Override int countByTypeName(Context context, String typeName);  }
@Test public void testDelete() throws Exception { List<Relationship> leftTypelist = new ArrayList<>(); List<Relationship> rightTypelist = new ArrayList<>(); Item leftItem = mock(Item.class); Item rightItem = mock(Item.class); RelationshipType testRel = new RelationshipType(); EntityType leftEntityType = mock(EntityType.class); EntityType rightEntityType = mock(EntityType.class); testRel.setLeftType(leftEntityType); testRel.setRightType(rightEntityType); testRel.setLeftwardType("Entitylabel"); testRel.setRightwardType("Entitylabel"); testRel.setLeftMinCardinality(0); testRel.setRightMinCardinality(0); relationship = getRelationship(leftItem, rightItem, testRel, 0,0); leftTypelist.add(relationship); rightTypelist.add(relationship); when(virtualMetadataPopulator.isUseForPlaceTrueForRelationshipType(relationship.getRelationshipType(), true)) .thenReturn(true); when(authorizeService.authorizeActionBoolean(context, relationship.getLeftItem(), Constants.WRITE)) .thenReturn(true); when(relationshipService.findByItem(context,leftItem)).thenReturn(leftTypelist); when(relationshipService.findByItem(context,rightItem)).thenReturn(rightTypelist); when(relationshipService.findByItemAndRelationshipType(context, leftItem, testRel, true)) .thenReturn(leftTypelist); when(relationshipService.findByItemAndRelationshipType(context, rightItem, testRel, false)) .thenReturn(rightTypelist); when(relationshipService.find(context,0)).thenReturn(relationship); relationshipService.delete(context, relationship); Mockito.verify(relationshipDAO).delete(context, relationship); }