FossologyFileHandler { protected void setFossologyStatus(Release release, final String clearingTeam, FossologyStatus status) { setFossologyStatus(release, clearingTeam, status, null, null); } @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 testUpdateFossologyStatusAddTheNewStatus() { Release release = mock(Release.class); final String clearingTeam2 = "team2"; final Map<String, FossologyStatus> existingStatuses = newHashMap(); existingStatuses.put(clearingTeam, FossologyStatus.SENT); existingStatuses.put(clearingTeam2, FossologyStatus.CLOSED); when(release.getClearingTeamToFossologyStatus()).thenReturn(existingStatuses); fossologyFileHandler.setFossologyStatus(release, clearingTeam, FossologyStatus.SCANNING); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { try { @SuppressWarnings("unchecked") Map<String, FossologyStatus> statusMap = (Map<String, FossologyStatus>) invocation.getArguments()[0]; assertThat(statusMap, hasEntry(clearingTeam, FossologyStatus.SCANNING)); assertThat(statusMap, hasEntry(clearingTeam2, FossologyStatus.CLOSED)); assertThat(statusMap.keySet(), containsInAnyOrder(clearingTeam, clearingTeam2)); } catch (ClassCastException e) { fail("status was supposed to be a map :-/" + e.getMessage()); } return null; } }).when(release).setClearingTeamToFossologyStatus(anyMapOf(String.class, FossologyStatus.class)); verify(release).setClearingTeamToFossologyStatus(anyMapOf(String.class, FossologyStatus.class)); }
@Test public void testUpdateFossologyStatusForTheFirstTimeCreatesTheStatusMap() { Release release = mock(Release.class); fossologyFileHandler.setFossologyStatus(release, clearingTeam, FossologyStatus.SCANNING, "13", "14"); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { try { @SuppressWarnings("unchecked") Map<String, FossologyStatus> statusMap = (Map<String, FossologyStatus>) invocation.getArguments()[0]; assertThat(statusMap, hasEntry(clearingTeam, FossologyStatus.SCANNING)); assertThat(statusMap.keySet(), containsInAnyOrder(clearingTeam)); } catch (ClassCastException e) { fail("status was supposed to be a map :-/" + e.getMessage()); } return null; } }).when(release).setClearingTeamToFossologyStatus(anyMapOf(String.class, FossologyStatus.class)); verify(release).setClearingTeamToFossologyStatus(anyMapOf(String.class, FossologyStatus.class)); verify(release).setFossologyId("13"); verify(release).setAttachmentInFossology("14"); }