Pruebas Unitarias
Ejemplo de prueba:
@Test
void testGetAllCupones() {
when(cuponRepository.findAll()).thenReturn(Arrays.asList(cupon));
assertEquals(1, cuponService.getAllCupones().size());
}
@Test
void testGetCuponById_found() {
when(cuponRepository.findById(1L)).thenReturn(Optional.of(cupon));
Optional<Cupon> resultado = cuponService.getCuponById(1L);
assertTrue(resultado.isPresent());
assertEquals("DESC10", resultado.get().getCodigo());
}
@Test
void testGetCuponById_notFound() {
when(cuponRepository.findById(99L)).thenReturn(Optional.empty());
assertTrue(cuponService.getCuponById(99L).isEmpty());
}

Last updated