Skip to content

Commit bc3941f

Browse files
committed
fix: unit test pipeline
1 parent 4e1c7c6 commit bc3941f

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

dao-factory/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.iluwatar</groupId>
8+
<artifactId>java-design-patterns</artifactId>
9+
<version>1.26.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>dao-factory</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>21</maven.compiler.source>
16+
<maven.compiler.target>21</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.h2database</groupId>
23+
<artifactId>h2</artifactId>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.slf4j</groupId>
28+
<artifactId>slf4j-api</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>ch.qos.logback</groupId>
32+
<artifactId>logback-classic</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.mongodb</groupId>
36+
<artifactId>mongodb-driver-legacy</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.google.code.gson</groupId>
40+
<artifactId>gson</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.junit.jupiter</groupId>
45+
<artifactId>junit-jupiter-engine</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.mockito</groupId>
51+
<artifactId>mockito-core</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
</dependencies>
55+
56+
</project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.iluwatar.daofactory;
2+
3+
import static org.mockito.Mockito.mock;
4+
import static org.mockito.Mockito.verify;
5+
import static org.mockito.Mockito.when;
6+
7+
import java.util.List;
8+
import org.bson.types.ObjectId;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
11+
12+
/** {@link App} */
13+
class AppTest {
14+
/** Test perform CRUD in main class */
15+
private CustomerDAO<Long> mockLongCustomerDAO;
16+
private CustomerDAO<ObjectId> mockObjectIdCustomerDAO;
17+
18+
@BeforeEach
19+
void setUp() {
20+
mockLongCustomerDAO = mock(CustomerDAO.class);
21+
mockObjectIdCustomerDAO = mock(CustomerDAO.class);
22+
}
23+
24+
@Test
25+
void testPerformCreateCustomerWithLongId() {
26+
Customer<Long> c1 = new Customer<>(1L, "Test1");
27+
Customer<Long> c2 = new Customer<>(2L, "Test2");
28+
29+
when(mockLongCustomerDAO.findAll()).thenReturn(List.of(c1, c2));
30+
31+
App.performCreateCustomer(mockLongCustomerDAO, List.of(c1, c2));
32+
33+
verify(mockLongCustomerDAO).save(c1);
34+
verify(mockLongCustomerDAO).save(c2);
35+
verify(mockLongCustomerDAO).findAll();
36+
}
37+
38+
@Test
39+
void testPerformUpdateCustomerWithObjectId() {
40+
ObjectId id = new ObjectId();
41+
Customer<ObjectId> updatedCustomer = new Customer<>(id, "Updated");
42+
43+
when(mockObjectIdCustomerDAO.findAll()).thenReturn(List.of(updatedCustomer));
44+
45+
App.performUpdateCustomer(mockObjectIdCustomerDAO, updatedCustomer);
46+
47+
verify(mockObjectIdCustomerDAO).update(updatedCustomer);
48+
verify(mockObjectIdCustomerDAO).findAll();
49+
}
50+
51+
@Test
52+
void testPerformDeleteCustomerWithLongId() {
53+
Long id = 100L;
54+
Customer<Long> remainingCustomer = new Customer<>(1L, "Remaining");
55+
56+
when(mockLongCustomerDAO.findAll()).thenReturn(List.of(remainingCustomer));
57+
58+
App.performDeleteCustomer(mockLongCustomerDAO, id);
59+
60+
verify(mockLongCustomerDAO).delete(id);
61+
verify(mockLongCustomerDAO).findAll();
62+
}
63+
64+
@Test
65+
void testDeleteSchema() {
66+
App.deleteSchema(mockLongCustomerDAO);
67+
verify(mockLongCustomerDAO).deleteSchema();
68+
}
69+
}

0 commit comments

Comments
 (0)