@Override
    public BlockedNodeAdditionResult addNewBlockedNodes(Collection<BlockedNode> newNodes) {
        checkNotNull(newNodes);

        final Map<String, BlockedNode> newlyAddedNodes = new HashMap<>();
        final Map<String, BlockedNode> mergedNodes = new HashMap<>();
        for (BlockedNode node : newNodes) {
            String nodeId = node.getNodeId();
            AddStatus status = tryAddOrMerge(node);
            switch (status) {
                case ADDED:
                    newlyAddedNodes.put(nodeId, blockedNodes.get(nodeId));
                    break;
                case MERGED:
                    mergedNodes.put(nodeId, blockedNodes.get(nodeId));
                    break;
                case NONE:
                    break;
                default:
                    throw new IllegalStateException(
                            "Add or merge status " + status + " is not supported.");
            }
        }
        return new BlockedNodeAdditionResult(newlyAddedNodes.values(), mergedNodes.values());
    }
@Test
    void testAddNewBlockedNodes() {
        BlockedNode blockedNode1 = new BlockedNode("node1", "cause1", 1L);
        BlockedNode blockedNode2 = new BlockedNode("node2", "cause1", 1L);
        BlockedNode blockedNode3 = new BlockedNode("node3", "cause1", 1L);

        BlocklistTracker blocklistTracker = new DefaultBlocklistTracker();

        blocklistTracker.addNewBlockedNodes(
                Arrays.asList(blockedNode1, blockedNode2, blockedNode3));
        assertThat(blocklistTracker.getAllBlockedNodeIds())
                .containsExactlyInAnyOrder("node1", "node2", "node3");

        // should be added
        BlockedNode blockedNode4 = new BlockedNode("node4", "cause1", 1L);
        // replace blockedNode2, because blockedNode5.endTimestamp > blockedNode2.endTimestamp
        BlockedNode blockedNode5 = new BlockedNode("node2", "cause2", 2L);
        // do nothing because blockedNode6 equals to blockedNode3
        BlockedNode blockedNode6 = new BlockedNode("node3", "cause1", 1L);

        BlockedNodeAdditionResult result =
                blocklistTracker.addNewBlockedNodes(
                        Arrays.asList(blockedNode4, blockedNode5, blockedNode6));

        assertThat(result.getNewlyAddedNodes()).containsExactly(blockedNode4);
        assertThat(result.getMergedNodes()).containsExactly(blockedNode5);
        assertThat(blocklistTracker.getAllBlockedNodes())
                .containsExactlyInAnyOrder(blockedNode1, blockedNode3, blockedNode4, blockedNode5);

        // replace blockedNode3, because blockedNode7.endTimestamp == blockedNode3.endTimestamp and
        // blockedNode7.cause != blockedNode3.cause
        BlockedNode blockedNode7 = new BlockedNode("node3", "cause2", 1L);

        result = blocklistTracker.addNewBlockedNodes(Collections.singletonList(blockedNode7));

        assertThat(result.getNewlyAddedNodes()).isEmpty();
        assertThat(result.getMergedNodes()).containsExactly(blockedNode7);
        assertThat(blocklistTracker.getAllBlockedNodes())
                .containsExactlyInAnyOrder(blockedNode1, blockedNode4, blockedNode5, blockedNode7);
    }