@@ -967,13 +967,15 @@ void temporarySaveExistingLetter_success() throws Exception {
967967 // given
968968 Long letterId = 1L ;
969969 Long writerId = 1L ;
970+ Long matchingId = 1L ;
970971
971972 // Letter를 mock으로 생성
972973 Letter existingLetter = mock (Letter .class );
973974 // mock 객체에 필요한 getter 메서드 동작 정의
974975 when (existingLetter .getId ()).thenReturn (letterId );
975976 when (existingLetter .getTitle ()).thenReturn ("임시 저장 제목" );
976977 when (existingLetter .getContent ()).thenReturn ("임시 저장 내용" );
978+ when (existingLetter .getMatchingId ()).thenReturn (matchingId );
977979 when (existingLetter .getCategory ()).thenReturn (Category .ETC );
978980 when (existingLetter .getFontType ()).thenReturn (FontType .HIMCHAN );
979981 when (existingLetter .getPaperType ()).thenReturn (PaperType .COMFORT );
@@ -987,6 +989,7 @@ void temporarySaveExistingLetter_success() throws Exception {
987989 Field fontField = TemporarySaveLetterRequest .class .getDeclaredField ("fontType" );
988990 Field paperTypeField = TemporarySaveLetterRequest .class .getDeclaredField ("paperType" );
989991 Field receiverIdField = TemporarySaveLetterRequest .class .getDeclaredField ("receiverId" );
992+ Field matchingIdField = TemporarySaveLetterRequest .class .getDeclaredField ("matchingId" );
990993 Field parentLetterIdField = TemporarySaveLetterRequest .class .getDeclaredField ("parentLetterId" );
991994
992995 titleField .setAccessible (true );
@@ -995,6 +998,7 @@ void temporarySaveExistingLetter_success() throws Exception {
995998 fontField .setAccessible (true );
996999 paperTypeField .setAccessible (true );
9971000 receiverIdField .setAccessible (true );
1001+ matchingIdField .setAccessible (true );
9981002 parentLetterIdField .setAccessible (true );
9991003
10001004 titleField .set (request , "임시 저장 제목" );
@@ -1003,6 +1007,7 @@ void temporarySaveExistingLetter_success() throws Exception {
10031007 fontField .set (request , FontType .HIMCHAN );
10041008 paperTypeField .set (request , PaperType .COMFORT );
10051009 receiverIdField .set (request , null );
1010+ matchingIdField .set (request , matchingId );
10061011 parentLetterIdField .set (request , null );
10071012
10081013 // 서비스 메서드 모킹
@@ -1013,6 +1018,7 @@ void temporarySaveExistingLetter_success() throws Exception {
10131018 // void 메서드 모킹 (doNothing 사용)
10141019 doNothing ().when (existingLetter ).updateTemporarySave (
10151020 request .getReceiverId (),
1021+ request .getMatchingId (),
10161022 request .getParentLetterId (),
10171023 request .getCategory (),
10181024 request .getTitle (),
@@ -1028,6 +1034,7 @@ void temporarySaveExistingLetter_success() throws Exception {
10281034 () -> assertEquals (letterId , response .getLetterId ()),
10291035 () -> assertEquals ("임시 저장 제목" , response .getTitle ()),
10301036 () -> assertEquals ("임시 저장 내용" , response .getContent ()),
1037+ () -> assertEquals (matchingId , response .getMatchingId ()),
10311038 () -> assertEquals (Category .ETC , response .getCategory ()),
10321039 () -> assertEquals (FontType .HIMCHAN , response .getFontType ()),
10331040 () -> assertEquals (PaperType .COMFORT , response .getPaperType ()),
@@ -1038,79 +1045,14 @@ void temporarySaveExistingLetter_success() throws Exception {
10381045 verify (letterRepository ).findByIdAndWriterId (letterId , writerId );
10391046 verify (existingLetter ).updateTemporarySave (
10401047 request .getReceiverId (),
1048+ request .getMatchingId (),
10411049 request .getParentLetterId (),
10421050 request .getCategory (),
10431051 request .getTitle (),
10441052 request .getContent ()
10451053 );
10461054 }
10471055
1048-
1049- @ Test
1050- @ DisplayName ("새 편지 임시 저장 성공 테스트" )
1051- void temporarySaveNewLetter_success () throws Exception {
1052- // given
1053- Long writerId = 1L ;
1054- Long newLetterId = 1L ;
1055-
1056- TemporarySaveLetterRequest request = new TemporarySaveLetterRequest ();
1057- Field titleField = TemporarySaveLetterRequest .class .getDeclaredField ("title" );
1058- Field contentField = TemporarySaveLetterRequest .class .getDeclaredField ("content" );
1059- Field categoryField = TemporarySaveLetterRequest .class .getDeclaredField ("category" );
1060- Field fontField = TemporarySaveLetterRequest .class .getDeclaredField ("fontType" );
1061- Field paperTypeField = TemporarySaveLetterRequest .class .getDeclaredField ("paperType" );
1062- Field parentLetterIdField = TemporarySaveLetterRequest .class .getDeclaredField ("parentLetterId" );
1063- Field receiverIdField = TemporarySaveLetterRequest .class .getDeclaredField ("receiverId" );
1064-
1065- titleField .setAccessible (true );
1066- contentField .setAccessible (true );
1067- categoryField .setAccessible (true );
1068- fontField .setAccessible (true );
1069- paperTypeField .setAccessible (true );
1070- parentLetterIdField .setAccessible (true );
1071- receiverIdField .setAccessible (true );
1072-
1073- titleField .set (request , "새 임시 저장 제목" );
1074- contentField .set (request , "새 임시 저장 내용" );
1075- categoryField .set (request , Category .ETC );
1076- fontField .set (request , FontType .GYEONGGI );
1077- paperTypeField .set (request , PaperType .PAPER );
1078- parentLetterIdField .set (request , null );
1079- receiverIdField .set (request , null );
1080-
1081- // 서비스 메서드 모킹
1082- when (authFacade .getCurrentUserId ()).thenReturn (writerId );
1083- when (authFacade .getZipCode ()).thenReturn ("12345" );
1084-
1085- // 중요: letterRepository.save() 메서드가 호출될 때 Letter 객체를 캡처하고 ID를 설정한 후 반환
1086- doAnswer (invocation -> {
1087- Letter letterToSave = invocation .getArgument (0 );
1088- // 저장 시점에 ID 설정
1089- ReflectionTestUtils .setField (letterToSave , "id" , newLetterId );
1090- return letterToSave ;
1091- }).when (letterRepository ).save (any (Letter .class ));
1092-
1093- // when
1094- LetterResponse response = letterService .temporarySaveLetter (null , request );
1095-
1096- // then
1097- assertAll ("새 편지 임시 저장 응답 검증" ,
1098- () -> assertNotNull (response ),
1099- () -> assertEquals (newLetterId , response .getLetterId ()),
1100- () -> assertEquals ("새 임시 저장 제목" , response .getTitle ()),
1101- () -> assertEquals ("새 임시 저장 내용" , response .getContent ()),
1102- () -> assertEquals (Category .ETC , response .getCategory ()),
1103- () -> assertEquals (FontType .GYEONGGI , response .getFontType ()),
1104- () -> assertEquals (PaperType .PAPER , response .getPaperType ()),
1105- () -> assertEquals (Status .SAVED , response .getStatus ()),
1106- () -> assertNull (response .getParentLetterId ()),
1107- () -> assertEquals ("12345" , response .getZipCode ())
1108- );
1109-
1110- verify (authFacade ).getCurrentUserId ();
1111- verify (letterRepository ).save (any (Letter .class ));
1112- }
1113-
11141056 @ Test
11151057 @ DisplayName ("임시 저장 편지 삭제 성공" )
11161058 void delete_temporarySaveLetter_success () throws Exception {
0 commit comments