@Test void should_build_details_uri_from_request_and_stock_value() { var i = Instant.parse("2019-01-01T12:34:56.789Z"); var input = new Stock("ABC", i, BigDecimal.valueOf(42)); given(converter.convert(i)).willReturn("20190101123456789"); given(request.getScheme()).willReturn("http"); given(request.getServerName()).willReturn("localhost"); given(request.getServerPort()).willReturn(8080); URI actual = stockUriHelper.buildDetailsUri(request, input); assertThat(actual) .hasScheme("http") .hasPort(8080) .hasPath("/api/v1/stocks/ABC/20190101123456789"); }
@NonNull public URI buildDetailsUri(@NonNull HttpServletRequest request, @NonNull Stock stock) { String date = instantStringConverter.convert(stock.getDate()); return ServletUriComponentsBuilder.fromRequestUri(request) .replacePath("/api/v1/stocks/{symbol}/{date}") .buildAndExpand(stock.getSymbol(), date) .toUri(); }
StockUriHelper { @NonNull public URI buildDetailsUri(@NonNull HttpServletRequest request, @NonNull Stock stock) { String date = instantStringConverter.convert(stock.getDate()); return ServletUriComponentsBuilder.fromRequestUri(request) .replacePath("/api/v1/stocks/{symbol}/{date}") .buildAndExpand(stock.getSymbol(), date) .toUri(); } }
StockUriHelper { @NonNull public URI buildDetailsUri(@NonNull HttpServletRequest request, @NonNull Stock stock) { String date = instantStringConverter.convert(stock.getDate()); return ServletUriComponentsBuilder.fromRequestUri(request) .replacePath("/api/v1/stocks/{symbol}/{date}") .buildAndExpand(stock.getSymbol(), date) .toUri(); } StockUriHelper(Converter<Instant, String> instantStringConverter); }
StockUriHelper { @NonNull public URI buildDetailsUri(@NonNull HttpServletRequest request, @NonNull Stock stock) { String date = instantStringConverter.convert(stock.getDate()); return ServletUriComponentsBuilder.fromRequestUri(request) .replacePath("/api/v1/stocks/{symbol}/{date}") .buildAndExpand(stock.getSymbol(), date) .toUri(); } StockUriHelper(Converter<Instant, String> instantStringConverter); @NonNull URI buildDetailsUri(@NonNull HttpServletRequest request, @NonNull Stock stock); }
StockUriHelper { @NonNull public URI buildDetailsUri(@NonNull HttpServletRequest request, @NonNull Stock stock) { String date = instantStringConverter.convert(stock.getDate()); return ServletUriComponentsBuilder.fromRequestUri(request) .replacePath("/api/v1/stocks/{symbol}/{date}") .buildAndExpand(stock.getSymbol(), date) .toUri(); } StockUriHelper(Converter<Instant, String> instantStringConverter); @NonNull URI buildDetailsUri(@NonNull HttpServletRequest request, @NonNull Stock stock);  }