-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
regular test for jobApplication controller
- Loading branch information
1 parent
76eeb3e
commit 9b0d5af
Showing
2 changed files
with
113 additions
and
1 deletion.
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
112 changes: 112 additions & 0 deletions
112
src/test/java/com/tnite/jobwinner/controller/JobApplicationControllerTest.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,112 @@ | ||
package com.tnite.jobwinner.controller; | ||
|
||
import com.tnite.jobwinner.model.AddInterviewInput; | ||
import com.tnite.jobwinner.model.AddJobApplicationInput; | ||
import com.tnite.jobwinner.model.Interview; | ||
import com.tnite.jobwinner.model.JobApplication; | ||
import com.tnite.jobwinner.service.JobApplicationService; | ||
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 reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class JobApplicationControllerTest { | ||
|
||
@InjectMocks | ||
private JobApplicationController jobApplicationController; | ||
|
||
@Mock | ||
private JobApplicationService jobApplicationService; | ||
|
||
@Test | ||
void testAddJobApplication() { | ||
AddJobApplicationInput addJobApplicationInput = new AddJobApplicationInput(); | ||
JobApplication jobApplication = new JobApplication(); | ||
when(jobApplicationService.addJobApplication(any(AddJobApplicationInput.class))).thenReturn(Mono.just(jobApplication)); | ||
|
||
Mono<JobApplication> result = jobApplicationController.addJobApplication(addJobApplicationInput); | ||
|
||
assertEquals(jobApplication, result.block()); | ||
} | ||
|
||
@Test | ||
void testUpdateJobApplication() { | ||
JobApplication jobApplication = new JobApplication(); | ||
when(jobApplicationService.updateJobApplication(any(JobApplication.class))).thenReturn(Mono.just(jobApplication)); | ||
|
||
Mono<JobApplication> result = jobApplicationController.updateJobApplication(jobApplication); | ||
|
||
assertEquals(jobApplication, result.block()); | ||
} | ||
|
||
@Test | ||
void testDeleteJobApplication() { | ||
JobApplication jobApplication = new JobApplication(); | ||
when(jobApplicationService.deleteJobApplication(anyInt())).thenReturn(Mono.just(jobApplication)); | ||
|
||
Mono<JobApplication> result = jobApplicationService.deleteJobApplication(1); | ||
|
||
assertEquals(jobApplication, result.block()); | ||
} | ||
|
||
@Test | ||
void testAllJobApplication() { | ||
JobApplication jobApplication1 = new JobApplication(); | ||
JobApplication jobApplication2 = new JobApplication(); | ||
when(jobApplicationService.allJobApplication()).thenReturn(Flux.just(jobApplication1, jobApplication2)); | ||
|
||
Flux<JobApplication> result = jobApplicationController.allJobApplication(); | ||
|
||
assertEquals(2, result.collectList().block().size()); | ||
assertEquals(jobApplication1, result.collectList().block().get(0)); | ||
assertEquals(jobApplication2, result.collectList().block().get(1)); | ||
} | ||
|
||
@Test | ||
void testAllJobApplicationWhenNoJobApplicationsThenReturnEmptyResult() { | ||
when(jobApplicationService.allJobApplication()).thenReturn(Flux.empty()); | ||
|
||
Flux<JobApplication> result = jobApplicationService.allJobApplication(); | ||
|
||
assertEquals(0, result.collectList().block().size()); | ||
} | ||
|
||
@Test | ||
void testSearchJobApplicationByIdReturnOneResult() { | ||
JobApplication jobApplication = new JobApplication(); | ||
when(jobApplicationService.searchJobApplications(anyString())).thenReturn(Flux.just(jobApplication)); | ||
|
||
Flux<JobApplication> result = jobApplicationController.searchJobApplications("foo"); | ||
|
||
assertEquals(1, result.collectList().block().size()); | ||
} | ||
|
||
@Test | ||
void testSearchJobApplicationByIdReturnTwoResults() { | ||
JobApplication jobApplication1 = new JobApplication(); | ||
JobApplication jobApplication2 = new JobApplication(); | ||
when(jobApplicationService.searchJobApplications(anyString())).thenReturn(Flux.just(jobApplication1, jobApplication2)); | ||
|
||
Flux<JobApplication> result = jobApplicationController.searchJobApplications("foo"); | ||
|
||
assertEquals(2, result.collectList().block().size()); | ||
} | ||
|
||
@Test | ||
void testSearchJobApplicationByIdReturnEmptyResults() { | ||
when(jobApplicationService.searchJobApplications(anyString())).thenReturn(Flux.empty()); | ||
|
||
Flux<JobApplication> result = jobApplicationController.searchJobApplications("foo"); | ||
|
||
assertEquals(0, result.collectList().block().size()); | ||
} | ||
|
||
} |