From dc38f2d26fb912a5cb1e6ee92610c8598484affc Mon Sep 17 00:00:00 2001 From: Jonas Honecker Date: Mon, 3 Jun 2024 12:33:38 +0200 Subject: [PATCH] Add delete method and unit test --- .../team2/backend/restaurant/RestaurantService.java | 4 ++++ .../backend/restaurant/RestaurantServiceTest.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantService.java b/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantService.java index e82836d..3a29523 100644 --- a/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantService.java +++ b/backend/src/main/java/com/neuefische/team2/backend/restaurant/RestaurantService.java @@ -17,4 +17,8 @@ public RestaurantService(RestaurantRepository restaurantRepository) { public List getRestaurants() { return restaurantRepository.findAll(); } + + public void deleteRestaurant(String id) { + restaurantRepository.deleteById(id); + } } diff --git a/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantServiceTest.java b/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantServiceTest.java index dac1803..f8bb284 100644 --- a/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantServiceTest.java +++ b/backend/src/test/java/com/neuefische/team2/backend/restaurant/RestaurantServiceTest.java @@ -42,4 +42,16 @@ void getRestaurants_whenOneRestaurantsInDB_thenReturnListOfOne() { List expected = List.of(restaurant); assertEquals(expected, actual); } + + @Test + void deleteRestaurant_whenMethodCalled_thenDeleteMethodOnRepositoryWasCalledOnlyOnce() { + //GIVEN + String id = "123"; + + //WHEN + restaurantService.deleteRestaurant(id); + + //THEN + verify(mockRestaurantRepository, times(1)).deleteById(id); + } }