### Question:
QueryController { @GetMapping("/portfolio/{portfolioId}") public CompletableFuture<ResponseEntity<PortfolioView>> getPortfolioById(@PathVariable String portfolioId) { return queryGateway.query(new PortfolioByIdQuery(new PortfolioId(portfolioId)), ResponseTypes.instanceOf(PortfolioView.class)) .thenApply(this::wrapResult); } QueryController(QueryGateway queryGateway); @GetMapping("/company/{companyId}") CompletableFuture<ResponseEntity<CompanyView>> getCompanyById(@PathVariable String companyId); @GetMapping("/company") CompletableFuture<ResponseEntity<List<CompanyView>>> findAllCompanies(
            @RequestParam(value = "page", defaultValue = "0") int page,
            @RequestParam(value = "pageSize", defaultValue = "100") int pageSize); @GetMapping("/order-book/{orderBookId}") CompletableFuture<ResponseEntity<OrderBookView>> getOrderBookById(@PathVariable String orderBookId); @GetMapping("/order-book/by-company/{companyId}") CompletableFuture<ResponseEntity<List<OrderBookView>>> getOrderBooksByCompanyId(
            @PathVariable String companyId); @GetMapping("/transaction/{transactionId}") CompletableFuture<ResponseEntity<TransactionView>> getTransactionById(@PathVariable String transactionId); @GetMapping("/transaction/by-portfolio/{portfolioId}") CompletableFuture<ResponseEntity<List<TransactionView>>> getTransactionsByPortfolioId(
            @PathVariable String portfolioId); @GetMapping("/executed-trades/{orderBookId}") CompletableFuture<ResponseEntity<List<TradeExecutedView>>> getExecutedTradesByOrderBookId(
            @PathVariable String orderBookId); @GetMapping("/portfolio/{portfolioId}") CompletableFuture<ResponseEntity<PortfolioView>> getPortfolioById(@PathVariable String portfolioId); @GetMapping("/portfolio/by-user/{userId}") CompletableFuture<ResponseEntity<PortfolioView>> getPortfolioByUserId(@PathVariable String userId); @GetMapping("/user/{userId}") CompletableFuture<ResponseEntity<UserView>> getUserById(@PathVariable String userId); @GetMapping("/user") CompletableFuture<ResponseEntity<List<UserView>>> findAllUsers(
            @RequestParam(value = "page", defaultValue = "0") int page,
            @RequestParam(value = "pageSize", defaultValue = "100") int pageSize); @GetMapping("/subscribe/order-book/{orderBookId}") Flux<ServerSentEvent<OrderBookView>> subscribeToOrderBook(@PathVariable String orderBookId);  }### Answer:
@Test public void testGetPortfolioByIdReturnsPortfolio() throws Exception { PortfolioView expectedView = new PortfolioView(); String testPortfolioId = "some-portfolio-id"; PortfolioByIdQuery testQuery = new PortfolioByIdQuery(new PortfolioId(testPortfolioId)); when(queryGateway.query(eq(testQuery), any(InstanceResponseType.class))) .thenReturn(completedFuture(expectedView)); CompletableFuture<ResponseEntity<PortfolioView>> result = testSubject.getPortfolioById(testPortfolioId); assertTrue(result.isDone()); ResponseEntity<PortfolioView> responseEntity = result.get(); assertSame(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(expectedView, responseEntity.getBody()); verify(queryGateway).query(eq(testQuery), any(InstanceResponseType.class)); }
@Test public void testGetPortfolioByIdReturnsNotFoundForNonExistingId() throws Exception { String testPortfolioId = "non-existing-id"; PortfolioByIdQuery testQuery = new PortfolioByIdQuery(new PortfolioId(testPortfolioId)); when(queryGateway.query(eq(testQuery), any(InstanceResponseType.class))) .thenReturn(completedFuture(null)); CompletableFuture<ResponseEntity<PortfolioView>> result = testSubject.getPortfolioById(testPortfolioId); assertTrue(result.isDone()); ResponseEntity<PortfolioView> responseEntity = result.get(); assertSame(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertNull(responseEntity.getBody()); verify(queryGateway).query(eq(testQuery), any(InstanceResponseType.class)); }