TransactionImpl implements Transaction { @Override public int hashCode() { int hash = 7; hash = 47 * hash + (this.id != null ? this.id.hashCode() : 0); return hash; } @Inject  TransactionImpl(TransactionService service, @Assisted boolean isolatedTransaction); String getId(); void commit(); void rollback(); boolean isCompleted(); void addTransactionCompletionListener(TransactionCompletionListener completionListener); void removeTransactionCompletionListener(TransactionCompletionListener completionListener); @Override boolean equals(Object obj); @Override int hashCode(); boolean isIsolatedTransaction();  }
@Test public void testEqualsAndHashCode() { mockery.checking(new Expectations() { { exactly(2).of(service).getNextTransactionId(); will(returnValue("1")); } }); final Injector injector = initializeInjector(); final Transaction tx1 = injector.getInstance(Transaction.class); Assert.assertNotNull(tx1); final Transaction tx2 = injector.getInstance(Transaction.class); Assert.assertNotNull(tx2); Assert.assertEquals(tx1, tx2); Assert.assertEquals(tx1.hashCode(), tx2.hashCode()); mockery.assertIsSatisfied(); }