### Question:
TxPoolModuleImpl implements TxPoolModule { @Override public String status() { Map<String, JsonNode> txProps = new HashMap<>(); txProps.put(PENDING, jsonNodeFactory.numberNode(transactionPool.getPendingTransactions().size())); txProps.put(QUEUED, jsonNodeFactory.numberNode(transactionPool.getQueuedTransactions().size())); JsonNode node = jsonNodeFactory.objectNode().setAll(txProps); return node.toString(); } @Autowired  TxPoolModuleImpl(TransactionPool transactionPool); @Override String content(); @Override String inspect(); @Override String status(); static final String PENDING; static final String QUEUED; }### Answer:
@Test public void txpool_status_basic() throws IOException { String result = txPoolModule.status(); ObjectMapper om = new ObjectMapper(); JsonNode node = om.reader().forType(JsonNode.class).readValue(result); checkFieldIsNumber(node,"pending"); checkFieldIsNumber(node,"queued"); }
@Test public void txpool_status_oneTx() throws Exception { Transaction tx = createSampleTransaction(); when(transactionPool.getPendingTransactions()).thenReturn(Collections.singletonList(tx)); String result = txPoolModule.status(); ObjectMapper om = new ObjectMapper(); JsonNode node = om.reader().forType(JsonNode.class).readValue(result); JsonNode queuedNode = checkFieldIsNumber(node, "queued"); JsonNode pendingNode = checkFieldIsNumber(node, "pending"); Assert.assertEquals(0, queuedNode.asInt()); Assert.assertEquals(1, pendingNode.asInt()); }
@Test public void txpool_status_manyPending() throws Exception { Transaction tx1 = createSampleTransaction(); Transaction tx2 = createSampleTransaction(); Transaction tx3 = createSampleTransaction(); List<Transaction> transactions = Arrays.asList(tx1, tx2, tx3); when(transactionPool.getPendingTransactions()).thenReturn(transactions); String result = txPoolModule.status(); ObjectMapper om = new ObjectMapper(); JsonNode node = om.reader().forType(JsonNode.class).readValue(result); JsonNode queuedNode = checkFieldIsNumber(node, "queued"); JsonNode pendingNode = checkFieldIsNumber(node, "pending"); Assert.assertEquals(0, queuedNode.asInt()); Assert.assertEquals(transactions.size(), pendingNode.asInt()); }
@Test public void txpool_status_manyTxs() throws Exception { Transaction tx1 = createSampleTransaction(); Transaction tx2 = createSampleTransaction(); Transaction tx3 = createSampleTransaction(); Transaction tx4 = createSampleTransaction(); List<Transaction> transactions = Arrays.asList(tx1, tx2, tx3); List<Transaction> txs = Arrays.asList(tx1, tx4); when(transactionPool.getPendingTransactions()).thenReturn(transactions); when(transactionPool.getQueuedTransactions()).thenReturn(txs); String result = txPoolModule.status(); ObjectMapper om = new ObjectMapper(); JsonNode node = om.reader().forType(JsonNode.class).readValue(result); JsonNode queuedNode = checkFieldIsNumber(node, "queued"); JsonNode pendingNode = checkFieldIsNumber(node, "pending"); Assert.assertEquals(txs.size(), queuedNode.asInt()); Assert.assertEquals(transactions.size(), pendingNode.asInt()); }