### Question:
CliqueBlockScheduler extends DefaultBlockScheduler { @Override @VisibleForTesting public BlockCreationTimeResult getNextTimestamp(final BlockHeader parentHeader) { final BlockCreationTimeResult result = super.getNextTimestamp(parentHeader); final long milliSecondsUntilNextBlock = result.getMillisecondsUntilValid() + calculateTurnBasedDelay(parentHeader); return new BlockCreationTimeResult( result.getTimestampForHeader(), Math.max(0, milliSecondsUntilNextBlock)); } CliqueBlockScheduler(
      final Clock clock,
      final VoteTallyCache voteTallyCache,
      final Address localNodeAddress,
      final long secondsBetweenBlocks); @Override @VisibleForTesting BlockCreationTimeResult getNextTimestamp(final BlockHeader parentHeader);  }### Answer:
@Test public void inturnValidatorWaitsExactlyBlockInterval() { final Clock clock = mock(Clock.class); final long currentSecondsSinceEpoch = 10L; final long secondsBetweenBlocks = 5L; when(clock.millis()).thenReturn(currentSecondsSinceEpoch * 1000); final CliqueBlockScheduler scheduler = new CliqueBlockScheduler(clock, voteTallyCache, localAddr, secondsBetweenBlocks); final BlockHeader parentHeader = blockHeaderBuilder.number(1).timestamp(currentSecondsSinceEpoch).buildHeader(); final BlockCreationTimeResult result = scheduler.getNextTimestamp(parentHeader); assertThat(result.getTimestampForHeader()) .isEqualTo(currentSecondsSinceEpoch + secondsBetweenBlocks); assertThat(result.getMillisecondsUntilValid()).isEqualTo(secondsBetweenBlocks * 1000); }
@Test public void outOfturnValidatorWaitsLongerThanBlockInterval() { final Clock clock = mock(Clock.class); final long currentSecondsSinceEpoch = 10L; final long secondsBetweenBlocks = 5L; when(clock.millis()).thenReturn(currentSecondsSinceEpoch * 1000); final CliqueBlockScheduler scheduler = new CliqueBlockScheduler(clock, voteTallyCache, localAddr, secondsBetweenBlocks); final BlockHeader parentHeader = blockHeaderBuilder.number(2).timestamp(currentSecondsSinceEpoch).buildHeader(); final BlockCreationTimeResult result = scheduler.getNextTimestamp(parentHeader); assertThat(result.getTimestampForHeader()) .isEqualTo(currentSecondsSinceEpoch + secondsBetweenBlocks); assertThat(result.getMillisecondsUntilValid()).isGreaterThan(secondsBetweenBlocks * 1000); }
@Test public void inTurnValidatorCreatesBlockNowIFParentTimestampSufficientlyBehindNow() { final Clock clock = mock(Clock.class); final long currentSecondsSinceEpoch = 10L; final long secondsBetweenBlocks = 5L; when(clock.millis()).thenReturn(currentSecondsSinceEpoch * 1000); final CliqueBlockScheduler scheduler = new CliqueBlockScheduler(clock, voteTallyCache, localAddr, secondsBetweenBlocks); final BlockHeader parentHeader = blockHeaderBuilder .number(1) .timestamp(currentSecondsSinceEpoch - secondsBetweenBlocks) .buildHeader(); final BlockCreationTimeResult result = scheduler.getNextTimestamp(parentHeader); assertThat(result.getTimestampForHeader()).isEqualTo(currentSecondsSinceEpoch); assertThat(result.getMillisecondsUntilValid()).isEqualTo(0); }