Skip to content

Commit

Permalink
Add delete method and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashonecker committed Jun 5, 2024
1 parent 2942910 commit a8645f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a8645f3

Please sign in to comment.