Created
September 7, 2025 20:24
-
-
Save guiathayde/e3b990ebedffb16f0919fb402f164b40 to your computer and use it in GitHub Desktop.
RelatorioDeFuncionariosTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.example.s03.ex4; | |
| import org.junit.jupiter.api.BeforeEach; | |
| import org.junit.jupiter.api.Test; | |
| import org.mockito.Mock; | |
| import org.mockito.MockitoAnnotations; | |
| import java.util.ArrayList; | |
| import static org.junit.jupiter.api.Assertions.assertEquals; | |
| import static org.mockito.Mockito.*; | |
| public class RelatorioDeFuncionariosTest { | |
| @Mock | |
| private FuncionarioDAO funcionarioDAO; | |
| @Mock | |
| private ReceitaFederal receitaFederal; | |
| private RelatorioDeFuncionarios relatorio; | |
| private AutoCloseable closeable; | |
| @BeforeEach | |
| public void setUp() { | |
| closeable = MockitoAnnotations.openMocks(this); | |
| relatorio = new RelatorioDeFuncionarios(funcionarioDAO); | |
| relatorio.setRf(receitaFederal); | |
| } | |
| @org.junit.jupiter.api.AfterEach | |
| void tearDown() throws Exception { | |
| closeable.close(); | |
| } | |
| @Test | |
| public void testFuncionariosTecnicosSemCPFBloqueado() { | |
| // Arrange | |
| ArrayList<Funcionario> funcionarios = new ArrayList<>(); | |
| Funcionario func1 = new Funcionario(); | |
| func1.setId(1); | |
| func1.setNome("Técnico 1"); | |
| func1.setCpf("123456789-00"); | |
| Funcionario func2 = new Funcionario(); | |
| func2.setId(2); | |
| func2.setNome("Técnico 2"); | |
| func2.setCpf("987654321-00"); | |
| funcionarios.add(func1); | |
| funcionarios.add(func2); | |
| when(funcionarioDAO.getFuncionariosBy("tecnico")).thenReturn(funcionarios); | |
| when(receitaFederal.isCPFBloqueado("123456789-00")).thenReturn(false); | |
| when(receitaFederal.isCPFBloqueado("987654321-00")).thenReturn(false); | |
| // Act | |
| int resultado = relatorio.getFuncComCPFBloqueado("tecnico"); | |
| // Assert | |
| assertEquals(0, resultado); | |
| verify(funcionarioDAO, times(1)).getFuncionariosBy("tecnico"); | |
| verify(receitaFederal, times(1)).isCPFBloqueado("123456789-00"); | |
| verify(receitaFederal, times(1)).isCPFBloqueado("987654321-00"); | |
| } | |
| @Test | |
| public void testFuncionarioAnalistaComCPFBloqueado() { | |
| // Arrange | |
| ArrayList<Funcionario> funcionarios = new ArrayList<>(); | |
| Funcionario func = new Funcionario(); | |
| func.setId(3); | |
| func.setNome("Analista 1"); | |
| func.setCpf("555666777-88"); | |
| funcionarios.add(func); | |
| when(funcionarioDAO.getFuncionariosBy("analista")).thenReturn(funcionarios); | |
| when(receitaFederal.isCPFBloqueado("555666777-88")).thenReturn(true); | |
| // Act | |
| int resultado = relatorio.getFuncComCPFBloqueado("analista"); | |
| // Assert | |
| assertEquals(1, resultado); | |
| verify(funcionarioDAO, times(1)).getFuncionariosBy("analista"); | |
| verify(receitaFederal, times(1)).isCPFBloqueado("555666777-88"); | |
| } | |
| @Test | |
| public void testFuncionariosGerenteComDoisCPFsBloqueados() { | |
| // Arrange | |
| ArrayList<Funcionario> funcionarios = new ArrayList<>(); | |
| Funcionario func1 = new Funcionario(); | |
| func1.setId(4); | |
| func1.setNome("Gerente 1"); | |
| func1.setCpf("123456789-00"); | |
| Funcionario func2 = new Funcionario(); | |
| func2.setId(5); | |
| func2.setNome("Gerente 2"); | |
| func2.setCpf("111222333-44"); | |
| Funcionario func3 = new Funcionario(); | |
| func3.setId(6); | |
| func3.setNome("Gerente 3"); | |
| func3.setCpf("654321987-23"); | |
| Funcionario func4 = new Funcionario(); | |
| func4.setId(7); | |
| func4.setNome("Gerente 4"); | |
| func4.setCpf("098876654-99"); | |
| funcionarios.add(func1); | |
| funcionarios.add(func2); | |
| funcionarios.add(func3); | |
| funcionarios.add(func4); | |
| when(funcionarioDAO.getFuncionariosBy("gerente")).thenReturn(funcionarios); | |
| when(receitaFederal.isCPFBloqueado("123456789-00")).thenReturn(false); | |
| when(receitaFederal.isCPFBloqueado("111222333-44")).thenReturn(true); | |
| when(receitaFederal.isCPFBloqueado("654321987-23")).thenReturn(false); | |
| when(receitaFederal.isCPFBloqueado("098876654-99")).thenReturn(true); | |
| // Act | |
| int resultado = relatorio.getFuncComCPFBloqueado("gerente"); | |
| // Assert | |
| assertEquals(2, resultado); | |
| verify(funcionarioDAO, times(1)).getFuncionariosBy("gerente"); | |
| verify(receitaFederal, times(1)).isCPFBloqueado("123456789-00"); | |
| verify(receitaFederal, times(1)).isCPFBloqueado("111222333-44"); | |
| verify(receitaFederal, times(1)).isCPFBloqueado("654321987-23"); | |
| verify(receitaFederal, times(1)).isCPFBloqueado("098876654-99"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment