Skip to content

Commit

Permalink
feat: Add unit test for LPVSScanossDetectService (#265)
Browse files Browse the repository at this point in the history
feat: Add unit test for LPVSScanossDetectServiceTest

Signed-off-by: Oleg Kopysov <[email protected]>
  • Loading branch information
o-kopysov authored Oct 26, 2023
1 parent e63f3b7 commit 3ff0ab3
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,24 @@ public void testCheckLicense() {
scanossDetectService.checkLicenses(webhookConfig);
Assertions.assertNotNull(scanossDetectService.checkLicenses(webhookConfig));
}

@Test
public void testWithNullHeadCommitSHA() {
LPVSLicenseService licenseService = Mockito.mock(LPVSLicenseService.class);
LPVSGitHubService gitHubService = Mockito.mock(LPVSGitHubService.class);
LPVSLicenseRepository lpvsLicenseRepository = Mockito.mock(LPVSLicenseRepository.class);
LPVSScanossDetectService scanossDetectService = new LPVSScanossDetectService(false, licenseService, gitHubService, lpvsLicenseRepository);
String licenseConflictsSource = "scanner";
LPVSQueue webhookConfig = Mockito.mock(LPVSQueue.class);
Mockito.when(LPVSWebhookUtil.getRepositoryName(webhookConfig)).thenReturn("A");
Mockito.when(webhookConfig.getHeadCommitSHA()).thenReturn(null);
Mockito.when(webhookConfig.getPullRequestUrl()).thenReturn("A/B");
Mockito.when(licenseService.findLicenseBySPDX("MIT")).thenReturn(new LPVSLicense(){{
setLicenseName("MIT");
setLicenseId(1L);
setSpdxId("MIT");
}});
ReflectionTestUtils.setField(licenseService, "licenseConflictsSource", licenseConflictsSource);
Assertions.assertNotNull(scanossDetectService.checkLicenses(webhookConfig));
}
}

0 comments on commit 3ff0ab3

Please sign in to comment.