Skip to content

Commit

Permalink
refactor: Modify test by deleting event publish
Browse files Browse the repository at this point in the history
  • Loading branch information
chris910512 committed Dec 11, 2023
1 parent b0e1397 commit 8b93100
Showing 1 changed file with 16 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
package com.depromeet.breadmapbackend.domain.admin.bakery.service;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.*;

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

import com.depromeet.breadmapbackend.domain.search.dto.keyword.BakeryLoadData;
import com.depromeet.breadmapbackend.domain.admin.bakery.handler.OpenSearchEventPublisher;
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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationEventPublisher;

import com.depromeet.breadmapbackend.domain.admin.bakery.AdminBakeryServiceImpl;
import com.depromeet.breadmapbackend.domain.admin.bakery.dto.AdminBakeryDto;
import com.depromeet.breadmapbackend.domain.admin.bakery.dto.BakeryAddDto;
Expand All @@ -39,6 +16,21 @@
import com.depromeet.breadmapbackend.domain.bakery.report.BakeryAddReportRepository;
import com.depromeet.breadmapbackend.domain.user.User;
import com.depromeet.breadmapbackend.global.infra.properties.CustomAWSS3Properties;
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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.*;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.BDDMockito.*;

@ExtendWith(MockitoExtension.class)
public class AdminBakeryServiceTest {
Expand All @@ -53,14 +45,10 @@ public class AdminBakeryServiceTest {
private BakeryRepository bakeryRepository;
@Mock
private CustomAWSS3Properties customAWSS3Properties;
@Mock
private ApplicationEventPublisher eventPublisher;
@Mock
private OpenSearchEventPublisher openSearchEventPublisher;

private List<Bakery> bakeries;
private List<Product> products;
private CustomAWSS3Properties.DefaultImage defaultImage = new CustomAWSS3Properties.DefaultImage(
private final CustomAWSS3Properties.DefaultImage defaultImage = new CustomAWSS3Properties.DefaultImage(
"bakery default image",
"comment default image",
"like default image",
Expand Down Expand Up @@ -202,9 +190,6 @@ void after() {
verify(bakeryRepository, times(1))
.existsByNameAndAddress(addRequest.getName(), addRequest.getAddress());

ArgumentCaptor<BakeryLoadData> bakeryLoadDataCaptor = ArgumentCaptor.forClass(BakeryLoadData.class);
verify(openSearchEventPublisher).publishSaveBakery(bakeryLoadDataCaptor.capture());

}

@DisplayName("addBakery - 이미지 0개 등록 테스트")
Expand Down Expand Up @@ -255,8 +240,6 @@ void after() {
verify(bakeryRepository, times(1))
.existsByNameAndAddress(addRequest.getName(), addRequest.getAddress());

ArgumentCaptor<BakeryLoadData> bakeryLoadDataCaptor = ArgumentCaptor.forClass(BakeryLoadData.class);
verify(openSearchEventPublisher).publishSaveBakery(bakeryLoadDataCaptor.capture());
}

@DisplayName("updateBakery 테스트")
Expand Down Expand Up @@ -317,9 +300,6 @@ void after() {
"2023-08-2700:00:00", "update check point"
);

ArgumentCaptor<BakeryLoadData> bakeryLoadDataCaptor = ArgumentCaptor.forClass(BakeryLoadData.class);
verify(openSearchEventPublisher).publishSaveBakery(bakeryLoadDataCaptor.capture());

}

@DisplayName("updateBakery 테스트 - 수정 이미지가 0개일 경우 기본 이미지 1개를 삽입한다")
Expand Down Expand Up @@ -364,8 +344,5 @@ void after() {
assertThat(bakeries.get(0).getImages()).hasSize(1);
assertThat(bakeries.get(0).getImages().get(0)).contains(
customAWSS3Properties.getCloudFront() + "/" + customAWSS3Properties.getDefaultImage().getBakery());

ArgumentCaptor<BakeryLoadData> bakeryLoadDataCaptor = ArgumentCaptor.forClass(BakeryLoadData.class);
verify(openSearchEventPublisher).publishSaveBakery(bakeryLoadDataCaptor.capture());
}
}

0 comments on commit 8b93100

Please sign in to comment.