### Question:
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);  }### Answer:
@Test public void testFindCompanyByIdReturnsACompanyView() { CompanyView testView = new CompanyView(); testView.setIdentifier(testCompanyId.getIdentifier()); testView.setName(COMPANY_NAME); testView.setValue(COMPANY_VALUE); testView.setAmountOfShares(AMOUNT_OF_SHARES); testView.setTradeStarted(false); when(companyViewRepository.getOne(testCompanyId.getIdentifier())).thenReturn(testView); CompanyView result = testSubject.find(new CompanyByIdQuery(testCompanyId)); assertEquals(testView, result); }
@Test public void testFindCompanyByIdReturnsNullForNonExistingCompanyId() { when(companyViewRepository.getOne(testCompanyId.getIdentifier())).thenReturn(null); Assert.assertNull(testSubject.find(new CompanyByIdQuery(testCompanyId))); }
@Test public void testFindAllCompaniesReturnsAllCompanyViews() { CompanyView testView = new CompanyView(); testView.setIdentifier(testCompanyId.getIdentifier()); testView.setName(COMPANY_NAME); testView.setValue(COMPANY_VALUE); testView.setAmountOfShares(AMOUNT_OF_SHARES); testView.setTradeStarted(false); when(companyViewRepository.findAll(any(Pageable.class))).thenReturn(new PageImpl<>(singletonList(testView))); List<CompanyView> result = testSubject.find(new FindAllCompaniesQuery(0, 50)); assertEquals(testView, result.get(0)); }