Skip to content

Commit

Permalink
regular test for jobApplication controller
Browse files Browse the repository at this point in the history
  • Loading branch information
januschung committed Oct 13, 2024
1 parent 76eeb3e commit 9b0d5af
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testAllInterviewWhenNoInterviewsThenReturnEmptyResult() {
}

@Test
void getInterview() {
void testGetInterview() {
Interview Interview1 = new Interview();
when(interviewService.getInterview(anyInt())).thenReturn(Mono.just(Interview1));

Expand Down
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());
}

}

0 comments on commit 9b0d5af

Please sign in to comment.