### Question:
AncestryValidationRule implements DetachedBlockHeaderValidationRule { @Override public boolean validate(final BlockHeader header, final BlockHeader parent) { if (!header.getParentHash().equals(parent.getHash())) { LOG.trace( "Invalid parent block header. Parent hash {} does not match " + "supplied parent header {}.", header.getParentHash(), parent.getHash()); return false; } if (header.getNumber() != (parent.getNumber() + 1)) { LOG.trace( "Invalid block header: number {} is not one more than parent number {}", header.getNumber(), parent.getNumber()); return false; } return true; }  @Override boolean validate(final BlockHeader header, final BlockHeader parent);  }### Answer:
@Test public void incrementingNumberAndLinkedHashesReturnTrue() { final AncestryValidationRule uut = new AncestryValidationRule(); final BlockHeader parentHeader = new BlockHeaderTestFixture().buildHeader(); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); headerBuilder.parentHash(parentHeader.getHash()); headerBuilder.number(parentHeader.getNumber() + 1); final BlockHeader header = headerBuilder.buildHeader(); assertThat(uut.validate(header, parentHeader)).isTrue(); }
@Test public void mismatchedHashesReturnsFalse() { final AncestryValidationRule uut = new AncestryValidationRule(); final BlockHeader parentHeader = new BlockHeaderTestFixture().buildHeader(); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); headerBuilder.parentHash(Hash.EMPTY); headerBuilder.number(parentHeader.getNumber() + 1); final BlockHeader header = headerBuilder.buildHeader(); assertThat(uut.validate(header, parentHeader)).isFalse(); }
@Test public void nonIncrementingBlockNumberReturnsFalse() { final AncestryValidationRule uut = new AncestryValidationRule(); final BlockHeader parentHeader = new BlockHeaderTestFixture().buildHeader(); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); headerBuilder.parentHash(parentHeader.getHash()); headerBuilder.number(parentHeader.getNumber() + 2); final BlockHeader header = headerBuilder.buildHeader(); assertThat(uut.validate(header, parentHeader)).isFalse(); }