-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add unit-tests for entity/result classes
Signed-off-by: Oleg Kopysov <[email protected]>
- Loading branch information
Showing
5 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/java/com/lpvs/entity/results/LPVSResultFileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright (c) 2023, Samsung Electronics Co., Ltd. All rights reserved. | ||
* | ||
* Use of this source code is governed by a MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package com.lpvs.entity.results; | ||
|
||
import com.lpvs.entity.result.LPVSResultFile; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
|
||
public class LPVSResultFileTest { | ||
|
||
private LPVSResultFile lpvsResultFile; | ||
Long id = 1L; | ||
String path = "example/file.txt"; | ||
String componentFileUrl = "https://example.com/file.txt"; | ||
String matchLine = "This is a matching line"; | ||
String matchValue = "LicenseA"; | ||
String status = "license.licenseUsage"; | ||
String licenseSpdx = "LicenseA"; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
lpvsResultFile = new LPVSResultFile(id, path, componentFileUrl, matchLine, matchValue, status, licenseSpdx); | ||
} | ||
|
||
@Test | ||
public void testGetters() { | ||
// Test getters | ||
assertEquals(1L, lpvsResultFile.getId().longValue()); | ||
assertEquals("example/file.txt", lpvsResultFile.getPath()); | ||
assertEquals("https://example.com/file.txt", lpvsResultFile.getComponentFileUrl()); | ||
assertEquals("This is a matching line", lpvsResultFile.getMatchLine()); | ||
assertEquals("LicenseA", lpvsResultFile.getMatchValue()); | ||
assertEquals("license.licenseUsage", lpvsResultFile.getStatus()); | ||
assertEquals("LicenseA", lpvsResultFile.getLicenseSpdx()); | ||
} | ||
|
||
@Test | ||
public void testInequality() { | ||
// Test inequality when objects are not the same | ||
LPVSResultFile file1 = new LPVSResultFile(1L, "example/file.txt", "https://example.com/file.txt", | ||
"This is a matching line", "LicenseA", "license.licenseUsage", "LicenseA"); | ||
LPVSResultFile file2 = new LPVSResultFile(2L, "another/file.txt", "https://example.com/another.txt", | ||
"This is not a matching line", "LicenseB", "license.licenseUsage", "LicenseB"); | ||
assertFalse(file1.equals(file2)); | ||
assertFalse(file2.equals(file1)); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/lpvs/entity/results/LPVSResultInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright (c) 2023, Samsung Electronics Co., Ltd. All rights reserved. | ||
* | ||
* Use of this source code is governed by a MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package com.lpvs.entity.results; | ||
|
||
import com.lpvs.entity.result.LPVSResultInfo; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class LPVSResultInfoTest { | ||
|
||
private LPVSResultInfo lpvsResultInfo; | ||
Long id = 1L; | ||
Date scanDate = new Date(); | ||
String repositoryName = "example/repository"; | ||
String status = "Success"; | ||
List<String> detectedLicenses = Arrays.asList("LicenseA", "LicenseB"); | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
lpvsResultInfo = new LPVSResultInfo(id, scanDate, repositoryName, status, detectedLicenses); | ||
} | ||
|
||
@Test | ||
public void testGetters() { | ||
// Test getters | ||
assertEquals(1L, lpvsResultInfo.getId().longValue()); | ||
assertNotNull(lpvsResultInfo.getScanDate()); | ||
assertEquals("example/repository", lpvsResultInfo.getRepositoryName()); | ||
assertEquals("Success", lpvsResultInfo.getStatus()); | ||
assertEquals(Arrays.asList("LicenseA", "LicenseB"), lpvsResultInfo.getDetectedLicenses()); | ||
} | ||
|
||
@Test | ||
public void testInequality() { | ||
// Test inequality when objects are not the same | ||
LPVSResultInfo info1 = new LPVSResultInfo(1L, new Date(), "example/repository", "Success", Arrays.asList("LicenseA", "LicenseB")); | ||
LPVSResultInfo info2 = new LPVSResultInfo(2L, new Date(), "another/repository", "Failure", Arrays.asList("LicenseC")); | ||
assertFalse(info1.equals(info2)); | ||
assertFalse(info2.equals(info1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) 2023, Samsung Electronics Co., Ltd. All rights reserved. | ||
* | ||
* Use of this source code is governed by a MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
package com.lpvs.entity.results; | ||
|
||
import com.lpvs.entity.result.LPVSResult; | ||
import com.lpvs.entity.result.LPVSResultFile; | ||
import com.lpvs.entity.result.LPVSResultInfo; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class LPVSResultTest { | ||
|
||
private LPVSResult lpvsResult; | ||
List<LPVSResultFile> resultFileList = new ArrayList<>(); | ||
LPVSResultInfo resultInfo = new LPVSResultInfo(null, null, null, null, null); | ||
Long count = 42L; | ||
Map<String, Integer> licenseCountMap = new HashMap<>(); | ||
String pullNumber = "123"; | ||
Boolean hasIssue = true; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
licenseCountMap.put("LicenseA", 1); | ||
lpvsResult = new LPVSResult(resultFileList, resultInfo, count, licenseCountMap, pullNumber, hasIssue); | ||
} | ||
|
||
@Test | ||
public void testGetters() { | ||
// Test getters | ||
assertEquals(resultFileList, lpvsResult.getLpvsResultFileList()); | ||
assertEquals(resultInfo, lpvsResult.getLpvsResultInfo()); | ||
assertEquals(count, lpvsResult.getCount()); | ||
assertEquals(licenseCountMap, lpvsResult.getLicenseCountMap()); | ||
assertEquals(pullNumber, lpvsResult.getPullNumber()); | ||
assertEquals(hasIssue, lpvsResult.getHasIssue()); | ||
} | ||
|
||
@Test | ||
public void testInequality() { | ||
// Test inequality when objects are not the same | ||
LPVSResult result1 = new LPVSResult(resultFileList, resultInfo, count, licenseCountMap, pullNumber, hasIssue); | ||
LPVSResult result2 = new LPVSResult(resultFileList, resultInfo, count, licenseCountMap, "456", hasIssue); | ||
assertFalse(result1.equals(result2)); | ||
assertFalse(result2.equals(result1)); | ||
} | ||
|
||
@Test | ||
public void testDifferentClassesEquality() { | ||
// Test equality with an object of a different class | ||
LPVSResult result1 = new LPVSResult(resultFileList, resultInfo, count, licenseCountMap, pullNumber, hasIssue); | ||
Object result2 = new Object(); | ||
assertFalse(result1.equals(result2)); | ||
} | ||
|
||
@Test | ||
public void testInequalityWithNullValues() { | ||
// Test inequality when some values are null | ||
LPVSResult result1 = new LPVSResult(resultFileList, resultInfo, count, licenseCountMap, pullNumber, hasIssue); | ||
LPVSResult result2 = new LPVSResult(null, null, null, null, null, null); | ||
assertFalse(result1.equals(result2)); | ||
assertFalse(result2.equals(result1)); | ||
} | ||
} |