diff --git a/src/main/java/com/diareat/diareat/user/controller/UserController.java b/src/main/java/com/diareat/diareat/user/controller/UserController.java index ce6c3f5..5024b92 100644 --- a/src/main/java/com/diareat/diareat/user/controller/UserController.java +++ b/src/main/java/com/diareat/diareat/user/controller/UserController.java @@ -7,7 +7,6 @@ import io.swagger.annotations.Api; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; -import net.bytebuddy.implementation.bind.annotation.Empty; import org.springframework.web.bind.annotation.*; import java.util.List; diff --git a/src/main/java/com/diareat/diareat/user/domain/User.java b/src/main/java/com/diareat/diareat/user/domain/User.java index 2f0d619..6852f48 100644 --- a/src/main/java/com/diareat/diareat/user/domain/User.java +++ b/src/main/java/com/diareat/diareat/user/domain/User.java @@ -44,9 +44,10 @@ public class User { private List favoriteFoods = new ArrayList<>(); // 생성 메서드 - public static User createUser(String name, String keyCode, int height, int weight, int gender, int age, BaseNutrition baseNutrition) { + public static User createUser(String name, String image, String keyCode, int height, int weight, int gender, int age, BaseNutrition baseNutrition) { User user = new User(); user.name = name; + user.image = image; user.keyCode = keyCode; user.height = height; user.weight = weight; @@ -68,4 +69,8 @@ public void updateUser(String name, int height, int weight, int age) { public void updateBaseNutrition(BaseNutrition baseNutrition) { this.baseNutrition = baseNutrition; } + + public void setId(Long id) { // 테스트코드용 메서드 + this.id = id; + } } diff --git a/src/main/java/com/diareat/diareat/user/dto/CreateUserDto.java b/src/main/java/com/diareat/diareat/user/dto/CreateUserDto.java index 481bef4..5c463ef 100644 --- a/src/main/java/com/diareat/diareat/user/dto/CreateUserDto.java +++ b/src/main/java/com/diareat/diareat/user/dto/CreateUserDto.java @@ -10,13 +10,14 @@ public class CreateUserDto { private String name; + private String image; private String keyCode; private int gender; private int height; private int weight; private int age; - public static CreateUserDto of(String name, String keyCode, int gender, int height, int weight, int age){ - return new CreateUserDto(name, keyCode, gender, height, weight, age); + public static CreateUserDto of(String name, String image, String keyCode, int gender, int height, int weight, int age){ + return new CreateUserDto(name, image, keyCode, gender, height, weight, age); } } diff --git a/src/main/java/com/diareat/diareat/user/service/UserService.java b/src/main/java/com/diareat/diareat/user/service/UserService.java index fe49358..80db78a 100644 --- a/src/main/java/com/diareat/diareat/user/service/UserService.java +++ b/src/main/java/com/diareat/diareat/user/service/UserService.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -29,7 +30,7 @@ public Long saveUser(CreateUserDto createUserDto) { // BaseNutrition baseNutrition = BaseNutrition.createNutrition(createUserDto.getGender(), createUserDto.getAge(), createUserDto.getHeight(), createUserDto.getWeight()); if (userRepository.existsByName(createUserDto.getName())) throw new UserException(ResponseCode.USER_ALREADY_EXIST); - User user = User.createUser(createUserDto.getName(), createUserDto.getKeyCode(), createUserDto.getHeight(), createUserDto.getWeight(), createUserDto.getGender(), createUserDto.getAge(), baseNutrition); + User user = User.createUser(createUserDto.getName(), createUserDto.getImage(), createUserDto.getKeyCode(), createUserDto.getHeight(), createUserDto.getWeight(), createUserDto.getGender(), createUserDto.getAge(), baseNutrition); return userRepository.save(user).getId(); } @@ -68,6 +69,7 @@ public void updateBaseNutrition(UpdateUserNutritionDto updateUserNutritionDto) { User user = getUserById(updateUserNutritionDto.getUserId()); BaseNutrition baseNutrition = BaseNutrition.createNutrition(updateUserNutritionDto.getCalorie(), updateUserNutritionDto.getCarbohydrate(), updateUserNutritionDto.getProtein(), updateUserNutritionDto.getFat()); user.updateBaseNutrition(baseNutrition); + userRepository.save(user); } // 회원 탈퇴 @@ -81,7 +83,8 @@ public void deleteUser(Long userId) { @Transactional(readOnly = true) public List searchUser(Long hostId, String name) { validateUser(hostId); - List users = userRepository.findAllByNameContaining(name); + List users = new ArrayList<>(userRepository.findAllByNameContaining(name)); + users.removeIf(user -> user.getId().equals(hostId)); // 검색 결과에서 자기 자신은 제외 (removeIf 메서드는 ArrayList에만 존재) return users.stream() .map(user -> ResponseSearchUserDto.of(user.getId(), user.getName(), user.getImage(), followRepository.existsByFromUserAndToUser(hostId, user.getId()))).collect(Collectors.toList()); } @@ -103,7 +106,7 @@ public void unfollowUser(Long userId, Long unfollowId) { validateUser(userId); validateUser(unfollowId); // 이미 팔로우 취소한 경우 - if (followRepository.existsByFromUserAndToUser(userId, unfollowId)) + if (!followRepository.existsByFromUserAndToUser(userId, unfollowId)) throw new UserException(ResponseCode.UNFOLLOWED_ALREADY); followRepository.delete(Follow.makeFollow(userId, unfollowId)); } diff --git a/src/test/java/com/diareat/diareat/service/FoodServiceTest.java b/src/test/java/com/diareat/diareat/service/FoodServiceTest.java index c598aab..651f7b3 100644 --- a/src/test/java/com/diareat/diareat/service/FoodServiceTest.java +++ b/src/test/java/com/diareat/diareat/service/FoodServiceTest.java @@ -53,7 +53,7 @@ public void setUp() { void testSaveAndGetFood() { // 음식 정보 저장 및 해당 날짜 음식 리스트 불러오기 // given BaseNutrition testBaseNutrition = BaseNutrition.createNutrition(1,1,1,1); - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 1,180, 80,18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","testPassword", 1,180, 80,18)); //when Long foodId = foodService.saveFood(CreateFoodDto.of(userId,"testFood",testBaseNutrition)); @@ -69,7 +69,7 @@ void testSaveAndGetFood() { // 음식 정보 저장 및 해당 날짜 음식 리 void testUpdateFood() { //given BaseNutrition testBaseNutrition = BaseNutrition.createNutrition(1,1,1,1); - Long userId = userService.saveUser(CreateUserDto.of("testUser", "tessPassword", 1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","tessPassword", 1, 180, 80, 18)); Long foodId = foodService.saveFood(CreateFoodDto.of(userId, "testFood", testBaseNutrition)); //when @@ -90,7 +90,7 @@ void testUpdateFood() { void testDeleteFood() { //given BaseNutrition testBaseNutrition = BaseNutrition.createNutrition(1,1,1,1); - Long userId = userService.saveUser(CreateUserDto.of("testUser", "tessPassword", 1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser","testImage", "tessPassword", 1, 180, 80, 18)); Long foodId = foodService.saveFood(CreateFoodDto.of(userId, "testFood", testBaseNutrition)); //when @@ -103,7 +103,7 @@ void testDeleteFood() { void testSaveAndGetFavoriteFood() { //given BaseNutrition testBaseNutrition = BaseNutrition.createNutrition(1,1,1,1); - Long userId = userService.saveUser(CreateUserDto.of("testUser", "tessPassword", 1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","tessPassword", 1, 180, 80, 18)); Long foodId = foodService.saveFood(CreateFoodDto.of(userId, "testFood", testBaseNutrition)); //when @@ -119,7 +119,7 @@ void testSaveAndGetFavoriteFood() { void testUpdateFavoriteFood() { //given BaseNutrition testBaseNutrition = BaseNutrition.createNutrition(1,1,1,1); - Long userId = userService.saveUser(CreateUserDto.of("testUser", "tessPassword", 1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","tessPassword", 1, 180, 80, 18)); Long foodId = foodService.saveFood(CreateFoodDto.of(userId, "testFood", testBaseNutrition)); Long favoriteFoodId = foodService.saveFavoriteFood(CreateFavoriteFoodDto.of(foodId, userId, "testFood", testBaseNutrition)); @@ -142,7 +142,7 @@ void testUpdateFavoriteFood() { void testDeleteFavoriteFood() { //given BaseNutrition testBaseNutrition = BaseNutrition.createNutrition(1,1,1,1); - Long userId = userService.saveUser(CreateUserDto.of("testUser", "tessPassword", 1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","tessPassword", 1, 180, 80, 18)); Long foodId = foodService.saveFood(CreateFoodDto.of(userId, "testFood", testBaseNutrition)); Long favoriteFoodId = foodService.saveFavoriteFood(CreateFavoriteFoodDto.of(foodId, userId, "testFood", testBaseNutrition)); @@ -156,7 +156,7 @@ void testDeleteFavoriteFood() { void testNutritionSumByDate(){ //given BaseNutrition testFoodNutrition = BaseNutrition.createNutrition(1400,150,200,250); - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword",1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","testPassword",1, 180, 80, 18)); Long foodId = foodService.saveFood(CreateFoodDto.of(userId,"testFood", testFoodNutrition)); Food food = foodRepository.getReferenceById(foodId); @@ -177,7 +177,7 @@ void testNutritionSumByDate(){ void testNutritionSumByWeekAndMonth(){ //given BaseNutrition testFoodNutrition = BaseNutrition.createNutrition(100,150,200,250); - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword",1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","testPassword",1, 180, 80, 18)); Long foodId = foodService.saveFood(CreateFoodDto.of(userId,"testFood", testFoodNutrition)); } @@ -185,7 +185,7 @@ void testNutritionSumByWeekAndMonth(){ @Test void getBest3FoodTest() { // given - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","testPassword", 1, 180, 80, 18)); foodService.saveFood(CreateFoodDto.of(userId, "Food1", BaseNutrition.createNutrition(100, 100 ,10, 1))); foodService.saveFood(CreateFoodDto.of(userId, "Food2", BaseNutrition.createNutrition(100, 100 ,8, 2))); foodService.saveFood(CreateFoodDto.of(userId, "Food3", BaseNutrition.createNutrition(100, 100 ,6, 3))); @@ -207,7 +207,7 @@ void getBest3FoodTest() { @Test void getWorst3FoodsTest() { // given - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 1, 180, 80, 18)); + Long userId = userService.saveUser(CreateUserDto.of("testUser", "testImage","testPassword", 1, 180, 80, 18)); foodService.saveFood(CreateFoodDto.of(userId, "Food1", BaseNutrition.createNutrition(100, 50 ,10, 1))); foodService.saveFood(CreateFoodDto.of(userId, "Food2", BaseNutrition.createNutrition(100, 100 ,8, 20))); foodService.saveFood(CreateFoodDto.of(userId, "Food3", BaseNutrition.createNutrition(100, 80 ,6, 7))); diff --git a/src/test/java/com/diareat/diareat/service/UserServiceTest.java b/src/test/java/com/diareat/diareat/service/UserServiceTest.java index 7d2ec45..0d062e9 100644 --- a/src/test/java/com/diareat/diareat/service/UserServiceTest.java +++ b/src/test/java/com/diareat/diareat/service/UserServiceTest.java @@ -1,167 +1,222 @@ package com.diareat.diareat.service; +import com.diareat.diareat.user.domain.BaseNutrition; +import com.diareat.diareat.user.domain.Follow; +import com.diareat.diareat.user.domain.User; import com.diareat.diareat.user.dto.*; import com.diareat.diareat.user.repository.FollowRepository; import com.diareat.diareat.user.repository.UserRepository; import com.diareat.diareat.user.service.UserService; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.List; +import java.util.Optional; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.*; -@SpringBootTest -@Transactional +@ExtendWith(MockitoExtension.class) class UserServiceTest { - @Autowired - UserService userService; - - @Autowired - UserRepository userRepository; + @InjectMocks + private UserService userService; - @Autowired - FollowRepository followRepository; - - @BeforeEach - void setUp() { - userRepository.deleteAll(); - followRepository.deleteAll(); - } + @Mock + private UserRepository userRepository; - @AfterEach - void tearDown() { - userRepository.deleteAll(); - followRepository.deleteAll(); - } + @Mock + private FollowRepository followRepository; + @DisplayName("회원정보 저장") @Test - void saveUser() { - // given - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 75, 1, 25)); - - // when - ResponseUserDto responseUserDto = userService.getUserInfo(userId); - - // then - assertNotNull(responseUserDto); - assertEquals("testUser", responseUserDto.getName()); - assertEquals(25, responseUserDto.getAge()); + void saveUser() { // setId() 메서드로 테스트 진행함 + // Given + CreateUserDto createUserDto = CreateUserDto.of("test", "profile.jpg", "testPassword", 0, 75, 1, 25); + BaseNutrition baseNutrition = BaseNutrition.createNutrition(2000, 300, 80, 80); + User user = User.createUser(createUserDto.getName(), createUserDto.getImage(), createUserDto.getKeyCode(), createUserDto.getHeight(), createUserDto.getWeight(), createUserDto.getGender(), createUserDto.getAge(), baseNutrition); + user.setId(1L); // 테스트 커밋 중 User에 setId() 메서드 임시적으로 삽입하여 테스트 진행함 + + given(userRepository.existsByName("test")).willReturn(false); + given(userRepository.save(any(User.class))).willReturn(user); + + // When + Long id = userService.saveUser(createUserDto); // id null로 반환됨 (Mock은 실제 DB에 객체를 생성하지 않기 때문) + + // Then + assertEquals(1L, id); + verify(userRepository, times(1)).save(any(User.class)); } @Test void getSimpleUserInfo() { - // given - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 75, 1, 25)); + // Given + Long userId = 1L; + User user = User.createUser("test", "profile.jpg", "keycode123", 175, 70, 0, 30, BaseNutrition.createNutrition(2000, 300, 80, 80)); + given(userRepository.findById(userId)).willReturn(Optional.of(user)); - // when - ResponseSimpleUserDto responseSimpleUserDto = userService.getSimpleUserInfo(userId); + // When + ResponseSimpleUserDto result = userService.getSimpleUserInfo(userId); - // then - assertEquals("testUser", responseSimpleUserDto.getName()); + // Then + assertEquals("test", result.getName()); + assertEquals("profile.jpg", result.getImage()); } @Test void getUserInfo() { - // given - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 75, 1, 25)); + // Given + Long userId = 1L; + User user = User.createUser("test", "profile.jpg", "keycode123", 175, 70, 0, 30, BaseNutrition.createNutrition(2000, 300, 80, 80)); + given(userRepository.findById(userId)).willReturn(Optional.of(user)); - // when - ResponseUserDto responseUserDto = userService.getUserInfo(userId); + // When + ResponseUserDto result = userService.getUserInfo(userId); - // then - assertEquals("testUser", responseUserDto.getName()); + // Then + assertEquals("test", result.getName()); + assertEquals(30, result.getAge()); } @Test void updateUserInfo() { // given - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 160, 50, 25)); - UpdateUserDto updateUserDto = UpdateUserDto.of(userId, "updateUser", 180, 75, 25, false); + UpdateUserDto updateUserDto = UpdateUserDto.of(1L, "update", 180, 75, 25, false); + User user = User.createUser("test", "profile.jpg", "keycode123", 175, 70, 0, 30, BaseNutrition.createNutrition(2000, 300, 80, 80)); + given(userRepository.findById(updateUserDto.getUserId())).willReturn(Optional.of(user)); // when userService.updateUserInfo(updateUserDto); - // then - assertEquals("updateUser", userService.getUserInfo(userId).getName()); - assertEquals(180, userService.getUserInfo(userId).getHeight()); + + // Then + assertEquals("update", user.getName()); + assertEquals(180, user.getHeight()); + assertEquals(75, user.getWeight()); + assertEquals(25, user.getAge()); } @Test void getUserNutrition() { // 임시 코드 사용, 추후 로직 개편 시 테스트코드 수정 - // given - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 160, 50, 25)); - - // when - ResponseUserNutritionDto responseUserNutritionDto = userService.getUserNutrition(userId); - - // then - assertEquals(2000, responseUserNutritionDto.getCalorie()); + // Given + Long userId = 1L; + User user = User.createUser("test", "profile.jpg", "keycode123", 175, 70, 0, 30, BaseNutrition.createNutrition(2000, 300, 80, 80)); + given(userRepository.findById(userId)).willReturn(Optional.of(user)); + + // When + ResponseUserNutritionDto result = userService.getUserNutrition(userId); + + // Then + assertEquals(2000, result.getCalorie()); + assertEquals(300, result.getCarbohydrate()); + assertEquals(80, result.getProtein()); + assertEquals(80, result.getFat()); } @Test void updateBaseNutrition() { - // given - Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 160, 50, 25)); + // Given + UpdateUserNutritionDto updateUserNutritionDto = UpdateUserNutritionDto.of(1L, 2000, 300, 80, 80); + // 필드 초기화 + User user = User.createUser("test", "profile.jpg", "keycode123", 175, 70, 0, 30, BaseNutrition.createNutrition(1000, 100, 40, 40)); + given(userRepository.findById(updateUserNutritionDto.getUserId())).willReturn(Optional.of(user)); - // when - UpdateUserNutritionDto updateUserNutritionDto = UpdateUserNutritionDto.of(userId, 2000, 300, 80, 80); + // When userService.updateBaseNutrition(updateUserNutritionDto); - // then - assertEquals(2000, userService.getUserNutrition(userId).getCalorie()); + // Then + assertEquals(2000, user.getBaseNutrition().getKcal()); + assertEquals(300, user.getBaseNutrition().getCarbohydrate()); + assertEquals(80, user.getBaseNutrition().getProtein()); + assertEquals(80, user.getBaseNutrition().getFat()); } @Test void deleteUser() { - // given - Long id = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 75, 1, 25)); + // Given + Long userId = 1L; + given(userRepository.existsById(userId)).willReturn(true); - // when - userService.deleteUser(id); + // When + userService.deleteUser(userId); - // then - assertFalse(userRepository.existsById(id)); + // Then + verify(userRepository, times(1)).deleteById(userId); } @Test - void searchUser() { - // given - userService.saveUser(CreateUserDto.of("user1", "testPassword", 0, 175, 80, 25)); - Long id = userService.saveUser(CreateUserDto.of("user2", "testPassword", 0, 175, 80, 25)); - String name = "user"; - - // then - assertEquals(2, userService.searchUser(id, name).size()); + void searchUser() { // setId() 메서드로 테스트 진행함 + // Given + Long userId1 = 1L; + Long userId2 = 2L; + Long userId3 = 3L; + String name = "John"; + + // 사용자 목록 생성 + User user1 = User.createUser("John", "profile1.jpg", "keycode123", 175, 70, 0, 30, BaseNutrition.createNutrition(2000, 300, 80, 80)); + User user2 = User.createUser("John Doe", "profile2.jpg", "keycode456", 170, 65, 1, 35, BaseNutrition.createNutrition(2000, 300, 80, 80)); + User user3 = User.createUser("John Doo", "profile3.jpg", "keycode789", 160, 55, 1, 25, BaseNutrition.createNutrition(2000, 300, 80, 80)); + user1.setId(userId1); + user2.setId(userId2); + user3.setId(userId3); + + given(userRepository.existsById(userId1)).willReturn(true); + given(userRepository.findAllByNameContaining(name)).willReturn(List.of(user1, user2, user3)); + given(followRepository.existsByFromUserAndToUser(userId1, userId2)).willReturn(true); + given(followRepository.existsByFromUserAndToUser(userId1, userId3)).willReturn(false); + + // When + List result = userService.searchUser(userId1, name); + + // Then + assertEquals(2, result.size()); + assertEquals("John Doe", result.get(0).getName()); + assertTrue(result.get(0).isFollow()); + assertEquals("John Doo", result.get(1).getName()); + assertFalse(result.get(1).isFollow()); + verify(userRepository, times(1)).findAllByNameContaining(name); } @Test void followUser() { - // given - Long id1 = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 75, 1, 25)); - Long id2 = userService.saveUser(CreateUserDto.of("followUser", "testPassword", 0, 75, 1, 25)); - - // when - userService.followUser(id2, id1); - - // then - assertEquals(1, followRepository.findAllByFromUser(id1).size()); + // Given + Long userId = 1L; // 팔로우 요청을 보낸 사용자의 ID + Long followId = 2L; // 팔로우할 사용자의 ID + + given(userRepository.existsById(userId)).willReturn(true); // userId에 해당하는 사용자가 존재함 + given(userRepository.existsById(followId)).willReturn(true); // followId에 해당하는 사용자가 존재함 + given(followRepository.existsByFromUserAndToUser(userId, followId)).willReturn(false); // 아직 팔로우 중이 아님 + + // When + userService.followUser(userId, followId); + + // Then + verify(userRepository, times(1)).existsById(userId); // 사용자 존재 여부 확인 + verify(userRepository, times(1)).existsById(followId); // 팔로우할 사용자 존재 여부 확인 + verify(followRepository, times(1)).existsByFromUserAndToUser(userId, followId); // 이미 팔로우 중인지 확인 + verify(followRepository, times(1)).save(any(Follow.class)); } @Test void unfollowUser() { - // given - Long id1 = userService.saveUser(CreateUserDto.of("testUser", "testPassword", 0, 175, 1, 25)); - Long id2 = userService.saveUser(CreateUserDto.of("followUser", "testPassword", 0, 175, 1, 25)); + // Given + Long userId = 1L; // 팔로우 취소를 요청한 사용자의 ID + Long unfollowId = 2L; // 팔로우를 취소할 사용자의 ID - // when - userService.followUser(id1, id2); - userService.unfollowUser(id1, id2); + given(userRepository.existsById(userId)).willReturn(true); // userId에 해당하는 사용자가 존재함 + given(userRepository.existsById(unfollowId)).willReturn(true); // unfollowId에 해당하는 사용자가 존재함 + given(followRepository.existsByFromUserAndToUser(userId, unfollowId)).willReturn(true); + + // When + userService.unfollowUser(userId, unfollowId); - // then - assertEquals(0, followRepository.findAllByFromUser(id1).size()); + // Then + verify(followRepository, times(1)).delete(any(Follow.class)); } } \ No newline at end of file