### Question:
NodeTable { public synchronized Node addNode(Node n) { NodeEntry e = new NodeEntry(node.getId(), n); if (nodes.contains(e)) { nodes.forEach(nodeEntry -> { if (nodeEntry.equals(e)) { nodeEntry.touch(); } }); return null; } NodeEntry lastSeen = buckets[getBucketId(e)].addNode(e); if (lastSeen != null) { return lastSeen.getNode(); } if (!nodes.contains(e)) { nodes.add(e); } return null; } NodeTable(Node n); Node getNode(); final void initialize(); synchronized Node addNode(Node n); synchronized void dropNode(Node n); synchronized boolean contains(Node n); synchronized void touchNode(Node n); int getBucketsCount(); synchronized NodeBucket[] getBuckets(); int getBucketId(NodeEntry e); synchronized int getNodesCount(); synchronized List<NodeEntry> getAllNodes(); synchronized List<Node> getClosestNodes(byte[] targetId);  }### Answer:
@Test public void addNodeTest() { Node node = new Node(ids.get(0), ips[0], 18888, 18888); Assert.assertEquals(0, nodeTable.getNodesCount()); nodeTable.addNode(node); Assert.assertEquals(1, nodeTable.getNodesCount()); Assert.assertTrue(nodeTable.contains(node)); }
@Test public void addNode_bucketFullTest() throws Exception { for (int i = 0; i < KademliaOptions.BUCKET_SIZE; i++) { TimeUnit.MILLISECONDS.sleep(10); addNode(new Node(ids.get(i), ips[i], 18888, 18888)); } Node lastSeen = nodeTable.addNode(new Node(ids.get(16), ips[16], 18888, 18888)); Assert.assertTrue(null != lastSeen); Assert.assertEquals(ips[15], lastSeen.getHost()); }