-
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
dd521e5
commit 67c1cc7
Showing
2 changed files
with
73 additions
and
17 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
72 changes: 72 additions & 0 deletions
72
...end/src/test/java/com/kurttekin/can/job_track/presentation/rest/ResumeControllerTest.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,72 @@ | ||
package com.kurttekin.can.job_track.presentation.rest; | ||
|
||
import com.kurttekin.can.job_track.application.dto.ResumeDTO; | ||
import com.kurttekin.can.job_track.domain.model.resume.Resume; | ||
import com.kurttekin.can.job_track.domain.model.user.User; | ||
import com.kurttekin.can.job_track.domain.service.ResumeService; | ||
import com.kurttekin.can.job_track.domain.service.UserService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
class ResumeControllerTest { | ||
|
||
@InjectMocks | ||
private ResumeController resumeController; | ||
|
||
@Mock | ||
private ResumeService resumeService; | ||
|
||
@Mock | ||
private UserService userService; | ||
|
||
private User user; | ||
private UserDetails userDetails; | ||
private Resume resume; | ||
private ResumeDTO resumeDTO; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
// Create mock User and Resume | ||
user = new User(); | ||
user.setId(1L); | ||
user.setUsername("testuser"); | ||
|
||
userDetails = mock(UserDetails.class); | ||
when(userDetails.getUsername()).thenReturn(user.getUsername()); | ||
|
||
resume = new Resume(); | ||
resume.setTitle("Software Developer but unemployed"); | ||
resumeDTO = new ResumeDTO(); | ||
resumeDTO.setTitle("Software Developer but unemployed"); | ||
} | ||
|
||
@Test | ||
public void testCreateOrUpdateResume_Success() { | ||
// Mock userService behavior | ||
when(userService.findUserByUsername(user.getUsername())).thenReturn(Optional.of(user)); | ||
|
||
// Mock resumeService behavior | ||
when(resumeService.createOrUpdateResume(resume)).thenReturn(resumeDTO); | ||
|
||
// Call the controller method | ||
ResponseEntity<ResumeDTO> response = resumeController.createOrUpdateResume(resume, userDetails); | ||
|
||
// Verify and assert | ||
assertEquals(HttpStatus.CREATED, response.getStatusCode()); | ||
assertEquals(resumeDTO, response.getBody()); | ||
verify(userService).findUserByUsername(user.getUsername()); | ||
verify(resumeService).createOrUpdateResume(resume); | ||
} | ||
} |