Skip to content

Commit

Permalink
Update AdminBakeryServiceTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
chris910512 committed Dec 11, 2023
1 parent 8b93100 commit c8a2b35
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.*;

Expand All @@ -45,6 +48,8 @@ public class AdminBakeryServiceTest {
private BakeryRepository bakeryRepository;
@Mock
private CustomAWSS3Properties customAWSS3Properties;
@Mock
private ApplicationEventPublisher eventPublisher;

private List<Bakery> bakeries;
private List<Product> products;
Expand All @@ -62,6 +67,8 @@ public class AdminBakeryServiceTest {
@BeforeEach
void setup() {

// MockitoAnnotations.openMocks(this);

List<String> images1 = List.of("bakery test image 1", "bakery test image 2");
List<String> images2 = List.of("bakery test image 1");

Expand Down Expand Up @@ -139,6 +146,8 @@ void after() {
verify(customAWSS3Properties, times(bakeries.get(0).getImages().size()))
.getDefaultImage();

ReflectionTestUtils.setField(adminBakeryService, "eventPublisher", eventPublisher);

}

@DisplayName("addBakery 테스트")
Expand Down Expand Up @@ -190,6 +199,8 @@ void after() {
verify(bakeryRepository, times(1))
.existsByNameAndAddress(addRequest.getName(), addRequest.getAddress());

ReflectionTestUtils.setField(adminBakeryService, "eventPublisher", eventPublisher);

}

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

ReflectionTestUtils.setField(adminBakeryService, "eventPublisher", eventPublisher);

}

@DisplayName("updateBakery 테스트")
Expand Down Expand Up @@ -344,5 +357,8 @@ void after() {
assertThat(bakeries.get(0).getImages()).hasSize(1);
assertThat(bakeries.get(0).getImages().get(0)).contains(
customAWSS3Properties.getCloudFront() + "/" + customAWSS3Properties.getDefaultImage().getBakery());

ReflectionTestUtils.setField(adminBakeryService, "eventPublisher", eventPublisher);

}
}

0 comments on commit c8a2b35

Please sign in to comment.