Skip to content

Instantly share code, notes, and snippets.

@luissimas
Created October 27, 2023 20:15
Show Gist options
  • Save luissimas/53b9dc05876334f69472830b6917b493 to your computer and use it in GitHub Desktop.
Save luissimas/53b9dc05876334f69472830b6917b493 to your computer and use it in GitHub Desktop.
Casos de teste para os exercícios propostos em sala de aula utilizando o framework JUnit 5.
/**
* Nome: Luís Augusto Simas do Nascimento
* RA: 790828
*/
package ex04;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.lang.reflect.Array;
import java.util.ArrayList;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.*;
class RelatorioDeFuncionariosTest {
FuncionarioDAO funcDaoMock;
ReceitaFederal rfMock;
@BeforeEach
void setUp() {
this.funcDaoMock = mock(FuncionarioDAO.class);
this.rfMock = mock(ReceitaFederal.class);
}
@Test
void testSemFuncionariosNoBanco() {
RelatorioDeFuncionarios rel = new RelatorioDeFuncionarios(this.funcDaoMock);
rel.setRf(this.rfMock);
ArrayList<Funcionario> funcionarios = new ArrayList<Funcionario>();
when(this.funcDaoMock.getFuncionariosBy("Dev")).thenReturn(funcionarios);
int resposta = rel.getFuncComCPFBloqueado("Dev");
assertEquals(resposta, 0);
}
@Test
void testDoisFuncionariosTecnicoSemCPFBloqueado() {
RelatorioDeFuncionarios rel = new RelatorioDeFuncionarios(this.funcDaoMock);
rel.setRf(this.rfMock);
ArrayList<Funcionario> funcionarios = new ArrayList<Funcionario>();
funcionarios.add(new Funcionario(0, "first-func", "first-cpf"));
funcionarios.add(new Funcionario(1, "second-func", "second-cpf"));
when(this.funcDaoMock.getFuncionariosBy("Tecnico")).thenReturn(funcionarios);
when(this.rfMock.isCPFBloqueado("first-cpf")).thenReturn(false);
when(this.rfMock.isCPFBloqueado("second-cpf")).thenReturn(false);
int resposta = rel.getFuncComCPFBloqueado("Tecnico");
assertEquals(resposta, 0);
}
@Test
void testUmFuncionarioAnalistaComCPFBloqueado() {
RelatorioDeFuncionarios rel = new RelatorioDeFuncionarios(this.funcDaoMock);
rel.setRf(this.rfMock);
ArrayList<Funcionario> funcionarios = new ArrayList<Funcionario>();
funcionarios.add(new Funcionario(0, "first-func", "first-cpf"));
when(this.funcDaoMock.getFuncionariosBy("Analista")).thenReturn(funcionarios);
when(this.rfMock.isCPFBloqueado("first-cpf")).thenReturn(true);
int resposta = rel.getFuncComCPFBloqueado("Analista");
assertEquals(resposta, 1);
}
@Test
void testQuatroFuncionariosGerenteComCPFBloqueado() {
RelatorioDeFuncionarios rel = new RelatorioDeFuncionarios(this.funcDaoMock);
rel.setRf(this.rfMock);
ArrayList<Funcionario> funcionarios = new ArrayList<Funcionario>();
funcionarios.add(new Funcionario(0, "first-func", "123456789-00"));
funcionarios.add(new Funcionario(1, "second-func", "111222333-44"));
funcionarios.add(new Funcionario(2, "third-func", "654321987-23"));
funcionarios.add(new Funcionario(3, "forth-func", "098876654-99"));
when(this.funcDaoMock.getFuncionariosBy("Gerente")).thenReturn(funcionarios);
when(this.rfMock.isCPFBloqueado("111222333-44")).thenReturn(true);
when(this.rfMock.isCPFBloqueado("098876654-99")).thenReturn(true);
int resposta = rel.getFuncComCPFBloqueado("Gerente");
assertEquals(resposta, 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment