### Question:
ComponentRepoVersionServiceImpl implements ComponentRepoVersionService { @Override public Optional<ComponentRepoVersion> findLatestVersion(Integer componentRepoId) { List<ComponentRepoVersion> allVersions = componentRepoVersionDao.findAllByComponentRepoId(componentRepoId); if(allVersions.isEmpty()) { return Optional.empty(); } List<ComponentRepoVersion> filtered = allVersions.stream().filter(apiRepoVersion -> !apiRepoVersion.getVersion().equals("master")).collect(Collectors.toList()); if(filtered.isEmpty()) { return Optional.empty(); } filtered.sort(new Comparator<ComponentRepoVersion>() { @Override public int compare(ComponentRepoVersion version1, ComponentRepoVersion version2) { return Version.compare(Version.parseVersion(version2.getVersion()), Version.parseVersion(version1.getVersion())); } }); return Optional.of(filtered.get(0)); }  @Override Optional<ComponentRepoVersion> findById(Integer componentRepoVersionId); @Override List<ComponentRepoVersion> findAllByComponentRepoId(Integer componentRepoId); @Override Optional<ComponentRepoVersion> findLatestVersion(Integer componentRepoId); @Override Optional<ComponentRepoVersion> findByComponentIdAndVersion(Integer componentRepoId, String version);  }### Answer:
@Test public void findLatestVersion_empty_versions() { assertThat(componentRepoVersionService.findLatestVersion(Integer.MAX_VALUE)).isEmpty(); }
@Test public void findLatestVersion_two_versions() { Integer componentRepoId = Integer.MAX_VALUE; ComponentRepoVersion version1 = new ComponentRepoVersion(); version1.setApiRepoVersionId(1); version1.setComponentRepoId(componentRepoId); version1.setName("component repo"); version1.setVersion("0.1.0"); version1.setGitTagName("v0.1.0"); version1.setAppType(AppType.WEB); version1.setBuild("dojo"); version1.setCreateUserId(1); version1.setCreateTime(LocalDateTime.now()); version1.setLastPublishTime(LocalDateTime.now()); componentRepoVersionDao.save(version1); ComponentRepoVersion version2 = new ComponentRepoVersion(); version2.setApiRepoVersionId(1); version2.setComponentRepoId(componentRepoId); version2.setName("component repo"); version2.setVersion("0.2.0"); version2.setGitTagName("v0.2.0"); version2.setAppType(AppType.WEB); version2.setBuild("dojo"); version2.setCreateUserId(1); version2.setCreateTime(LocalDateTime.now()); version2.setLastPublishTime(LocalDateTime.now()); componentRepoVersionDao.save(version2); ComponentRepoVersion master = new ComponentRepoVersion(); master.setApiRepoVersionId(1); master.setComponentRepoId(componentRepoId); master.setName("component repo"); master.setVersion("master"); master.setGitTagName("refs/heads/master"); master.setAppType(AppType.WEB); master.setBuild("dojo"); master.setCreateUserId(1); master.setCreateTime(LocalDateTime.now()); master.setLastPublishTime(LocalDateTime.now()); componentRepoVersionDao.save(master); assertThat(componentRepoVersionService.findLatestVersion(componentRepoId).get().getVersion()).isEqualTo("0.2.0"); }