Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add missing unit tests for dashboard classes #253

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
package com.lpvs.entity.dashboard;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDate;
import java.util.Map;

@Getter @Setter @AllArgsConstructor
@Getter @AllArgsConstructor
@EqualsAndHashCode
public class DashBoardElements {
private Map<LocalDate, DashboardElementsByDate> dashboardElementsMap;
}
2 changes: 1 addition & 1 deletion src/main/java/com/lpvs/entity/dashboard/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;
import java.util.Map;

@Getter @Setter @AllArgsConstructor
@Getter @AllArgsConstructor
public class Dashboard {
private String name;
private Map<String, Integer> licenseCountMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

import com.lpvs.entity.enums.Grade;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.time.LocalDate;
import java.util.Map;

@Getter @AllArgsConstructor
@EqualsAndHashCode
public class DashboardElementsByDate {
private LocalDate date;
private int participantCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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.dashboard;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DashBoardElementsTest {

private DashBoardElements dashBoardElements;

@BeforeEach
public void setUp() {
Map<LocalDate, DashboardElementsByDate> dashboardElementsMap = new HashMap<>();
dashboardElementsMap.put(LocalDate.of(2023, 10, 1), new DashboardElementsByDate(LocalDate.of(2023, 10, 1), 10, 2, new HashMap<>()));
dashboardElementsMap.put(LocalDate.of(2023, 10, 2), new DashboardElementsByDate(LocalDate.of(2023, 10, 2), 15, 5, new HashMap<>()));
dashBoardElements = new DashBoardElements(dashboardElementsMap);
}

@Test
public void testGetDashboardElementsMap() {
Map<LocalDate, DashboardElementsByDate> expectedMap = new HashMap<>();
expectedMap.put(LocalDate.of(2023, 10, 1), new DashboardElementsByDate(LocalDate.of(2023, 10, 1), 10, 2, new HashMap<>()));
expectedMap.put(LocalDate.of(2023, 10, 2), new DashboardElementsByDate(LocalDate.of(2023, 10, 2), 15, 5, new HashMap<>()));
assertEquals(expectedMap, dashBoardElements.getDashboardElementsMap());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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.dashboard;

import com.lpvs.entity.enums.Grade;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DashboardElementsByDateTest {

private DashboardElementsByDate dashboardData;

@BeforeEach
public void setUp() {
Map<Grade, Integer> riskGradeMap = new HashMap<>();
riskGradeMap.put(Grade.LOW, 5);
riskGradeMap.put(Grade.MIDDLE, 3);
dashboardData = new DashboardElementsByDate(LocalDate.of(2023, 10, 1), 10, 2, riskGradeMap);
}

@Test
public void testGetDate() {
assertEquals(LocalDate.of(2023, 10, 1), dashboardData.getDate());
}

@Test
public void testGetParticipantCount() {
assertEquals(10, dashboardData.getParticipantCount());
}

@Test
public void testGetPullRequestCount() {
assertEquals(2, dashboardData.getPullRequestCount());
}

@Test
public void testGetRiskGradeMap() {
Map<Grade, Integer> expectedRiskGradeMap = new HashMap<>();
expectedRiskGradeMap.put(Grade.LOW, 5);
expectedRiskGradeMap.put(Grade.MIDDLE, 3);

assertEquals(expectedRiskGradeMap, dashboardData.getRiskGradeMap());
}
}
67 changes: 67 additions & 0 deletions src/test/java/com/lpvs/entity/dashboard/DashboardTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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.dashboard;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DashboardTest {

private Dashboard dashboard;

@BeforeEach
public void setUp() {
Map<String, Integer> licenseCountMap = new HashMap<>();
licenseCountMap.put("License1", 10);
licenseCountMap.put("License2", 5);
dashboard = new Dashboard("Test Dashboard", licenseCountMap, 100, 20, 30, 50, 10, null);
}

@Test
public void testGetName() {
assertEquals("Test Dashboard", dashboard.getName());
}

@Test
public void testGetLicenseCountMap() {
Map<String, Integer> expectedMap = new HashMap<>();
expectedMap.put("License1", 10);
expectedMap.put("License2", 5);

assertEquals(expectedMap, dashboard.getLicenseCountMap());
}

@Test
public void testTotalDetectionCount() {
assertEquals(100, dashboard.getTotalDetectionCount());
}

@Test
public void testHighSimilarityCount() {
assertEquals(20, dashboard.getHighSimilarityCount());
}

@Test
public void testTotalIssueCount() {
assertEquals(30, dashboard.getTotalIssueCount());
}

@Test
public void testTotalParticipantsCount() {
assertEquals(50, dashboard.getTotalParticipantsCount());
}

@Test
public void testTotalRepositoryCount() {
assertEquals(10, dashboard.getTotalRepositoryCount());
}
}
31 changes: 31 additions & 0 deletions src/test/java/com/lpvs/entity/enums/GradeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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.enums;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class GradeTest {

@Test
public void testGradeValues() {
assertEquals(Grade.SERIOUS, Grade.valueOf("SERIOUS"));
assertEquals(Grade.HIGH, Grade.valueOf("HIGH"));
assertEquals(Grade.MIDDLE, Grade.valueOf("MIDDLE"));
assertEquals(Grade.LOW, Grade.valueOf("LOW"));
assertEquals(Grade.NONE, Grade.valueOf("NONE"));
}

@Test
public void testToString() {
assertEquals("SERIOUS", Grade.SERIOUS.toString());
assertEquals("HIGH", Grade.HIGH.toString());
assertEquals("MIDDLE", Grade.MIDDLE.toString());
assertEquals("LOW", Grade.LOW.toString());
assertEquals("NONE", Grade.NONE.toString());
}
}
Loading