-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from STUDIO-EYE/develop
V.0.0.6
- Loading branch information
Showing
8 changed files
with
1,776 additions
and
473 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
71 changes: 71 additions & 0 deletions
71
src/test/java/studio/studioeye/domain/email/application/EmailServiceTest.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,71 @@ | ||
package studio.studioeye.domain.email.application; | ||
|
||
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 org.springframework.mail.SimpleMailMessage; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import studio.studioeye.domain.email.service.EmailService; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class EmailServiceTest { | ||
|
||
@InjectMocks | ||
private EmailService emailService; // EmailService를 올바르게 주입 | ||
|
||
@Mock | ||
private JavaMailSender javaMailSender; | ||
|
||
@Test | ||
@DisplayName("이메일 전송 성공 테스트") | ||
public void sendEmailSuccess() { | ||
// given | ||
String to = "[email protected]"; | ||
String subject = "Test Subject"; | ||
String text = "Test Body"; | ||
// stub | ||
doNothing().when(javaMailSender).send(any(SimpleMailMessage.class)); | ||
// when | ||
boolean result = emailService.sendEmail(to, subject, text); | ||
// then | ||
assertTrue(result, "이메일이 정상적으로 전송되어야 합니다."); | ||
verify(javaMailSender, times(1)).send(any(SimpleMailMessage.class)); | ||
} | ||
|
||
@Test | ||
@DisplayName("이메일 전송 실패 테스트 - 크기 초과") | ||
public void sendEmailFailDueToSize() { | ||
// given | ||
String to = "[email protected]"; | ||
String subject = "This is a very long subject that will exceed the limit"; | ||
String text = "A".repeat(25 * 1024 * 1024); // 25MB 이상의 텍스트 | ||
// when | ||
boolean result = emailService.sendEmail(to, subject, text); | ||
// then | ||
assertFalse(result, "이메일 크기가 초과된 경우 전송에 실패해야 합니다."); | ||
verify(javaMailSender, never()).send(any(SimpleMailMessage.class)); | ||
} | ||
|
||
@Test | ||
@DisplayName("이메일 전송 실패 테스트 - 수신자 없음") | ||
public void sendEmailFailNoRecipient() { | ||
// given | ||
String to = null; | ||
String subject = "Test Subject"; | ||
String text = "Test Body"; | ||
// when | ||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { | ||
emailService.sendEmail(to, subject, text); | ||
}); | ||
// then | ||
assertEquals("Invalid recipient address", exception.getMessage()); | ||
verify(javaMailSender, never()).send(any(SimpleMailMessage.class)); | ||
} | ||
} |
Oops, something went wrong.