@Test void getBodyIsCalledOnce() { final AtomicInteger counter = new AtomicInteger(); final HttpRequest httpRequest = new HttpRequest("foo", "GET", emptyList(), emptyMap(), null, emptyMap(), (a, b) -> { assertEquals(0, counter.getAndIncrement()); return Optional.of(new byte[0]); }, new Object[0], null); assertEquals(0, counter.get()); IntStream.range(0, 3).forEach(idx -> { assertTrue(httpRequest.getBody().isPresent()); assertEquals(1, counter.get()); }); }
public Optional<byte[]> getBody() { if (bodyCache != null) { return bodyCache; } synchronized (this) { if (bodyCache != null) { return bodyCache; } return bodyCache = doGetBody(); } }
HttpRequest { public Optional<byte[]> getBody() { if (bodyCache != null) { return bodyCache; } synchronized (this) { if (bodyCache != null) { return bodyCache; } return bodyCache = doGetBody(); } } }
HttpRequest { public Optional<byte[]> getBody() { if (bodyCache != null) { return bodyCache; } synchronized (this) { if (bodyCache != null) { return bodyCache; } return bodyCache = doGetBody(); } }  }
HttpRequest { public Optional<byte[]> getBody() { if (bodyCache != null) { return bodyCache; } synchronized (this) { if (bodyCache != null) { return bodyCache; } return bodyCache = doGetBody(); } }  Optional<byte[]> getBody(); Configurer.ConfigurerConfiguration getConfigurationOptions(); }
HttpRequest { public Optional<byte[]> getBody() { if (bodyCache != null) { return bodyCache; } synchronized (this) { if (bodyCache != null) { return bodyCache; } return bodyCache = doGetBody(); } }  Optional<byte[]> getBody(); Configurer.ConfigurerConfiguration getConfigurationOptions();  }