@Test public void shouldEditExistingMotherChildRelationship() { Person mother = new Person(1); 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 expectedRelationship = new Relationship(mother, child, relationshipType); expect(contextService.getPersonService()).andReturn(personService).anyTimes(); expect(personService.getRelationshipTypeByName(eq(PARENT_CHILD))).andReturn(relationshipType).atLeastOnce(); expect(personService.getRelationships(null, child, relationshipType)).andReturn(oldRelationships).times(2); expect(personService.saveRelationship(EasyMock.<Relationship>anyObject())).andReturn(oldRelationship); replay(contextService, personService); Relationship motherChildRelationship = service.saveOrUpdateMotherRelationship(mother, child, true); verify(contextService, personService); assertEquals(oldRelationship,motherChildRelationship); assertEquals(expectedRelationship.getPersonA().getId(), oldRelationship.getPersonA().getId()); assertEquals(expectedRelationship.getPersonB().getId(), oldRelationship.getPersonB().getId()); assertEquals(expectedRelationship.getRelationshipType(), oldRelationship.getRelationshipType()); }
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);  }