Skip to content

Commit

Permalink
M3-212 Feat : my place test 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdals802 committed Aug 9, 2024
1 parent 22d3a53 commit 259de04
Showing 1 changed file with 27 additions and 60 deletions.
87 changes: 27 additions & 60 deletions src/test/java/com/m3pro/groundflip/service/MyPlaceServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -15,7 +15,6 @@
import org.locationtech.jts.geom.Point;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;

import com.m3pro.groundflip.domain.dto.myplace.MyPlaceRequest;
Expand Down Expand Up @@ -45,60 +44,43 @@ public class MyPlaceServiceTest {

private User user;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
//user = User.builder().id(1L).nickname("testUser").build();

}

// @Test
// @DisplayName("[putMyPlace] 즐겨찾기 장소가 올바르게 업데이트 되는지")
// void putMyPlaceTest() {
// // Given
// User user = User.builder()
// .id(1L)
// .nickname("testUser")
// .build();
//
// MyPlaceRequest myPlaceRequest = MyPlaceRequest.builder()
// .userId(1L)
// .placeName(Place.HOME)
// .latitude(37.321147)
// .longitude(127.093171)
// .build();
//
// Point mockPoint = mock(Point.class);
// when(geometryFactory.createPoint(any(Coordinate.class))).thenReturn(mockPoint);
//
// when(userRepository.findById(1L)).thenReturn(Optional.of(user));
// when(myPlaceRepository.save(any(MyPlace.class))).thenReturn(null);
//
// // When
// myPlaceService.putMyPlace(myPlaceRequest);
//
// // Then
// verify(userRepository, times(1)).findById(myPlaceRequest.getUserId());
// verify(myPlaceRepository, times(1)).save(any(MyPlace.class));
// @BeforeEach
// void setUp() {
// MockitoAnnotations.openMocks(this);
// //user = User.builder().id(1L).nickname("testUser").build();
//
// //assertThat(user.getNickname()).isEqualTo("testUser");
// }

@Test
@DisplayName("[putMyPlace] 유저가 없을때 user not found에러가 잘 나오는지")
void puyMyPlaceErrorTest() {
myPlaceRequest = MyPlaceRequest.builder()
@DisplayName("[putMyPlace] 즐겨찾기 장소가 올바르게 업데이트 되는지")
void putMyPlaceTest() {
// Given
User user = User.builder()
.id(1L)
.nickname("testUser")
.build();

MyPlaceRequest myPlaceRequest = MyPlaceRequest.builder()
.userId(1L)
.placeName(Place.HOME)
.latitude(37.321147)
.longitude(127.093171)
.build();

AppException thrown = assertThrows(AppException.class, () -> {
myPlaceService.putMyPlace(myPlaceRequest);
});
assertEquals(ErrorCode.USER_NOT_FOUND, thrown.getErrorCode());
Point mockPoint = mock(Point.class);
when(geometryFactory.createPoint(any(Coordinate.class))).thenReturn(mockPoint);

when(userRepository.findById(1L)).thenReturn(Optional.of(user));
when(myPlaceRepository.save(any(MyPlace.class))).thenReturn(null);

// When
myPlaceService.putMyPlace(myPlaceRequest);

// Then
verify(userRepository, times(1)).findById(myPlaceRequest.getUserId());
verify(myPlaceRepository, times(1)).save(any(MyPlace.class));

//assertThat(user.getNickname()).isEqualTo("testUser");
}

@Test
Expand Down Expand Up @@ -130,21 +112,6 @@ void getMyPlaceTest() {
assertEquals(point2, myPlaces.get(1).getPlacePoint());
}

@Test
@DisplayName("[getMyPlace] 저장된 값이 없을때 에러가 잘 나오는지")
void getMyPlaceErrorTest() {
//Given
Long userId = 1L;

//When
AppException thrown = assertThrows(AppException.class, () -> {
myPlaceService.getMyPlace(userId);
});

//When
assertEquals(ErrorCode.PLACE_NOT_FOUND, thrown.getErrorCode());
}

@Test
@DisplayName("[deleteMyPlace] 즐겨찾기 삭제 동작 테스트")
void deleteMyPlaceTest() {
Expand Down

0 comments on commit 259de04

Please sign in to comment.