From b289dd6463092befcf4ba31ad58661bca7941be5 Mon Sep 17 00:00:00 2001 From: Arnaud Mengus Date: Thu, 30 May 2024 08:17:48 +0000 Subject: [PATCH] refactor: Use Optional in repository tests Refactor the repository tests to use `Optional` when retrieving entities by UUID. This change improves code readability and ensures safer handling of null values. --- .../src/test/java/ai/dragon/repository/FarmRepositoryTest.java | 2 +- .../test/java/ai/dragon/repository/ProviderRepositoryTest.java | 2 +- .../src/test/java/ai/dragon/repository/SiloRepositoryTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/test/java/ai/dragon/repository/FarmRepositoryTest.java b/backend/src/test/java/ai/dragon/repository/FarmRepositoryTest.java index 0a018cae..b7581785 100644 --- a/backend/src/test/java/ai/dragon/repository/FarmRepositoryTest.java +++ b/backend/src/test/java/ai/dragon/repository/FarmRepositoryTest.java @@ -29,7 +29,7 @@ void insertFarms() { farm.setName(farmName); farmRepository.save(farm); - FarmEntity retrievedFarm = farmRepository.getByUuid(farm.getUuid()); + FarmEntity retrievedFarm = farmRepository.getByUuid(farm.getUuid()).orElseThrow(); assertNotNull(farmRepository.getByUuid(retrievedFarm.getUuid())); assertEquals(farmName, retrievedFarm.getName()); } diff --git a/backend/src/test/java/ai/dragon/repository/ProviderRepositoryTest.java b/backend/src/test/java/ai/dragon/repository/ProviderRepositoryTest.java index 30602c4f..e6d9c8e5 100644 --- a/backend/src/test/java/ai/dragon/repository/ProviderRepositoryTest.java +++ b/backend/src/test/java/ai/dragon/repository/ProviderRepositoryTest.java @@ -31,7 +31,7 @@ void insertProviders() { provider.setType(ProviderType.ONNX); providerRepository.save(provider); - ProviderEntity retrievedProvider = providerRepository.getByUuid(provider.getUuid()); + ProviderEntity retrievedProvider = providerRepository.getByUuid(provider.getUuid()).orElseThrow(); assertNotNull(providerRepository.getByUuid(retrievedProvider.getUuid())); assertEquals(providerName, retrievedProvider.getName()); } diff --git a/backend/src/test/java/ai/dragon/repository/SiloRepositoryTest.java b/backend/src/test/java/ai/dragon/repository/SiloRepositoryTest.java index 84b296f7..0e48b2e9 100644 --- a/backend/src/test/java/ai/dragon/repository/SiloRepositoryTest.java +++ b/backend/src/test/java/ai/dragon/repository/SiloRepositoryTest.java @@ -29,7 +29,7 @@ void insertSilos() { silo.setName(siloName); siloRepository.save(silo); - SiloEntity retrievedSilo = siloRepository.getByUuid(silo.getUuid()); + SiloEntity retrievedSilo = siloRepository.getByUuid(silo.getUuid()).orElseThrow(); assertNotNull(siloRepository.getByUuid(retrievedSilo.getUuid())); assertEquals(siloName, retrievedSilo.getName()); }