Skip to content

Commit

Permalink
feat: Add missing unit tests for dashboard classes (#253)
Browse files Browse the repository at this point in the history
feat: Add missing unit tests for dashboard classes

Signed-off-by: Oleg Kopysov <[email protected]>
  • Loading branch information
o-kopysov authored Oct 18, 2023
1 parent ab873e8 commit 8e9a3b6
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 2 deletions.
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
37 changes: 37 additions & 0 deletions src/test/java/com/lpvs/entity/dashboard/DashBoardElementsTest.java
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());
}
}

0 comments on commit 8e9a3b6

Please sign in to comment.