### Question:
AppReleaseServiceImpl implements AppReleaseService { @Override public List<AppRelease> findAllByAppName(String appName) { List<AppRelease> result = appDao.findByAppName(appName).map(app -> { return appReleaseDao.findByAppIdOrderByIdDesc(app.getId()); }).orElse(Collections.emptyList()); result.forEach(release -> { release.setName(appName); }); return result; }  @Override Optional<AppRelease> findById(int releaseId); @Override Optional<AppRelease> findLatestReleaseApp(Integer appId); @Override Optional<AppRelease> findByAppIdAndVersion(Integer appId, String version); @Override List<AppRelease> findAllByAppName(String appName); @Override Optional<AppRelease> findLatestReleaseAppByAppName(String appName);  }### Answer:
@Test public void find_by_app_name_no_data() { assertThat(appReleaseService.findAllByAppName("a")).isEmpty(); }
@Test public void find_by_app_name_success() { App app = new App(); app.setAppName("app"); app.setCreateUserId(1); app.setCreateTime(LocalDateTime.now()); Integer appId = appDao.save(app).getId(); AppRelease appRelease = new AppRelease(); appRelease.setAppId(appId); appRelease.setVersion("0.0.1"); appRelease.setTitle("title"); appRelease.setDescription("description"); appRelease.setReleaseTime(LocalDateTime.now()); appRelease.setReleaseMethod(ReleaseMethod.AUTO); appRelease.setCreateUserId(1); appRelease.setCreateTime(LocalDateTime.now()); appReleaseDao.save(appRelease); List<AppRelease> releases = appReleaseService.findAllByAppName("app"); assertThat(releases).hasSize(1); assertThat(releases.get(0).getName()).isEqualTo("app"); assertThat(releases.get(0).getVersion()).isEqualTo("0.0.1"); }
@Test public void find_by_app_name_order_by_release_time() { App app = new App(); app.setAppName("app"); app.setCreateUserId(1); app.setCreateTime(LocalDateTime.now()); Integer appId = appDao.save(app).getId(); AppRelease appRelease = new AppRelease(); appRelease.setAppId(appId); appRelease.setVersion("0.0.1"); appRelease.setTitle("title"); appRelease.setDescription("description"); appRelease.setReleaseTime(LocalDateTime.now()); appRelease.setReleaseMethod(ReleaseMethod.AUTO); appRelease.setCreateUserId(1); appRelease.setCreateTime(LocalDateTime.now().minusSeconds(1)); appReleaseDao.save(appRelease); appRelease = new AppRelease(); appRelease.setAppId(appId); appRelease.setVersion("0.0.2"); appRelease.setTitle("title2"); appRelease.setDescription("description2"); appRelease.setReleaseTime(LocalDateTime.now()); appRelease.setReleaseMethod(ReleaseMethod.AUTO); appRelease.setCreateUserId(1); appRelease.setCreateTime(LocalDateTime.now().minusSeconds(1)); appReleaseDao.save(appRelease); List<AppRelease> releases = appReleaseService.findAllByAppName("app"); assertThat(releases).hasSize(2).isSortedAccordingTo(Comparator.comparing(AppRelease::getReleaseTime).reversed()); }