FreshTimestampSupplierAdapter implements LongSupplier { public void setTimestampService(TimestampService timestampService) { Preconditions.checkNotNull(timestampService, "Should not re-set timestamp service in a" + " FreshTimestampSupplierAdapter to null"); this.timestampService = timestampService; }  void setTimestampService(TimestampService timestampService); @Override long getAsLong();  }
@Test public void throwsNullPointerExceptionIfSettingTimestampServiceToNull() { assertThatThrownBy(() -> adapter.setTimestampService(null)).isInstanceOf(NullPointerException.class); }
@Test public void throwsNullPointerExceptionIfResettingTimestampServiceToNull() { TimestampService timestampService = mock(TimestampService.class); adapter.setTimestampService(timestampService); assertThatThrownBy(() -> adapter.setTimestampService(null)).isInstanceOf(NullPointerException.class); verifyNoMoreInteractions(timestampService); }
@Test public void propagatesExceptionsThrownByTimestampService() { TimestampService timestampService = mock(TimestampService.class); when(timestampService.getFreshTimestamp()).thenThrow(new IllegalStateException()); adapter.setTimestampService(timestampService); assertThatThrownBy(adapter::getAsLong).isInstanceOf(IllegalStateException.class); }