### Question:
IbftValidatorsValidationRule implements AttachedBlockHeaderValidationRule { @Override public boolean validate( final BlockHeader header, final BlockHeader parent, final ProtocolContext context) { try { final ValidatorProvider validatorProvider = context .getConsensusState(IbftContext.class) .getVoteTallyCache() .getVoteTallyAfterBlock(parent); final IbftExtraData ibftExtraData = IbftExtraData.decode(header); final NavigableSet<Address> sortedReportedValidators = new TreeSet<>(ibftExtraData.getValidators()); if (!Iterables.elementsEqual(ibftExtraData.getValidators(), sortedReportedValidators)) { LOGGER.trace( "Validators are not sorted in ascending order. Expected {} but got {}.", sortedReportedValidators, ibftExtraData.getValidators()); return false; } final Collection<Address> storedValidators = validatorProvider.getValidators(); if (!Iterables.elementsEqual(ibftExtraData.getValidators(), storedValidators)) { LOGGER.trace( "Incorrect validators. Expected {} but got {}.", storedValidators, ibftExtraData.getValidators()); return false; } } catch (final RLPException ex) { LOGGER.trace("ExtraData field was unable to be deserialised into an IBFT Struct.", ex); return false; } catch (final IllegalArgumentException ex) { LOGGER.trace("Failed to verify extra data", ex); return false; } return true; }  @Override boolean validate(
      final BlockHeader header, final BlockHeader parent, final ProtocolContext context);  }### Answer:
@Test public void correctlyConstructedHeaderPassesValidation() { final List<Address> validators = Lists.newArrayList( AddressHelpers.ofValue(1), AddressHelpers.ofValue(2), AddressHelpers.ofValue(3)); final ProtocolContext context = new ProtocolContext(null, null, setupContextWithValidators(validators)); final BlockHeader header = HeaderValidationTestHelpers.createProposedBlockHeader(validators, emptyList(), false); assertThat(validatorsValidationRule.validate(header, null, context)).isTrue(); }
@Test public void validatorsInNonAscendingOrderFailValidation() { final List<Address> validators = Lists.newArrayList( AddressHelpers.ofValue(1), AddressHelpers.ofValue(2), AddressHelpers.ofValue(3)); final ProtocolContext context = new ProtocolContext(null, null, setupContextWithValidators(validators)); final BlockHeader header = HeaderValidationTestHelpers.createProposedBlockHeader( Lists.reverse(validators), emptyList(), false); assertThat(validatorsValidationRule.validate(header, null, context)).isFalse(); }
@Test public void mismatchingReportedValidatorsVsLocallyStoredListFailsValidation() { final List<Address> storedValidators = Lists.newArrayList( AddressHelpers.ofValue(1), AddressHelpers.ofValue(2), AddressHelpers.ofValue(3)); final List<Address> reportedValidators = Lists.newArrayList( AddressHelpers.ofValue(2), AddressHelpers.ofValue(3), AddressHelpers.ofValue(4)); final ProtocolContext context = new ProtocolContext(null, null, setupContextWithValidators(storedValidators)); final BlockHeader header = HeaderValidationTestHelpers.createProposedBlockHeader( reportedValidators, emptyList(), false); assertThat(validatorsValidationRule.validate(header, null, context)).isFalse(); }