-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitializerTest.java
More file actions
62 lines (47 loc) · 1.55 KB
/
InitializerTest.java
File metadata and controls
62 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package de.eemkeen.model;
import one.microstream.persistence.types.Storer;
import one.microstream.storage.types.StorageManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.ArrayList;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class InitializerTest {
@Mock
private StorageManager storageManager;
@Mock
private Root root;
@Mock
private Storer storer;
private Initializer initializer;
@BeforeEach
void setUp() {
initializer = new Initializer();
when(storageManager.root()).thenReturn(root);
}
@Test
void initialize_shouldStoreRootWhenUsersEmpty() {
// Arrange
when(root.getUsers()).thenReturn(new ArrayList<>());
when(storageManager.createEagerStorer()).thenReturn(storer);
// Act
initializer.initialize(storageManager);
// Assert
verify(storageManager).createEagerStorer();
verify(storer).store(root);
}
@Test
void initialize_shouldNotStoreRootWhenUsersNotEmpty() {
// Arrange
ArrayList<User> users = new ArrayList<>();
users.add(User.builder().name("Existing User").build());
when(root.getUsers()).thenReturn(users);
// Act
initializer.initialize(storageManager);
// Assert
verify(storageManager, never()).createEagerStorer();
}
}