OptionalService { static <T> OptionalService<T> unavailable(String reason) { return new AbsentOptionalService<T>(reason); }  abstract Availability getAvailability(); abstract @Nullable T getService();  }
@Test public void testUnavailable() { OptionalService<Object> optionalService = OptionalService.unavailable("abc"); assertThat(optionalService.getAvailability().getAvailable()).isFalse(); assertThat(optionalService.getAvailability().getReason()).isEqualTo("abc"); }