Skip to content

Commit 5f5e008

Browse files
committed
fix: unit test pipeline
1 parent c24ac0a commit 5f5e008

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

dao-factory/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
<groupId>ch.qos.logback</groupId>
3232
<artifactId>logback-classic</artifactId>
3333
</dependency>
34-
<!-- <dependency>-->
35-
<!-- <groupId>org.mongodb</groupId>-->
36-
<!-- <artifactId>bson</artifactId>-->
37-
<!-- </dependency>-->
3834
<dependency>
3935
<groupId>org.mongodb</groupId>
4036
<artifactId>mongodb-driver-legacy</artifactId>
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,69 @@
11
package com.iluwatar.daofactory;
22

3-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3+
import static org.mockito.Mockito.mock;
4+
import static org.mockito.Mockito.verify;
5+
import static org.mockito.Mockito.when;
46

7+
import java.util.List;
8+
import org.bson.types.ObjectId;
9+
import org.junit.jupiter.api.BeforeEach;
510
import org.junit.jupiter.api.Test;
611

712
/** {@link App} */
813
class AppTest {
9-
/** Test ensure that no exception when execute main function */
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+
1064
@Test
11-
void shouldExecuteDaoWithoutException() {
12-
assertDoesNotThrow(() -> App.main(new String[] {}));
65+
void testDeleteSchema() {
66+
App.deleteSchema(mockLongCustomerDAO);
67+
verify(mockLongCustomerDAO).deleteSchema();
1368
}
1469
}

money/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<configuration>
5656
<archive>
5757
<manifest>
58-
<mainClass>com.iluwatar.daofactory.App</mainClass>
58+
<mainClass>com.iluwatar.App</mainClass>
5959
</manifest>
6060
</archive>
6161
</configuration>

0 commit comments

Comments
 (0)