-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1af0781
commit 0268301
Showing
6 changed files
with
175 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/test/java/com/inq/wishhair/wesharewishhair/global/mail/EmailSenderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.inq.wishhair.wesharewishhair.global.mail; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.thymeleaf.ITemplateEngine; | ||
import org.thymeleaf.context.Context; | ||
|
||
import com.inq.wishhair.wesharewishhair.user.event.RefundMailSendEvent; | ||
|
||
import jakarta.mail.MessagingException; | ||
import jakarta.mail.internet.MimeMessage; | ||
|
||
@DisplayName("[EmailSender 테스트]") | ||
class EmailSenderTest { | ||
|
||
private static final String AUTH_TEMPLATE = "AuthMailTemplate"; | ||
private static final String REFUND_TEMPLATE = "RefundRequestMailTemplate"; | ||
private static final String ADDRESS = "[email protected]"; | ||
|
||
private final EmailSender emailSender; | ||
private final JavaMailSender mailSender; | ||
private final ITemplateEngine templateEngine; | ||
private final MimeMessage mimeMessage; | ||
|
||
public EmailSenderTest() { | ||
this.mailSender = Mockito.mock(); | ||
this.templateEngine = Mockito.mock(ITemplateEngine.class); | ||
this.mimeMessage = Mockito.mock(MimeMessage.class); | ||
this.emailSender = new EmailSender("from", "receiver", mailSender, templateEngine); | ||
} | ||
|
||
@Test | ||
@DisplayName("인증 메일 발송 테스트") | ||
void sendAuthMail() throws MessagingException, UnsupportedEncodingException { | ||
//given | ||
given(templateEngine.process(any(String.class), any(Context.class))).willReturn(AUTH_TEMPLATE); | ||
given(mailSender.createMimeMessage()).willReturn(mimeMessage); | ||
|
||
//when | ||
boolean actual = emailSender.sendAuthMail(ADDRESS, "1927"); | ||
|
||
//then | ||
assertThat(actual).isTrue(); | ||
} | ||
|
||
@Test | ||
@DisplayName("환급 요청 메일 발송 테스트") | ||
void sendRefundRequestMail() throws MessagingException, UnsupportedEncodingException { | ||
//given | ||
given(templateEngine.process(any(String.class), any(Context.class))).willReturn(REFUND_TEMPLATE); | ||
given(mailSender.createMimeMessage()).willReturn(mimeMessage); | ||
RefundMailSendEvent event = new RefundMailSendEvent("userA", "기업은행", "111111111", 1000); | ||
|
||
//when | ||
boolean actual = emailSender.sendRefundRequestMail(event); | ||
|
||
//then | ||
assertThat(actual).isTrue(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...st/java/com/inq/wishhair/wesharewishhair/global/mail/event/MailSendEventListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.inq.wishhair.wesharewishhair.global.mail.event; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
|
||
import com.inq.wishhair.wesharewishhair.auth.event.AuthMailSendEvent; | ||
import com.inq.wishhair.wesharewishhair.common.support.MockTestSupport; | ||
import com.inq.wishhair.wesharewishhair.global.mail.EmailSender; | ||
import com.inq.wishhair.wesharewishhair.point.application.dto.PointUseRequest; | ||
import com.inq.wishhair.wesharewishhair.user.domain.entity.Email; | ||
import com.inq.wishhair.wesharewishhair.user.event.RefundMailSendEvent; | ||
|
||
class MailSendEventListenerTest extends MockTestSupport { | ||
private static final String ADDRESS = "[email protected]"; | ||
|
||
@InjectMocks | ||
private MailSendEventListener listener; | ||
|
||
@Mock | ||
private EmailSender emailSender; | ||
|
||
@Test | ||
@DisplayName("인증 메일 발송 이벤트 리스너 테스트") | ||
void sendAuthMail() throws Exception { | ||
//given | ||
final String authKey = "2816"; | ||
given(emailSender.sendAuthMail(anyString(), anyString())).willReturn(true); | ||
|
||
//when, then | ||
assertDoesNotThrow(() -> listener.sendAuthMail(new AuthMailSendEvent(new Email(ADDRESS), authKey))); | ||
} | ||
|
||
@Test | ||
@DisplayName("포인트 환급요청 메일 발송 이벤트 리스너 테스트") | ||
void sendRefundMail() throws Exception { | ||
//given | ||
PointUseRequest request = new PointUseRequest("bank", "1234", 1000); | ||
RefundMailSendEvent event = request.toRefundMailEvent("userName"); | ||
given(emailSender.sendRefundRequestMail(event)).willReturn(true); | ||
|
||
//when, then | ||
assertDoesNotThrow(() -> listener.sendRefundMail(event)); | ||
} | ||
} |