Skip to content

Commit 89c65b8

Browse files
committed
fix: unit test pipeline
1 parent c24ac0a commit 89c65b8

File tree

1 file changed

+59
-3
lines changed
  • dao-factory/src/test/java/com/iluwatar/daofactory

1 file changed

+59
-3
lines changed
Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,70 @@
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 {
914
/** Test ensure that no exception when execute main function */
15+
16+
private CustomerDAO<Long> mockLongCustomerDAO;
17+
private CustomerDAO<ObjectId> mockObjectIdCustomerDAO;
18+
19+
@BeforeEach
20+
void setUp() {
21+
mockLongCustomerDAO = mock(CustomerDAO.class);
22+
mockObjectIdCustomerDAO = mock(CustomerDAO.class);
23+
}
24+
25+
@Test
26+
void testPerformCreateCustomerWithLongId() {
27+
Customer<Long> c1 = new Customer<>(1L, "Test1");
28+
Customer<Long> c2 = new Customer<>(2L, "Test2");
29+
30+
when(mockLongCustomerDAO.findAll()).thenReturn(List.of(c1, c2));
31+
32+
App.performCreateCustomer(mockLongCustomerDAO, List.of(c1, c2));
33+
34+
verify(mockLongCustomerDAO).save(c1);
35+
verify(mockLongCustomerDAO).save(c2);
36+
verify(mockLongCustomerDAO).findAll();
37+
}
38+
39+
@Test
40+
void testPerformUpdateCustomerWithObjectId() {
41+
ObjectId id = new ObjectId();
42+
Customer<ObjectId> updatedCustomer = new Customer<>(id, "Updated");
43+
44+
when(mockObjectIdCustomerDAO.findAll()).thenReturn(List.of(updatedCustomer));
45+
46+
App.performUpdateCustomer(mockObjectIdCustomerDAO, updatedCustomer);
47+
48+
verify(mockObjectIdCustomerDAO).update(updatedCustomer);
49+
verify(mockObjectIdCustomerDAO).findAll();
50+
}
51+
52+
@Test
53+
void testPerformDeleteCustomerWithLongId() {
54+
Long id = 100L;
55+
Customer<Long> remainingCustomer = new Customer<>(1L, "Remaining");
56+
57+
when(mockLongCustomerDAO.findAll()).thenReturn(List.of(remainingCustomer));
58+
59+
App.performDeleteCustomer(mockLongCustomerDAO, id);
60+
61+
verify(mockLongCustomerDAO).delete(id);
62+
verify(mockLongCustomerDAO).findAll();
63+
}
64+
1065
@Test
11-
void shouldExecuteDaoWithoutException() {
12-
assertDoesNotThrow(() -> App.main(new String[] {}));
66+
void testDeleteSchema() {
67+
App.deleteSchema(mockLongCustomerDAO);
68+
verify(mockLongCustomerDAO).deleteSchema();
1369
}
1470
}

0 commit comments

Comments
 (0)