Escolar Documentos
Profissional Documentos
Cultura Documentos
Guia Atualização Nos Testes Automatizados
Guia Atualização Nos Testes Automatizados
/repositories/ProductRepositoryTests.java
1. Remover teste para id inexistente:
@Test
public void deleteShouldThrowEmptyResultDataAccessExceptionWhenIdDoesNotExist() {
Assertions.assertThrows(EmptyResultDataAccessException.class, () -> {
repository.deleteById(nonExistingId);
});
}
/services/ProductServiceTests.java
1. Incluir mocks para existsById:
Mockito.when(repository.existsById(existingId)).thenReturn(true);
Mockito.when(repository.existsById(nonExistingId)).thenReturn(false);
Mockito.when(repository.existsById(dependentId)).thenReturn(true);
Assertions.assertThrows(ResourceNotFoundException.class, () -> {
service.delete(nonExistingId);
});
Mockito.verify(repository, times(1)).deleteById(nonExistingId);
}