Skip to content

Commit e880c68

Browse files
committed
test(mentorship): updated mentorship service unit tests.
1 parent cd4be56 commit e880c68

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

apps/jobboard-backend/src/test/java/org/bounswe/jobboardbackend/mentorship/service/MentorshipServiceImplTest.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import org.bounswe.jobboardbackend.mentorship.dto.ResumeFileResponseDTO;
1414
import org.bounswe.jobboardbackend.mentorship.model.*;
1515
import org.bounswe.jobboardbackend.mentorship.repository.*;
16+
import org.bounswe.jobboardbackend.notification.service.NotificationService;
1617
import org.junit.jupiter.api.BeforeEach;
1718
import org.junit.jupiter.api.Test;
1819
import org.junit.jupiter.api.extension.ExtendWith;
1920
import org.mockito.*;
21+
import org.mockito.junit.jupiter.MockitoExtension;
2022
import org.springframework.messaging.simp.SimpMessagingTemplate;
2123
import org.springframework.security.core.Authentication;
2224
import org.springframework.test.util.ReflectionTestUtils;
@@ -31,7 +33,7 @@
3133
import static org.mockito.ArgumentMatchers.*;
3234
import static org.mockito.Mockito.*;
3335

34-
@ExtendWith(org.mockito.junit.jupiter.MockitoExtension.class)
36+
@ExtendWith(MockitoExtension.class)
3537
class MentorshipServiceImplTest {
3638

3739
@Mock
@@ -61,6 +63,10 @@ class MentorshipServiceImplTest {
6163
@InjectMocks
6264
private MentorshipServiceImpl mentorshipService;
6365

66+
@Mock
67+
private NotificationService notificationService;
68+
69+
6470
@BeforeEach
6571
void setUp() {
6672
// Replace the internal Storage field with our mock
@@ -250,6 +256,10 @@ void createMentorshipRequest_success() {
250256
when(mentor.getId()).thenReturn(mentorId);
251257
when(mentor.canAccept()).thenReturn(true);
252258

259+
User mentorUser = new User();
260+
mentorUser.setUsername("mentorUser");
261+
when(mentor.getUser()).thenReturn(mentorUser);
262+
253263
User jobSeeker = new User();
254264
jobSeeker.setId(jobSeekerId);
255265

@@ -277,6 +287,7 @@ void createMentorshipRequest_success() {
277287
verify(mentorshipRequestRepository).save(any(MentorshipRequest.class));
278288
}
279289

290+
280291
// ---------------------------------------------------------------------
281292
// respondToMentorshipRequest
282293
// ---------------------------------------------------------------------
@@ -286,27 +297,40 @@ void respondToMentorshipRequest_accept_success() {
286297
Long requestId = 1L;
287298
Long mentorUserId = 10L;
288299

300+
User mentorUser = new User();
301+
mentorUser.setId(mentorUserId);
302+
mentorUser.setUsername("mentorUser");
303+
289304
MentorProfile mentorProfile = new MentorProfile();
290305
mentorProfile.setId(mentorUserId);
291306
mentorProfile.setCurrentMentees(0);
292-
mentorProfile.setUser(new User());
307+
mentorProfile.setUser(mentorUser);
293308

294309
User requester = new User();
295310
requester.setId(20L);
311+
requester.setUsername("requesterUser");
296312

297313
MentorshipRequest request = new MentorshipRequest();
298314
request.setId(requestId);
299315
request.setMentor(mentorProfile);
300316
request.setRequester(requester);
301317
request.setStatus(RequestStatus.PENDING);
302318

303-
when(mentorshipRequestRepository.findById(requestId)).thenReturn(Optional.of(request));
319+
when(mentorshipRequestRepository.findById(requestId))
320+
.thenReturn(Optional.of(request));
321+
304322
when(resumeReviewRepository.save(any(ResumeReview.class)))
305323
.thenAnswer(invocation -> {
306324
ResumeReview r = invocation.getArgument(0);
307325
r.setId(100L);
308326
return r;
309327
});
328+
329+
Conversation conversation = new Conversation();
330+
conversation.setId(555L);
331+
when(chatService.createConversationForReview(any(ResumeReview.class)))
332+
.thenReturn(conversation);
333+
310334
when(mentorshipRequestRepository.save(request)).thenReturn(request);
311335

312336
var result = mentorshipService.respondToMentorshipRequest(requestId, true, mentorUserId);
@@ -316,6 +340,8 @@ void respondToMentorshipRequest_accept_success() {
316340
verify(mentorProfileRepository).save(mentorProfile);
317341
}
318342

343+
344+
319345
@Test
320346
void respondToMentorshipRequest_decline_success() {
321347
Long requestId = 1L;

0 commit comments

Comments
 (0)