-
Notifications
You must be signed in to change notification settings - Fork 0
/
AtendimentoServiceTest.java
112 lines (96 loc) · 3.55 KB
/
AtendimentoServiceTest.java
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package br.ufac.sgcmapi.service;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import br.ufac.sgcmapi.model.Atendimento;
import br.ufac.sgcmapi.model.EStatus;
import br.ufac.sgcmapi.model.Profissional;
import br.ufac.sgcmapi.repository.AtendimentoRepository;
@ExtendWith(MockitoExtension.class)
public class AtendimentoServiceTest {
@Mock
private AtendimentoRepository repo;
@InjectMocks
private AtendimentoService servico;
Atendimento a1;
Atendimento a2;
List<Atendimento> atendimentos;
@BeforeEach
public void setUp() {
a1 = new Atendimento();
a2 = new Atendimento();
a1.setId(1L);
a2.setId(2L);
a1.setHora(LocalTime.of(14, 00));
a2.setHora(LocalTime.of(15, 00));
atendimentos = new ArrayList<>();
atendimentos.add(a1);
atendimentos.add(a2);
}
@Test
public void testAtendimentoDelete() {
// Mockito.doNothing().when(repo).deleteById(1L);
// repo.deleteById(1L);
// Mockito.verify(repo, Mockito.times(1)).deleteById(1L);
Mockito.when(repo.findById(1L)).thenReturn(Optional.of(a1));
assertEquals(EStatus.AGENDADO, a1.getStatus());
servico.delete(1L);
assertEquals(EStatus.CANCELADO, a1.getStatus());
}
@Test
public void testAtendimentoGetAll() {
Mockito.when(repo.findAll()).thenReturn(atendimentos);
List<Atendimento> result = servico.get();
assertEquals(2, result.size());
assertEquals(2L, result.get(1).getId());
}
@Test
void testAtendimentoGetById() {
Mockito.when(repo.findById(1L)).thenReturn(Optional.of(a1));
Atendimento result = servico.get(1L);
assertEquals(1L, result.getId());
}
@Test
void testAtendimentoGetTermoBusca() {
Mockito.when(repo.busca("termo")).thenReturn(atendimentos);
List<Atendimento> result = servico.get("termo");
assertEquals(2, result.size());
assertEquals(1, result.get(0).getId());
assertEquals(2, result.get(1).getId());
}
@Test
void testGetHorarios() {
Mockito.when(repo.findByProfissionalAndDataAndStatusNot(
Mockito.any(Profissional.class),
Mockito.eq(LocalDate.now()),
Mockito.eq(EStatus.CANCELADO))).thenReturn(atendimentos);
List<String> result = servico.getHorarios(1L, LocalDate.now());
assertEquals(2, result.size());
assertTrue(result.contains("15:00:00"));
}
@Test
void testAtendimentoSave() {
Mockito.when(repo.save(a1)).thenReturn(a1);
Atendimento result = servico.save(a1);
assertEquals(1L, result.getId());
}
@Test
public void testUpdateStatus() {
Mockito.when(repo.findById(1L)).thenReturn(Optional.of(a1));
Atendimento result = servico.updateStatus(1L);
assertNotNull(result);
assertEquals(EStatus.CONFIRMADO, result.getStatus());
}
}