@Test
public void testValidateChain() {

    List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 100);
    SyncQueueImpl queue = new SyncQueueImpl(randomChain);
    byte[] nodeId = randomPeerId();
    List<Block> chain = TestUtils.getRandomChain(randomChain.get(randomChain.size() - 1).getHash(),
            100, SyncQueueImpl.MAX_CHAIN_LEN - 100 - 1);
    queue.addHeaders(createHeadersFromBlocks(chain, nodeId));
    List<SyncQueueImpl.HeaderElement> longestChain = queue.getLongestChain();
    // no validator is set
    assertEquals(SyncQueueIfc.ValidatedHeaders.Empty, queue.validateChain(longestChain));
    chain = TestUtils.getRandomChain(chain.get(chain.size() - 1).getHash(),
            SyncQueueImpl.MAX_CHAIN_LEN - 1, SyncQueueImpl.MAX_CHAIN_LEN);
    queue.addHeaders(createHeadersFromBlocks(chain, nodeId));
    chain = TestUtils.getRandomChain(chain.get(chain.size() - 1).getHash(),
            2 * SyncQueueImpl.MAX_CHAIN_LEN - 1, SyncQueueImpl.MAX_CHAIN_LEN);
    // the chain is invalid
    queue.withParentHeaderValidator(RedRule);
    SyncQueueIfc.ValidatedHeaders ret = queue.addHeadersAndValidate(createHeadersFromBlocks(chain, nodeId));
    assertFalse(ret.isValid());
    assertArrayEquals(nodeId, ret.getNodeId());
    // the chain is valid
    queue.withParentHeaderValidator(GreenRule);
    ret = queue.addHeadersAndValidate(createHeadersFromBlocks(chain, nodeId));
    assertEquals(SyncQueueIfc.ValidatedHeaders.Empty, ret);
}