FossologyFileHandler { public Release getStatusInFossology(String releaseId, User user, String clearingTeam) throws TException { final Release release; final ComponentService.Iface componentClient; try { componentClient = thriftClients.makeComponentClient(); release = componentClient.getReleaseById(releaseId, user); assertNotNull(release); } catch (TException e) { log.error("cannot get release " + releaseId, e); throw e; } if (release.isSetFossologyId()) { int fossologyId = CommonUtils.toUnsignedInt(release.getFossologyId()); boolean updateInDb = true; for (String allClearingTeam : getAllClearingTeams(release, clearingTeam)) { final FossologyStatus status = fossologyUploader.getStatusInFossology(fossologyId, allClearingTeam); setFossologyStatus(release, allClearingTeam, status); if (isError(status)) { updateInDb = false; } } Optional<FossologyStatus> maxStatus = nullToEmptyMap(release.getClearingTeamToFossologyStatus()) .values() .stream() .max(FossologyStatus::compareTo); updateReleaseClearingState(release, maxStatus); if (updateInDb) { updateRelease(release, user, componentClient); } } getReleaseAndUnlockIt(releaseId, user, componentClient); return release; } @Autowired  FossologyFileHandler(AttachmentConnector attachmentConnector, FossologyUploader fossologyUploader, ThriftClients thriftClients); RequestStatus sendToFossology(String releaseId, User user, String clearingTeam); Release getStatusInFossology(String releaseId, User user, String clearingTeam);  }
@Test public void testGetStatusInFossology() throws Exception { final String id1 = "41"; final FilledAttachment filledAttachment = getMockFilledAttachment(id1); final Release release = mock(Release.class); final Release updated = mock(Release.class); when(componentService.getReleaseById(releaseId, user)).thenReturn(release, updated); spyGetFilledSourceAttachment(filledAttachment); int fossologyId = 14; when(release.isSetFossologyId()).thenReturn(true); when(release.getFossologyId()).thenReturn("" + fossologyId); String clearingTeam2 = "anotherClearingTeam"; when(fossologyUploader.getStatusInFossology(eq(fossologyId), eq(clearingTeam))) .thenReturn(FossologyStatus.IN_PROGRESS); when(fossologyUploader.getStatusInFossology(eq(fossologyId), eq(clearingTeam2))) .thenReturn(FossologyStatus.OPEN); doNothing().when(fossologyFileHandler) .setFossologyStatus(eq(release), eq(clearingTeam), eq(FossologyStatus.IN_PROGRESS), eq("" + fossologyId), eq(id1)); doReturn(ImmutableList.of(clearingTeam, clearingTeam2)) .when(fossologyFileHandler).getAllClearingTeams(release, clearingTeam); final Release resultRelease = fossologyFileHandler.getStatusInFossology(releaseId, user, clearingTeam); assertThat(resultRelease, is(sameInstance(release))); verify(fossologyFileHandler).setFossologyStatus(release, clearingTeam, FossologyStatus.IN_PROGRESS); verify(fossologyFileHandler).setFossologyStatus(release, clearingTeam2, FossologyStatus.OPEN); verify(fossologyUploader).getStatusInFossology(fossologyId, clearingTeam); verify(fossologyUploader).getStatusInFossology(fossologyId, clearingTeam2); verify(componentService, atLeastOnce()).getReleaseById(releaseId, user); verify(componentService).updateReleaseFossology(release, user); }