### Question:
ConstantFieldValidationRule implements DetachedBlockHeaderValidationRule { @Override public boolean validate(final BlockHeader header, final BlockHeader parent) { final T actualValue = accessor.apply(header); if (!actualValue.equals(expectedValue)) { LOG.trace( "{} failed validation. Actual != Expected ({} != {}).", fieldName, actualValue, expectedValue); return false; } return true; } ConstantFieldValidationRule(
      final String fieldName, final Function<BlockHeader, T> accessor, final T expectedValue); @Override boolean validate(final BlockHeader header, final BlockHeader parent);  }### Answer:
@Test public void ommersFieldValidatesCorrectly() { final ConstantFieldValidationRule<Hash> uut = new ConstantFieldValidationRule<>( "OmmersHash", BlockHeader::getOmmersHash, Hash.EMPTY_LIST_HASH); final BlockHeaderTestFixture blockHeaderBuilder = new BlockHeaderTestFixture(); blockHeaderBuilder.ommersHash(Hash.EMPTY_LIST_HASH); BlockHeader header = blockHeaderBuilder.buildHeader(); assertThat(uut.validate(header, null)).isTrue(); blockHeaderBuilder.ommersHash(Hash.ZERO); header = blockHeaderBuilder.buildHeader(); assertThat(uut.validate(header, null)).isFalse(); }
@Test public void difficultyFieldIsValidatedCorrectly() { final ConstantFieldValidationRule<Difficulty> uut = new ConstantFieldValidationRule<>("Difficulty", BlockHeader::getDifficulty, Difficulty.ONE); final BlockHeaderTestFixture blockHeaderBuilder = new BlockHeaderTestFixture(); blockHeaderBuilder.difficulty(Difficulty.ONE); BlockHeader header = blockHeaderBuilder.buildHeader(); assertThat(uut.validate(header, null)).isTrue(); blockHeaderBuilder.difficulty(Difficulty.ZERO); header = blockHeaderBuilder.buildHeader(); assertThat(uut.validate(header, null)).isFalse(); }