@Test
  public void shouldRemovePhone() {
    OutsiderTeacher teacher = scenarioHelper.createOutsiderTeacher();

    assertThat(teacher.getContact().getPhones()).isNotEmpty();

    for (Phone phone : teacher.getContact().getPhones()) {
      outsiderTeacherManager.removePhone(phone.getId());
    }
    assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getPhones())
        .isEmpty();
    assertThat(phoneRepository.findAll()).isEmpty();
  }
  @Test
  public void shouldAddPhone() {
    OutsiderTeacher teacher = scenarioHelper.createEmptyOutsiderTeacher();
    Phone phone = PhoneTest.createOne(scenarioHelper.createPhoneType());

    assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getPhones())
        .isEmpty();
    Phone saved = outsiderTeacherManager.addPhone(teacher.getId(), phone);

    assertThat(phoneRepository.findAll()).hasSize(1);
    assertThat(outsiderTeacherManager.findOneById(teacher.getId()).getContact().getPhones())
        .hasSize(1);
    assertThat(saved.getId()).isNotNull();
  }
  public Phone addPhone(Long teacherId, Phone model) {
    if (teacherId == null) {
      throw new IllegalArgumentException(
          "Cannot find a " + Teacher.class.getName() + " with a null id.");
    }
    if (model == null) {
      throw new IllegalArgumentException("Cannot persist a null " + Phone.class.getName());
    }
    if (model.getId() != null) {
      throw new AlreadyDefinedInOnNonPersistedEntity(
          "Cannot persist a " + Phone.class.getName() + " which already has an ID.");
    }

    model = phoneManager.create(model);

    Teacher fetched = findOneById(teacherId);
    fetched.getContact().addPhone(model);
    teacherRepository.saveAndFlush(new TeacherDomain(fetched));
    return model;
  }
 @Test(expected = AlreadyDefinedInOnNonPersistedEntity.class)
 public void shouldFailAddPhoneWithPhoneHavingIdAlreadyDefined() {
   Phone model = PhoneTest.createOne();
   model.setId(12L);
   outsiderTeacherManager.addPhone(12L, model);
 }