Skip to content

Commit

Permalink
feat: Add unit-tests for entity/result classes
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Kopysov <[email protected]>
  • Loading branch information
o-kopysov committed Oct 12, 2023
1 parent 36d5eae commit e99f619
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/lpvs/entity/result/LPVSResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Map;

@Setter
@Getter
@AllArgsConstructor
public class LPVSResult {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/lpvs/entity/result/LPVSResultInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Date;
import java.util.List;

@Getter @Setter @AllArgsConstructor
@Getter @AllArgsConstructor
public class LPVSResultInfo {

private Long id;
Expand Down
56 changes: 56 additions & 0 deletions src/test/java/com/lpvs/entity/results/LPVSResultFileTest.java
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 src/test/java/com/lpvs/entity/results/LPVSResultInfoTest.java
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));
}
}
75 changes: 75 additions & 0 deletions src/test/java/com/lpvs/entity/results/LPVSResultTest.java
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));
}
}

0 comments on commit e99f619

Please sign in to comment.