DocumentService { public List<DocumentMetadata> documentQuery(DocumentQueryParams params) { List<DocumentMetadata> documents; List<DocumentMetadata> queryMatchDocs = documentDao.findDocuments(params); List<DocumentMetadata> eventCodeMatchDocs; if (params != null && NullChecker.isNotNullish(params.getEventCodeParams())) { eventCodeMatchDocs = queryByEventCode(params.getEventCodeParams(), params.getSlots()); if (NullChecker.isNotNullish(queryMatchDocs) && NullChecker.isNotNullish(eventCodeMatchDocs)) { documents = createUnion(queryMatchDocs, eventCodeMatchDocs); } else { documents = eventCodeMatchDocs; } } else { documents = queryMatchDocs; } return documents; }  DocumentMetadata saveDocument(DocumentMetadata document); void deleteDocument(DocumentMetadata document); DocumentMetadata getDocument(Long documentId); List<DocumentMetadata> getAllDocuments(); List<DocumentMetadata> documentQuery(DocumentQueryParams params); String getNextID();  }
@Test public void testDocumentQuery() { DocumentService documentService = getDocumentServiceWithMockDaos(); final long DOC_ID = 12345L; final String DOC_UNIQUE_ID = "Doc ID"; DocumentMetadata doc = new DocumentMetadata(); doc.setDocumentid(DOC_ID); doc.setDocumentUniqueId(DOC_UNIQUE_ID); List<DocumentMetadata> documents = new ArrayList<>(); documents.add(doc); DocumentQueryParams dqParams = mock(DocumentQueryParams.class); EventCodeParam ecParam = new EventCodeParam(); ecParam.setEventCode("T-32000"); ecParam.setEventCodeScheme("SNM3"); List<EventCodeParam> ecParamList = new ArrayList<>(); ecParamList.add(ecParam); List<EventCode> eventCodeList = new ArrayList<>(); EventCode eventcode = mock(EventCode.class); eventCodeList.add(eventcode); when(DOCUMENT_DAO.findDocuments(dqParams)).thenReturn(documents); when(dqParams.getEventCodeParams()).thenReturn(ecParamList); when(EVENTCODE_DAO.eventCodeQuery(Mockito.anyList())).thenReturn(eventCodeList); when(eventcode.getDocument()).thenReturn(doc); List<DocumentMetadata> resultDocList = documentService.documentQuery(dqParams); DocumentMetadata resultDoc = resultDocList.get(0); assertEquals(1, resultDocList.size()); assertEquals((Long) DOC_ID, resultDoc.getDocumentid()); assertEquals(DOC_UNIQUE_ID, resultDoc.getDocumentUniqueId()); }