### Question:
NodeMessageHandler implements MessageHandler, Runnable { private void processTransactionsMessage(@Nonnull final MessageChannel sender, @Nonnull final TransactionsMessage message) { long start = System.nanoTime(); loggerMessageProcess.debug("Tx message about to be process: {}", message.getMessageContentInfo()); List<Transaction> messageTxs = message.getTransactions(); Metrics.processTxsMessage("start", messageTxs, sender.getPeerNodeID()); List<Transaction> txs = new LinkedList(); for (Transaction tx : messageTxs) { if (!tx.acceptTransactionSignature(config.getBlockchainConfig().getCommonConstants().getChainId())) { recordEvent(sender, EventType.INVALID_TRANSACTION); } else { txs.add(tx); recordEvent(sender, EventType.VALID_TRANSACTION); } } List<Transaction> acceptedTxs = transactionGateway.receiveTransactionsFrom(txs, sender.getPeerNodeID()); Metrics.processTxsMessage("validTxsAddedToTransactionPool", acceptedTxs, sender.getPeerNodeID()); Metrics.processTxsMessage("finish", acceptedTxs, sender.getPeerNodeID()); loggerMessageProcess.debug("Tx message process finished after [{}] nano.", System.nanoTime() - start); } @Autowired  NodeMessageHandler(UscSystemProperties config,
                              @Nonnull final BlockProcessor blockProcessor,
                              final SyncProcessor syncProcessor,
                              @Nullable final ChannelManager channelManager,
                              @Nullable final TransactionGateway transactionGateway,
                              @Nullable final PeerScoringManager peerScoringManager,
                              @Nonnull BlockValidationRule blockValidationRule); synchronized void processMessage(final MessageChannel sender, @Nonnull final Message message); @Override void postMessage(MessageChannel sender, Message message); @Override void start(); @Override void stop(); @Override long getMessageQueueSize(); @Override void run(); synchronized Block getBestBlock(); synchronized BlockDifficulty getTotalDifficulty(); @VisibleForTesting BlockProcessor getBlockProcessor(); static final int MAX_NUMBER_OF_MESSAGES_CACHED; static final long RECEIVED_MESSAGES_CACHE_DURATION; }### Answer:
@Test public void processTransactionsMessage() throws UnknownHostException { PeerScoringManager scoring = createPeerScoringManager(); TransactionGateway transactionGateway = mock(TransactionGateway.class); BlockProcessor blockProcessor = mock(BlockProcessor.class); Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false); final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, null, transactionGateway, scoring, new ProofOfWorkRule(config).setFallbackMiningEnabled(false)); final SimpleMessageChannel sender = new SimpleMessageChannel(); sender.setPeerNodeID(new NodeID(new byte[] {1})); final SimpleMessageChannel sender2 = new SimpleMessageChannel(); sender2.setPeerNodeID(new NodeID(new byte[] {2})); final List<Transaction> txs = TransactionUtils.getTransactions(10); final TransactionsMessage message = new TransactionsMessage(txs); handler.processMessage(sender, message); Mockito.verify(transactionGateway, times(1)).receiveTransactionsFrom(txs, sender.getPeerNodeID()); handler.processMessage(sender2, message); Mockito.verify(transactionGateway, times(1)).receiveTransactionsFrom(txs, sender2.getPeerNodeID()); Assert.assertFalse(scoring.isEmpty()); PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID()); Assert.assertNotNull(pscoring); Assert.assertFalse(pscoring.isEmpty()); Assert.assertEquals(10, pscoring.getTotalEventCounter()); Assert.assertEquals(10, pscoring.getEventCounter(EventType.VALID_TRANSACTION)); pscoring = scoring.getPeerScoring(sender2.getPeerNodeID()); Assert.assertNotNull(pscoring); Assert.assertFalse(pscoring.isEmpty()); Assert.assertEquals(10, pscoring.getTotalEventCounter()); Assert.assertEquals(10, pscoring.getEventCounter(EventType.VALID_TRANSACTION)); }