### Question:
AppReleaseRelationServiceImpl implements AppReleaseRelationService { @Override public Optional<Integer> findSingle(int appReleaseId) { List<AppReleaseRelation> result = appReleaseRelationDao.findByAppReleaseId(appReleaseId); if(result.isEmpty()) { return Optional.empty(); } if(result.size() == 1) { return Optional.of(result.get(0).getDependAppReleaseId()); } logger.error("期望最多找到一个依赖的 APP，但是却找到了 {} 个", result.size()); return Optional.empty(); }  @Override Optional<Integer> findSingle(int appReleaseId);  }### Answer:
@Test public void find_single_no_data() { Optional<Integer> dependAppReleaseIdOption = appReleaseRelationService.findSingle(1); assertThat(dependAppReleaseIdOption).isEmpty(); }
@Test public void find_single_success_one_row() { int appReleaseId = 1; AppReleaseRelation appReleaseRelation = new AppReleaseRelation(); appReleaseRelation.setAppReleaseId(appReleaseId); appReleaseRelation.setDependAppReleaseId(2); appReleaseRelationDao.save(appReleaseRelation); Optional<Integer> dependAppReleaseIdOption = appReleaseRelationService.findSingle(appReleaseId); assertThat(dependAppReleaseIdOption).get().isEqualTo(2); }
@Test public void find_single_success_two_row() { int appReleaseId = 1; AppReleaseRelation appReleaseRelation = new AppReleaseRelation(); appReleaseRelation.setAppReleaseId(appReleaseId); appReleaseRelation.setDependAppReleaseId(2); appReleaseRelationDao.save(appReleaseRelation); appReleaseRelation = new AppReleaseRelation(); appReleaseRelation.setAppReleaseId(appReleaseId); appReleaseRelation.setDependAppReleaseId(3); appReleaseRelationDao.save(appReleaseRelation); Optional<Integer> dependAppReleaseIdOption = appReleaseRelationService.findSingle(appReleaseId); assertThat(dependAppReleaseIdOption).isEmpty(); }