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 3, 2024
1 parent a4955a1 commit dc38f2d
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 @@ -17,4 +17,8 @@ public RestaurantService(RestaurantRepository restaurantRepository) {
public List<Restaurant> getRestaurants() {
return restaurantRepository.findAll();
}

public void deleteRestaurant(String id) {
restaurantRepository.deleteById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ void getRestaurants_whenOneRestaurantsInDB_thenReturnListOfOne() {
List<Restaurant> 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);
}
}

0 comments on commit dc38f2d

Please sign in to comment.