### Question:
RepositoryTagServiceImpl implements RepositoryTagService { @Override public Optional<RepositoryTag> findLatestTag(Integer repositoryId) { return repositoryTagDao.findFirstByRepositoryIdOrderByIdDesc(repositoryId); }  @Override Optional<RepositoryTag> find(Integer repositoryId, String version); @Override Optional<RepositoryTag> findLatestTag(Integer repositoryId);  }### Answer:
@Test public void find_latest_no_data() { Optional<RepositoryTag> repositoryTagOption = repositoryTagService.findLatestTag(1); assertThat(repositoryTagOption).isEmpty(); }
@Test public void find_latest_success_one_project_two_version() { RepositoryTag repositoryTag = new RepositoryTag(); repositoryTag.setRepositoryId(1); repositoryTag.setVersion("0.1.0"); repositoryTag.setGitTagId("i-am-a-git-tag-1"); repositoryTag.setCreateUserId(2); repositoryTag.setCreateTime(LocalDateTime.now()); repositoryTagDao.save(repositoryTag); repositoryTag = new RepositoryTag(); repositoryTag.setRepositoryId(1); repositoryTag.setVersion("0.1.1"); repositoryTag.setGitTagId("i-am-a-git-tag-2"); repositoryTag.setCreateUserId(2); repositoryTag.setCreateTime(LocalDateTime.now()); repositoryTagDao.save(repositoryTag); Optional<RepositoryTag> repositoryTagOption = repositoryTagService.findLatestTag(1); assertThat(repositoryTagOption.get().getVersion()).isEqualTo("0.1.1"); }
@Test public void find_latest_success_two_project_one_version() { RepositoryTag repositoryTag = new RepositoryTag(); repositoryTag.setRepositoryId(1); repositoryTag.setVersion("0.1.0"); repositoryTag.setGitTagId("i-am-a-git-tag-1"); repositoryTag.setCreateUserId(2); repositoryTag.setCreateTime(LocalDateTime.now()); repositoryTagDao.save(repositoryTag); repositoryTag = new RepositoryTag(); repositoryTag.setRepositoryId(2); repositoryTag.setVersion("0.1.1"); repositoryTag.setGitTagId("i-am-a-git-tag-2"); repositoryTag.setCreateUserId(2); repositoryTag.setCreateTime(LocalDateTime.now()); repositoryTagDao.save(repositoryTag); Optional<RepositoryTag> repositoryTagOption = repositoryTagService.findLatestTag(1); assertThat(repositoryTagOption.get().getVersion()).isEqualTo("0.1.0"); }