@Test public void shouldNotVoidMotherChildRelationship() { Person oldMother = new Person(4); Person child = new Person(2); List<Relationship> oldRelationships = new ArrayList<Relationship>(); Relationship oldRelationship = new Relationship(oldMother, child, relationshipType); oldRelationship.setId(1); oldRelationships.add(oldRelationship); Relationship voidRelationship = oldRelationship.copy(); voidRelationship.setVoided(true); expect(contextService.getPersonService()).andReturn(personService).anyTimes(); expect(personService.getRelationshipTypeByName(eq(PARENT_CHILD))).andReturn(relationshipType); expect(personService.getRelationships(null, child, relationshipType)).andReturn(oldRelationships); replay(contextService, personService); Relationship motherChildRelationship = service.saveOrUpdateMotherRelationship(null, child, false); verify(contextService, personService); assertFalse(motherChildRelationship.isVoided()); }
public Relationship saveOrUpdateMotherRelationship(Person mother, Person child, Boolean canVoidRelationship) { Relationship motherRelationship = getMotherRelationship(child); boolean motherRelationshipCreated = mother != null && motherRelationship == null; boolean motherRelationshipEdited = mother != null && motherRelationship != null; boolean motherRelationshipRemoved = mother == null && motherRelationship != null; if (motherRelationshipCreated) motherRelationship = createMotherChildRelationship(mother, child); else if (motherRelationshipEdited) motherRelationship = updateMotherRelationship(mother, child); else if (canVoidRelationship && motherRelationshipRemoved) motherRelationship = voidRelationship(motherRelationship); return motherRelationship; }
RelationshipServiceImpl implements RelationshipService { public Relationship saveOrUpdateMotherRelationship(Person mother, Person child, Boolean canVoidRelationship) { Relationship motherRelationship = getMotherRelationship(child); boolean motherRelationshipCreated = mother != null && motherRelationship == null; boolean motherRelationshipEdited = mother != null && motherRelationship != null; boolean motherRelationshipRemoved = mother == null && motherRelationship != null; if (motherRelationshipCreated) motherRelationship = createMotherChildRelationship(mother, child); else if (motherRelationshipEdited) motherRelationship = updateMotherRelationship(mother, child); else if (canVoidRelationship && motherRelationshipRemoved) motherRelationship = voidRelationship(motherRelationship); return motherRelationship; } }
RelationshipServiceImpl implements RelationshipService { public Relationship saveOrUpdateMotherRelationship(Person mother, Person child, Boolean canVoidRelationship) { Relationship motherRelationship = getMotherRelationship(child); boolean motherRelationshipCreated = mother != null && motherRelationship == null; boolean motherRelationshipEdited = mother != null && motherRelationship != null; boolean motherRelationshipRemoved = mother == null && motherRelationship != null; if (motherRelationshipCreated) motherRelationship = createMotherChildRelationship(mother, child); else if (motherRelationshipEdited) motherRelationship = updateMotherRelationship(mother, child); else if (canVoidRelationship && motherRelationshipRemoved) motherRelationship = voidRelationship(motherRelationship); return motherRelationship; }  }
RelationshipServiceImpl implements RelationshipService { public Relationship saveOrUpdateMotherRelationship(Person mother, Person child, Boolean canVoidRelationship) { Relationship motherRelationship = getMotherRelationship(child); boolean motherRelationshipCreated = mother != null && motherRelationship == null; boolean motherRelationshipEdited = mother != null && motherRelationship != null; boolean motherRelationshipRemoved = mother == null && motherRelationship != null; if (motherRelationshipCreated) motherRelationship = createMotherChildRelationship(mother, child); else if (motherRelationshipEdited) motherRelationship = updateMotherRelationship(mother, child); else if (canVoidRelationship && motherRelationshipRemoved) motherRelationship = voidRelationship(motherRelationship); return motherRelationship; }  Relationship saveOrUpdateMotherRelationship(Person mother, Person child, Boolean canVoidRelationship); Relationship updateMotherRelationship(Person mother, Person child); Relationship voidRelationship(Relationship relationship); Relationship createMotherChildRelationship(Person mother, Person child); Relationship getMotherRelationship(Person child); void setContextService(ContextService contextService); }
RelationshipServiceImpl implements RelationshipService { public Relationship saveOrUpdateMotherRelationship(Person mother, Person child, Boolean canVoidRelationship) { Relationship motherRelationship = getMotherRelationship(child); boolean motherRelationshipCreated = mother != null && motherRelationship == null; boolean motherRelationshipEdited = mother != null && motherRelationship != null; boolean motherRelationshipRemoved = mother == null && motherRelationship != null; if (motherRelationshipCreated) motherRelationship = createMotherChildRelationship(mother, child); else if (motherRelationshipEdited) motherRelationship = updateMotherRelationship(mother, child); else if (canVoidRelationship && motherRelationshipRemoved) motherRelationship = voidRelationship(motherRelationship); return motherRelationship; }  Relationship saveOrUpdateMotherRelationship(Person mother, Person child, Boolean canVoidRelationship); Relationship updateMotherRelationship(Person mother, Person child); Relationship voidRelationship(Relationship relationship); Relationship createMotherChildRelationship(Person mother, Person child); Relationship getMotherRelationship(Person child); void setContextService(ContextService contextService);  }