Created
September 2, 2025 14:14
-
-
Save guiathayde/75fdaf6015716b8c190f8a74dc491d49 to your computer and use it in GitHub Desktop.
ClassificadorTest.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.s01.ex4; | |
| import org.junit.jupiter.api.Test; | |
| import static org.junit.jupiter.api.Assertions.*; | |
| public class ClassificadorTest { | |
| @Test | |
| public void testDefinirFaixaEtariaComIdadeInvalida() { | |
| Classificador classificador = new Classificador(); | |
| // Testa idade negativa | |
| Pessoa pessoaIdadeNegativa = new Pessoa("João", -5); | |
| Exception exceptionIdadeNegativa = assertThrows(IllegalArgumentException.class, () -> { | |
| classificador.definirFaixaEtaria(pessoaIdadeNegativa); | |
| }); | |
| assertEquals("idade inválida", exceptionIdadeNegativa.getMessage()); | |
| // Testa idade muito alta (≥ 110) | |
| Pessoa pessoaIdadeAlta = new Pessoa("Maria", 110); | |
| Exception exceptionIdadeAlta = assertThrows(IllegalArgumentException.class, () -> { | |
| classificador.definirFaixaEtaria(pessoaIdadeAlta); | |
| }); | |
| assertEquals("idade inválida", exceptionIdadeAlta.getMessage()); | |
| } | |
| @Test | |
| public void testDefinirFaixaEtariaCrianca() { | |
| Classificador classificador = new Classificador(); | |
| // Teste limite inferior (0 anos) | |
| Pessoa bebê = new Pessoa("Pedro", 0); | |
| assertEquals("Pedro é criança", classificador.definirFaixaEtaria(bebê)); | |
| // Teste valor intermediário | |
| Pessoa criança = new Pessoa("Ana", 8); | |
| assertEquals("Ana é criança", classificador.definirFaixaEtaria(criança)); | |
| // Teste limite superior (11 anos) | |
| Pessoa criançaLimiteSuperior = new Pessoa("Lucas", 11); | |
| assertEquals("Lucas é criança", classificador.definirFaixaEtaria(criançaLimiteSuperior)); | |
| } | |
| @Test | |
| public void testDefinirFaixaEtariaAdolescente() { | |
| Classificador classificador = new Classificador(); | |
| // Teste limite inferior (12 anos) | |
| Pessoa adolescenteLimiteInferior = new Pessoa("Julia", 12); | |
| assertEquals("Julia é adolescente", classificador.definirFaixaEtaria(adolescenteLimiteInferior)); | |
| // Teste valor intermediário | |
| Pessoa adolescente = new Pessoa("Gabriel", 15); | |
| assertEquals("Gabriel é adolescente", classificador.definirFaixaEtaria(adolescente)); | |
| // Teste limite superior (18 anos) | |
| Pessoa adolescenteLimiteSuperior = new Pessoa("Carla", 18); | |
| assertEquals("Carla é adolescente", classificador.definirFaixaEtaria(adolescenteLimiteSuperior)); | |
| } | |
| @Test | |
| public void testDefinirFaixaEtariaAdulto() { | |
| Classificador classificador = new Classificador(); | |
| // Teste limite inferior (19 anos) | |
| Pessoa adultoLimiteInferior = new Pessoa("Rafael", 19); | |
| assertEquals("Rafael é adulto", classificador.definirFaixaEtaria(adultoLimiteInferior)); | |
| // Teste valor intermediário | |
| Pessoa adulto = new Pessoa("Fernanda", 35); | |
| assertEquals("Fernanda é adulto", classificador.definirFaixaEtaria(adulto)); | |
| // Teste limite superior (59 anos) | |
| Pessoa adultoLimiteSuperior = new Pessoa("Carlos", 59); | |
| assertEquals("Carlos é adulto", classificador.definirFaixaEtaria(adultoLimiteSuperior)); | |
| } | |
| @Test | |
| public void testDefinirFaixaEtariaIdoso() { | |
| Classificador classificador = new Classificador(); | |
| // Teste limite inferior (60 anos) | |
| Pessoa idosoLimiteInferior = new Pessoa("Teresa", 60); | |
| assertEquals("Teresa é idoso", classificador.definirFaixaEtaria(idosoLimiteInferior)); | |
| // Teste valor intermediário | |
| Pessoa idoso = new Pessoa("Antônio", 75); | |
| assertEquals("Antônio é idoso", classificador.definirFaixaEtaria(idoso)); | |
| // Teste próximo ao limite superior (109 anos) | |
| Pessoa idosoLimiteSuperior = new Pessoa("Joana", 109); | |
| assertEquals("Joana é idoso", classificador.definirFaixaEtaria(idosoLimiteSuperior)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment