From a8645f3d09dacf9ea98b06a605bfa0b1a85b6775 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 0339112..791200e 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 @@ -25,4 +25,8 @@ public Restaurant findRestaurantById(String id) { public Restaurant addRestaurant(Restaurant restaurant) { return restaurantRepository.save(restaurant); } + + 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 78b5543..a55470e 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 @@ -84,4 +84,16 @@ void addRestaurant_whenRestaurantToSave_thenReturnSavedRestaurantWithId() { verify(mockRestaurantRepository).save(restaurantToSave); assertEquals(savedRestaurant, actual); } + + @Test + void deleteRestaurant_whenMethodCalled_thenDeleteMethodOnRepositoryWasCalledOnlyOnce() { + //GIVEN + String id = "123"; + + //WHEN + restaurantService.deleteRestaurant(id); + + //THEN + verify(mockRestaurantRepository, times(1)).deleteById(id); + } }