@Test @RunWithCustomExecutor public void when_find_by_identifier_should_return_null_given_no_result() throws VitamException { DbRequestResult findResultMock = mock(DbRequestResult.class); when(findResultMock.getCount()).thenReturn(1l); when(findResultMock.getDocuments(ManagementContract.class, ManagementContractModel.class)) .thenReturn(Arrays.asList()); when(findResultMock.getRequestResponseOK(any(JsonNode.class), eq(ManagementContract.class), eq(ManagementContractModel.class))) .thenReturn(new RequestResponseOK<ManagementContractModel>() .addAllResults(Arrays.asList(getManagementContract("IdentifierMC1")))); when(mongoAccess.findDocuments(any(), eq(FunctionalAdminCollections.MANAGEMENT_CONTRACT))) .thenReturn(findResultMock); ManagementContractModel response = managementContractService.findByIdentifier("IdentifierMC1"); assertThat(response).isNull(); verify(mongoAccess, times(1)).findDocuments(any(), eq(FunctionalAdminCollections.MANAGEMENT_CONTRACT)); }
@Override public ManagementContractModel findByIdentifier(String identifier) throws ReferentialException, InvalidParseOperationException { SanityChecker.checkParameter(identifier); try (DbRequestResult result = ContractHelper.findByIdentifier(identifier, FunctionalAdminCollections.MANAGEMENT_CONTRACT, mongoAccess)) { final List<ManagementContractModel> list = result.getDocuments(ManagementContract.class, ManagementContractModel.class); if (list.isEmpty()) { return null; } return list.get(0); } }
ManagementContractImpl implements ContractService<ManagementContractModel> { @Override public ManagementContractModel findByIdentifier(String identifier) throws ReferentialException, InvalidParseOperationException { SanityChecker.checkParameter(identifier); try (DbRequestResult result = ContractHelper.findByIdentifier(identifier, FunctionalAdminCollections.MANAGEMENT_CONTRACT, mongoAccess)) { final List<ManagementContractModel> list = result.getDocuments(ManagementContract.class, ManagementContractModel.class); if (list.isEmpty()) { return null; } return list.get(0); } } }
ManagementContractImpl implements ContractService<ManagementContractModel> { @Override public ManagementContractModel findByIdentifier(String identifier) throws ReferentialException, InvalidParseOperationException { SanityChecker.checkParameter(identifier); try (DbRequestResult result = ContractHelper.findByIdentifier(identifier, FunctionalAdminCollections.MANAGEMENT_CONTRACT, mongoAccess)) { final List<ManagementContractModel> list = result.getDocuments(ManagementContract.class, ManagementContractModel.class); if (list.isEmpty()) { return null; } return list.get(0); } } ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService);  ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
            StorageClient storageClient, LogbookOperationsClient logbookOperationsClient,
            FunctionalBackupService functionalBackupService); }
ManagementContractImpl implements ContractService<ManagementContractModel> { @Override public ManagementContractModel findByIdentifier(String identifier) throws ReferentialException, InvalidParseOperationException { SanityChecker.checkParameter(identifier); try (DbRequestResult result = ContractHelper.findByIdentifier(identifier, FunctionalAdminCollections.MANAGEMENT_CONTRACT, mongoAccess)) { final List<ManagementContractModel> list = result.getDocuments(ManagementContract.class, ManagementContractModel.class); if (list.isEmpty()) { return null; } return list.get(0); } } ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService);  ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
            StorageClient storageClient, LogbookOperationsClient logbookOperationsClient,
            FunctionalBackupService functionalBackupService); @Override RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList); @Override RequestResponse<ManagementContractModel> updateContract(String identifier, JsonNode queryDsl); @Override ManagementContractModel findByIdentifier(String identifier); @Override RequestResponseOK<ManagementContractModel> findContracts(JsonNode queryDsl); @Override void close(); }
ManagementContractImpl implements ContractService<ManagementContractModel> { @Override public ManagementContractModel findByIdentifier(String identifier) throws ReferentialException, InvalidParseOperationException { SanityChecker.checkParameter(identifier); try (DbRequestResult result = ContractHelper.findByIdentifier(identifier, FunctionalAdminCollections.MANAGEMENT_CONTRACT, mongoAccess)) { final List<ManagementContractModel> list = result.getDocuments(ManagementContract.class, ManagementContractModel.class); if (list.isEmpty()) { return null; } return list.get(0); } } ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService);  ManagementContractImpl(MongoDbAccessAdminImpl mongoAccess, VitamCounterService vitamCounterService,
            StorageClient storageClient, LogbookOperationsClient logbookOperationsClient,
            FunctionalBackupService functionalBackupService); @Override RequestResponse<ManagementContractModel> createContracts(List<ManagementContractModel> contractModelList); @Override RequestResponse<ManagementContractModel> updateContract(String identifier, JsonNode queryDsl); @Override ManagementContractModel findByIdentifier(String identifier); @Override RequestResponseOK<ManagementContractModel> findContracts(JsonNode queryDsl); @Override void close(); static final String CONTRACT_BACKUP_EVENT; }