44import dmu .dasom .api .domain .common .exception .ErrorCode ;
55import dmu .dasom .api .domain .email .enums .MailType ;
66import dmu .dasom .api .domain .email .service .EmailService ;
7+ import dmu .dasom .api .global .generation .service .GenerationService ;
78import jakarta .mail .MessagingException ;
89import jakarta .mail .internet .MimeMessage ;
910import org .junit .jupiter .api .BeforeEach ;
@@ -29,6 +30,9 @@ class EmailServiceTest {
2930 @ Mock
3031 private TemplateEngine templateEngine ;
3132
33+ @ Mock
34+ private GenerationService generationService ;
35+
3236 @ InjectMocks
3337 private EmailService emailService ;
3438
@@ -42,6 +46,9 @@ void setUp() {
4246
4347 // 테스트 환경에서 from 값을 설정
4448 ReflectionTestUtils .
setField (
emailService ,
"from" ,
"[email protected] " );
49+
50+ // generationService Mock 반환값 설정
51+ when (generationService .getCurrentGeneration ()).thenReturn ("34기" );
4552 }
4653
4754 @ Test
@@ -52,9 +59,8 @@ void sendEmail_documentResult() throws MessagingException {
5259 String name = "지원자" ;
5360 MailType mailType = MailType .DOCUMENT_RESULT ;
5461
55- String expectedTemplate = "email-template" ;
56- String expectedHtmlBody = "<html><body>Document Pass</body></html>" ;
57- when (templateEngine .process (eq (expectedTemplate ), any (Context .class ))).thenReturn (expectedHtmlBody );
62+ when (templateEngine .process (eq ("email-template" ), any (Context .class )))
63+ .thenReturn ("<html><body>Document Pass - 34기</body></html>" );
5864
5965 // when
6066 emailService .sendEmail (to , name , mailType );
@@ -65,7 +71,8 @@ void sendEmail_documentResult() throws MessagingException {
6571
6672 MimeMessage sentMessage = messageCaptor .getValue ();
6773 assertNotNull (sentMessage );
68- verify (templateEngine ).process (eq (expectedTemplate ), any (Context .class ));
74+ verify (templateEngine ).process (eq ("email-template" ), any (Context .class ));
75+ verify (generationService ).getCurrentGeneration ();
6976 }
7077
7178 @ Test
@@ -76,9 +83,8 @@ void sendEmail_finalResult() throws MessagingException {
7683 String name = "지원자" ;
7784 MailType mailType = MailType .FINAL_RESULT ;
7885
79- String expectedTemplate = "email-template" ;
80- String expectedHtmlBody = "<html><body>Final Pass</body></html>" ;
81- when (templateEngine .process (eq (expectedTemplate ), any (Context .class ))).thenReturn (expectedHtmlBody );
86+ when (templateEngine .process (eq ("email-template" ), any (Context .class )))
87+ .thenReturn ("<html><body>Final Pass - 36기</body></html>" );
8288
8389 // when
8490 emailService .sendEmail (to , name , mailType );
@@ -89,7 +95,8 @@ void sendEmail_finalResult() throws MessagingException {
8995
9096 MimeMessage sentMessage = messageCaptor .getValue ();
9197 assertNotNull (sentMessage );
92- verify (templateEngine ).process (eq (expectedTemplate ), any (Context .class ));
98+ verify (templateEngine ).process (eq ("email-template" ), any (Context .class ));
99+ verify (generationService ).getCurrentGeneration ();
93100 }
94101
95102 @ Test
0 commit comments