@Test void should_find_stock_when_find_by_id_given_valid_input() { given(findById.bind(stock1.getSymbol(), stock1.getDate())).willReturn(bound); given(session.execute(bound)).willReturn(resultSet); given(resultSet.one()).willReturn(row1); given(row1.getString(SYMBOL)).willReturn(stock1.getSymbol()); given(row1.getInstant(DATE)).willReturn(stock1.getDate()); given(row1.getBigDecimal(VALUE)).willReturn(stock1.getValue()); var stockRepository = new SyncStockRepository(session, insert, delete, findById, findBySymbol, rowMapper); Optional<Stock> result = stockRepository.findById(stock1.getSymbol(), stock1.getDate()); assertThat(result).isNotEmpty().contains(stock1); verify(session).execute(bound); }
@NonNull public Optional<Stock> findById(@NonNull String symbol, @NonNull Instant date) { BoundStatement bound = findById.bind(symbol, date); ResultSet rs = session.execute(bound); return Optional.ofNullable(rs.one()).map(rowMapper); }
SyncStockRepository { @NonNull public Optional<Stock> findById(@NonNull String symbol, @NonNull Instant date) { BoundStatement bound = findById.bind(symbol, date); ResultSet rs = session.execute(bound); return Optional.ofNullable(rs.one()).map(rowMapper); } }
SyncStockRepository { @NonNull public Optional<Stock> findById(@NonNull String symbol, @NonNull Instant date) { BoundStatement bound = findById.bind(symbol, date); ResultSet rs = session.execute(bound); return Optional.ofNullable(rs.one()).map(rowMapper); } SyncStockRepository(
      CqlSession session,
      @Qualifier("stocks.prepared.insert") PreparedStatement insert,
      @Qualifier("stocks.prepared.deleteById") PreparedStatement deleteById,
      @Qualifier("stocks.prepared.findById") PreparedStatement findById,
      @Qualifier("stocks.prepared.findBySymbol") PreparedStatement findBySymbol,
      Function<Row, Stock> rowMapper); }
SyncStockRepository { @NonNull public Optional<Stock> findById(@NonNull String symbol, @NonNull Instant date) { BoundStatement bound = findById.bind(symbol, date); ResultSet rs = session.execute(bound); return Optional.ofNullable(rs.one()).map(rowMapper); } SyncStockRepository(
      CqlSession session,
      @Qualifier("stocks.prepared.insert") PreparedStatement insert,
      @Qualifier("stocks.prepared.deleteById") PreparedStatement deleteById,
      @Qualifier("stocks.prepared.findById") PreparedStatement findById,
      @Qualifier("stocks.prepared.findBySymbol") PreparedStatement findBySymbol,
      Function<Row, Stock> rowMapper); @NonNull Stock save(@NonNull Stock stock); void deleteById(@NonNull String symbol, @NonNull Instant date); @NonNull Optional<Stock> findById(@NonNull String symbol, @NonNull Instant date); @NonNull Stream<Stock> findAllBySymbol(
      @NonNull String symbol,
      @NonNull Instant start,
      @NonNull Instant end,
      long offset,
      long limit); }
SyncStockRepository { @NonNull public Optional<Stock> findById(@NonNull String symbol, @NonNull Instant date) { BoundStatement bound = findById.bind(symbol, date); ResultSet rs = session.execute(bound); return Optional.ofNullable(rs.one()).map(rowMapper); } SyncStockRepository(
      CqlSession session,
      @Qualifier("stocks.prepared.insert") PreparedStatement insert,
      @Qualifier("stocks.prepared.deleteById") PreparedStatement deleteById,
      @Qualifier("stocks.prepared.findById") PreparedStatement findById,
      @Qualifier("stocks.prepared.findBySymbol") PreparedStatement findBySymbol,
      Function<Row, Stock> rowMapper); @NonNull Stock save(@NonNull Stock stock); void deleteById(@NonNull String symbol, @NonNull Instant date); @NonNull Optional<Stock> findById(@NonNull String symbol, @NonNull Instant date); @NonNull Stream<Stock> findAllBySymbol(
      @NonNull String symbol,
      @NonNull Instant start,
      @NonNull Instant end,
      long offset,
      long limit);  }