### Question:
FavoriteService { public void deleteFavorite(long favoriteId) { Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null); checkUserOperatePermission(favorite); favoriteRepository.delete(favorite); }  Favorite addFavorite(Favorite favorite); List<Favorite> search(String userId, String appId, Pageable page); void deleteFavorite(long favoriteId); void adjustFavoriteToFirst(long favoriteId); void batchDeleteByAppId(String appId, String operator); static final long POSITION_DEFAULT; }### Answer:
@Test @Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testDeleteFavorite() { long legalFavoriteId = 21L; favoriteService.deleteFavorite(legalFavoriteId); Assert.assertNull(favoriteRepository.findById(legalFavoriteId).orElse(null)); }
@Test(expected = BadRequestException.class) @Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testDeleteFavoriteFail() { long anotherPersonFavoriteId = 23L; favoriteService.deleteFavorite(anotherPersonFavoriteId); Assert.assertNull(favoriteRepository.findById(anotherPersonFavoriteId).orElse(null)); }