@Test public void testFindCompanyByIdReturnsNullForNonExistingCompanyId() { when(companyViewRepository.getOne(testCompanyId.getIdentifier())).thenReturn(null); Assert.assertNull(testSubject.find(new CompanyByIdQuery(testCompanyId))); }
@QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); }
CompanyEventHandler { @QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); } }
CompanyEventHandler { @QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); } CompanyEventHandler(CompanyViewRepository companyRepository); }
CompanyEventHandler { @QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); } CompanyEventHandler(CompanyViewRepository companyRepository); @EventHandler void on(CompanyCreatedEvent event); @QueryHandler CompanyView find(CompanyByIdQuery query); @QueryHandler List<CompanyView> find(FindAllCompaniesQuery query); }
CompanyEventHandler { @QueryHandler public CompanyView find(CompanyByIdQuery query) { String companyId = query.getCompanyId().getIdentifier(); return Optional.ofNullable(companyRepository.getOne(companyId)) .orElseGet(() -> { logger.warn("Tried to retrieve a Company query model with a non existent company id [{}]", companyId); return null; }); } CompanyEventHandler(CompanyViewRepository companyRepository); @EventHandler void on(CompanyCreatedEvent event); @QueryHandler CompanyView find(CompanyByIdQuery query); @QueryHandler List<CompanyView> find(FindAllCompaniesQuery query);  }