Skip to content

Commit

Permalink
feat: Add unit tests for entity\history classes (#244)
Browse files Browse the repository at this point in the history
* feat: Add unit tests for entity\history classes

Signed-off-by: Oleg Kopysov <[email protected]>

* fix: Apply fixes after code review

Signed-off-by: Oleg Kopysov <[email protected]>

---------

Signed-off-by: Oleg Kopysov <[email protected]>
  • Loading branch information
o-kopysov authored Oct 13, 2023
1 parent b85f442 commit c3bd273
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/lpvs/entity/history/LPVSHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import lombok.Getter;
import lombok.Setter;

@Getter @Setter @AllArgsConstructor
@Getter @AllArgsConstructor
public class LPVSHistory {
private String scanDate;
private String repositoryName;
Expand Down
58 changes: 58 additions & 0 deletions src/test/java/com/lpvs/entity/history/HistoryEntityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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.history;

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

import java.util.ArrayList;
import java.util.List;

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

public class HistoryEntityTest {

private HistoryEntity historyEntity;
private List<LPVSHistory> lpvsHistories = new ArrayList<>();
private Long count = 2L;

@BeforeEach
public void setUp() {
lpvsHistories.add(new LPVSHistory("2023-10-12", "example/repository1", 1L,
"https://example.com/pull/1", "Success", "john.doe", "pull/1", true));
lpvsHistories.add(new LPVSHistory("2023-10-12", "example/repository2", 2L,
"https://example.com/pull/2", "Success", "john.doe", "pull/2", true));
historyEntity = new HistoryEntity(lpvsHistories, count);
}

@Test
public void testGetters() {
// Test getters
assertEquals(2, historyEntity.getLpvsHistories().size());
assertEquals(2L, historyEntity.getCount().longValue());
}

@Test
public void testInequality() {
// Test inequality when objects are not the same
List<LPVSHistory> lpvsHistories1 = new ArrayList<>();
lpvsHistories1.add(new LPVSHistory("2023-10-12", "example/repository1", 1L,
"https://example.com/pull/1", "Success", "john.doe", "pull/1", true));
lpvsHistories1.add(new LPVSHistory("2023-10-12", "example/repository2", 2L,
"https://example.com/pull/2", "Success", "john.doe", "pull/2", true));
Long count1 = 2L;
HistoryEntity entity1 = new HistoryEntity(lpvsHistories1, count1);
List<LPVSHistory> lpvsHistories2 = new ArrayList<>();
lpvsHistories2.add(new LPVSHistory("2023-10-12", "example/repository3", 3L,
"https://example.com/pull/3", "Success", "john.doe", "pull/3", true));
Long count2 = 1L;
HistoryEntity entity2 = new HistoryEntity(lpvsHistories2, count2);
assertFalse(entity1.equals(entity2));
assertFalse(entity2.equals(entity1));
}
}
60 changes: 60 additions & 0 deletions src/test/java/com/lpvs/entity/history/HistoryPageEntityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* 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.history;

import com.lpvs.entity.LPVSPullRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;

import java.util.ArrayList;
import java.util.List;

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

public class HistoryPageEntityTest {

private HistoryPageEntity historyPageEntity;
private List<LPVSPullRequest> pullRequests = new ArrayList<>();
private Page<LPVSPullRequest> prPage;
private Long count = 2L;

@BeforeEach
public void setUp() {
pullRequests.add(new LPVSPullRequest(1L, null, "Title 1", null, null, null, null, null, null, null));
pullRequests.add(new LPVSPullRequest(2L, null, "Title 2", null, null, null, null, null, null, null));
prPage = new PageImpl<>(pullRequests);
historyPageEntity = new HistoryPageEntity(prPage, count);
}

@Test
public void testGetters() {
// Test getters
assertEquals(2, historyPageEntity.getPrPage().getSize());
assertEquals(2L, historyPageEntity.getCount().longValue());
}

@Test
public void testInequality() {
// Test inequality when objects are not the same
List<LPVSPullRequest> pullRequests1 = new ArrayList<>();
pullRequests1.add(new LPVSPullRequest(1L, null, "Title 1", null, null, null, null, null, null, null));
pullRequests1.add(new LPVSPullRequest(2L, null, "Title 2", null, null, null, null, null, null, null));
Page<LPVSPullRequest> prPage1 = new PageImpl<>(pullRequests1);
Long count1 = 2L;
HistoryPageEntity entity1 = new HistoryPageEntity(prPage1, count1);
List<LPVSPullRequest> pullRequests2 = new ArrayList<>();
pullRequests2.add(new LPVSPullRequest(3L, null, "Title 3", null, null, null, null, null, null, null));
Page<LPVSPullRequest> prPage2 = new PageImpl<>(pullRequests2);
Long count2 = 1L;
HistoryPageEntity entity2 = new HistoryPageEntity(prPage2, count2);
assertFalse(entity1.equals(entity2));
assertFalse(entity2.equals(entity1));
}
}
57 changes: 57 additions & 0 deletions src/test/java/com/lpvs/entity/history/LPVSHistoryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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.history;

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 static org.junit.jupiter.api.Assertions.assertTrue;


public class LPVSHistoryTest {

private LPVSHistory lpvsHistory;
private String scanDate = "2023-10-12";
private String repositoryName = "example/repository";
private Long pullRequestId = 1L;
private String url = "https://example.com/pull/1";
private String status = "Success";
private String sender = "john.doe";
private String pullNumber = "pull/1";
private Boolean hasIssue = true;

@BeforeEach
public void setUp() {
lpvsHistory = new LPVSHistory(scanDate, repositoryName, pullRequestId, url, status, sender, pullNumber, hasIssue);
}

@Test
public void testGetters() {
// Test getters
assertEquals("2023-10-12", lpvsHistory.getScanDate());
assertEquals("example/repository", lpvsHistory.getRepositoryName());
assertEquals(1L, lpvsHistory.getPullRequestId().longValue());
assertEquals("https://example.com/pull/1", lpvsHistory.getUrl());
assertEquals("Success", lpvsHistory.getStatus());
assertEquals("john.doe", lpvsHistory.getSender());
assertEquals("pull/1", lpvsHistory.getPullNumber());
assertTrue(lpvsHistory.getHasIssue());
}

@Test
public void testInequality() {
// Test inequality when objects are not the same
LPVSHistory history1 = new LPVSHistory("2023-10-12", "example/repository", 1L,
"https://example.com/pull/1", "Success", "john.doe", "pull/1", true);
LPVSHistory history2 = new LPVSHistory("2023-10-13", "another/repository", 2L,
"https://example.com/pull/2", "Failure", "jane.doe", "pull/2", false);
assertFalse(history1.equals(history2));
assertFalse(history2.equals(history1));
}
}

0 comments on commit c3bd273

Please sign in to comment.