### Question:
PrintJobOperations { public DataResponse<BasicPrintJob> getAllPrintJobs(String status) { DataResponse<BasicPrintJob> response = new DataResponse<BasicPrintJob>("Could not get all print jobs"); List<PrintJob> printJobs = status == null? printJobRepo.findActive() : printJobRepo.findPrintJobByStatus(Status.fromValue(status)); if (printJobs == null || printJobs.isEmpty()){ ErrorType.PRINT_JOBS_NOT_EXIST.throwException(); } List<BasicPrintJob> basicPrintJobs = new BasicPrintJob().ConvertPrintJobs(printJobs); response.setSuccess(true); response.setMessage(status == null? "Successfully returned all print jobs" : "Successfully returned print jobs by " + status + " status"); response.setData(basicPrintJobs); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } PrintJobOperations(FileService fileService, PrintJobRepo printJobRepo,
                              ColorTypeRepo colorTypeRepo, CustomerInfoRepo customerInfoRepo,
                              EmployeeRepo employeeRepo, EmailHashUtil emailHashUtil, QueueRepo queueRepo); DataResponse<BasicPrintJob> newPrintJob(PrintJobNewRequest printJobNewRequest, Principal principal); DataResponse<BasicPrintJob> updateModel(Integer printId, PrintModelUpdateRequest model); GenericResponse deleteModel(Integer printId); GenericResponse updatePrintJobStatus(Integer printId, PrintJobUpdateRequest dto); GenericResponse deletePrintJob(PrintJobDeleteRequest dto); DataResponse<BasicPrintJob> getAllPrintJobs(String status); DataResponse<BasicPrintJob> getDeletablePrintJobs(); DataResponse<BasicPrintJob> updatePrintJobProps(Integer printJobId, UpdatePrintJobPropertiesRequest request); DataResponse<BasicPrintJob> getPrintJobById(Integer printJobId);  }### Answer:
@Test public void getAllPrintJobs(){ PrintJob printJob = new PrintJob(); printJob.setColorType(new ColorType(1, "Red")); printJob.setComments("comments"); printJob.setCreatedAt(LocalDateTime.now()); printJob.setQueueId(new Queue(printJob, new Long(1))); printJob.setStatus(Status.ARCHIVED); printJob.setEmployee(new Employee()); printJob.setId(1); List<PrintJob> printJobs = new ArrayList<PrintJob>(); printJobs.add(printJob); when(printJobRepo.findActive()).thenReturn(printJobs); DataResponse<BasicPrintJob> result = operations.getAllPrintJobs(null); Assert.assertEquals(result.getData().get(0).getId(), printJob.getId()); }
@Test public void getAllPrintJobsByStatus() throws Exception { PrintJob printJob = new PrintJob(); printJob.setColorType(new ColorType(1, "Red")); printJob.setComments("comments"); printJob.setCreatedAt(LocalDateTime.now()); printJob.setQueueId(new Queue(printJob, new Long(1))); printJob.setStatus(Status.ARCHIVED); printJob.setEmployee(new Employee()); printJob.setId(1); List<PrintJob> printJobList = Arrays.asList(printJob); when(printJobRepo.findPrintJobByStatus(Status.ARCHIVED)).thenReturn(printJobList); DataResponse<BasicPrintJob> result = operations.getAllPrintJobs(Status.ARCHIVED.getName()); verify(printJobRepo, times(1)).findPrintJobByStatus(Status.ARCHIVED); assertEquals(result.getData().get(0).getId(), printJob.getId()); }
@Test(expected = IdeaLabApiException.class) public void getAllPrintJobs_shouldThrow_IdeaLabApiException_when_printJob_is_not_exist(){ when(printJobRepo.findActive()).thenReturn(null); operations.getAllPrintJobs(null); }
@Test(expected = IdeaLabApiException.class) public void getAllPrintJobs_shouldThrow_IdeaLabApiException_when_empty_printJobs_returned(){ when(printJobRepo.findActive()).thenReturn(new ArrayList<>()); operations.getAllPrintJobs(null); operations.getAllPrintJobs(null); }