Skip to content

Commit

Permalink
KL-166/test: fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhamma committed Sep 9, 2024
1 parent f0fe22c commit 7a66599
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@ExtendWith(MockitoExtension.class)
@Transactional
public class CommentServiceTest {
public class CommentServiceImplTest {
@Mock
private CommentRepository commentRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void testPostLike() throws Exception {

// when & then
mockMvc.perform(post("/v1/products/{productId}/likes", productId))
.andExpect(status().isOk())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.isSuccess", is(true)))
.andExpect(jsonPath("$.data.isLiked", is(true)))
.andExpect(jsonPath("$.data.likeCount", is(1)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void afterEach() {
void testPostLike() throws Exception {
// when & then
mockMvc.perform(post("/v1/products/{productId}/likes", product.getId()))
.andExpect(status().isOk())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.data.isLiked", is(true)))
.andExpect(jsonPath("$.data.likeCount", is(1)));

Expand All @@ -97,12 +97,12 @@ void testDeleteLike() throws Exception {
void testPostLikeMultiple() throws Exception {
// when & then
mockMvc.perform(post("/v1/products/{productId}/likes", product.getId()))
.andExpect(status().isOk())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.data.isLiked", is(true)))
.andExpect(jsonPath("$.data.likeCount", is(1)));

mockMvc.perform(post("/v1/products/{productId}/likes", product.getId()))
.andExpect(status().isOk())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.data.isLiked", is(true)))
.andExpect(jsonPath("$.data.likeCount", is(1)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

@ExtendWith(MockitoExtension.class)
@Transactional
public class NotificationServiceTest {
public class NotificationServiceImplTest {

@Mock
private NotificationRepository notificationRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ void testCreateProduct() {
void testUpdateProduct() {
// Given
when(productRepository.findById(1L)).thenReturn(Optional.of(testProduct));
when(userUtil.getCurrentUser()).thenReturn(user);
when(cityUtil.findCityEntityById(1L)).thenReturn(city);
when(subcategoryUtil.findSubcategoryEntityById(1L)).thenReturn(subcategory);
when(currencyUtil.findCurrencyEntityById(1L)).thenReturn(currency);
Expand Down Expand Up @@ -441,6 +442,7 @@ void testUpdateProduct_NotFound() {
void testDeleteProduct() {
// Given
when(productRepository.findById(1L)).thenReturn(Optional.of(testProduct));
when(userUtil.getCurrentUser()).thenReturn(user);

// When
productService.deleteProduct(1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.util.Optional;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -38,10 +40,10 @@ public void testGetUserById() {
// given

User user = mock(User.class);
when(userUtil.getCurrentUser()).thenReturn(user);
when(user.getId()).thenReturn(1L);
when(user.getName()).thenReturn("testUser");
when(user.getDescription()).thenReturn("테스트입니다.");
when(userRepository.findById(1L)).thenReturn(Optional.of(user));

// when
UserDetailResponse userDto = userServiceImpl.getUserById(1L);
Expand Down

0 comments on commit 7a66599

Please sign in to comment.