LazyFxControllerAndView implements FxControllerAndView<C, V> { protected FxControllerAndView<C, V> initOrGet() { if (inner == null) { inner = supplier.get(); } return inner; } LazyFxControllerAndView(Supplier<FxControllerAndView<C, V>> supplier); @Override C getController(); @Override Optional<V> getView(); @Override String toString();  }
@Test public void initOrGetCallsSupplierExactlyOnce() throws Exception { Supplier<FxControllerAndView<Object, Node>> supplier = mock(Supplier.class); when(supplier.get()).thenReturn(mock(FxControllerAndView.class)); LazyFxControllerAndView<Object, Node> controllerAndView = new LazyFxControllerAndView<>(supplier); FxControllerAndView<Object, Node> cav1 = controllerAndView.initOrGet(); FxControllerAndView<Object, Node> cav2 = controllerAndView.initOrGet(); assertThat(cav1).isSameAs(cav2); verify(supplier, times(1)).get(); }