### Question:
TxConfidenceTable { public TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer) { TransactionConfidence confidence; boolean fresh = false; lock.lock(); try { cleanTable(); confidence = getOrCreate(hash); fresh = confidence.markBroadcastBy(byPeer); } finally { lock.unlock(); } if (fresh) confidence.queueListeners(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS); return confidence; } TxConfidenceTable(final int size);   TxConfidenceTable(final int size, TransactionConfidence.Factory confidenceFactory);  TxConfidenceTable(); int numBroadcastPeers(Sha256Hash txHash); TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer); TransactionConfidence getOrCreate(Sha256Hash hash); @Nullable TransactionConfidence get(Sha256Hash hash); static final int MAX_SIZE; }### Answer:
@Test public void events() throws Exception { final TransactionConfidence.Listener.ChangeReason[] run = new TransactionConfidence.Listener.ChangeReason[1]; tx1.getConfidence().addEventListener(Threading.SAME_THREAD, new TransactionConfidence.Listener() { @Override public void onConfidenceChanged(TransactionConfidence confidence, ChangeReason reason) { run[0] = reason; } }); table.seen(tx1.getTxId(), address1); assertEquals(TransactionConfidence.Listener.ChangeReason.SEEN_PEERS, run[0]); run[0] = null; table.seen(tx1.getTxId(), address1); assertNull(run[0]); }
@Test public void testSeen() { PeerAddress peer = createMock(PeerAddress.class); Sha256Hash brokenHash = createMock(Sha256Hash.class); Sha256Hash correctHash = createMock(Sha256Hash.class); TransactionConfidence brokenConfidence = createMock(TransactionConfidence.class); expect(brokenConfidence.getTransactionHash()).andReturn(brokenHash); expect(brokenConfidence.markBroadcastBy(peer)).andThrow(new ArithmeticException("some error")); TransactionConfidence correctConfidence = createMock(TransactionConfidence.class); expect(correctConfidence.getTransactionHash()).andReturn(correctHash); expect(correctConfidence.markBroadcastBy(peer)).andReturn(true); correctConfidence.queueListeners(anyObject(TransactionConfidence.Listener.ChangeReason.class)); expectLastCall(); TransactionConfidence.Factory factory = createMock(TransactionConfidence.Factory.class); expect(factory.createConfidence(brokenHash)).andReturn(brokenConfidence); expect(factory.createConfidence(correctHash)).andReturn(correctConfidence); replay(factory, brokenConfidence, correctConfidence); TxConfidenceTable table = new TxConfidenceTable(1, factory); try { table.seen(brokenHash, peer); } catch (ArithmeticException expected) { } assertNotNull(table.seen(correctHash, peer)); }