CommonTxDao implements CommonDao<T, String> { public Set<T> getByIds(List<String> ids) { LinkedHashSet<T> set = new LinkedHashSet<T>(); if (ids != null) { for (String id : ids) { T dto = this.getById(id); set.add(dto); } } return set; } @Inject  CommonTxDao(@Transactionable CommonReadDao<T, String> readDao,
                     @Transactionable CommonWriteDao<T> writeDao, TransactionService txService,
                     TransactionManager txManager, TransactionInMemoryCache memCache, Class<T> entityClass); Set<T> getByIds(List<String> ids); T getById(String id); T getSingle(QueryParameter... query); T getSingle(List<QueryParameter> query); Set<T> getAll(); List<T> getList(List<QueryParameter> query); OtherTemplate getOther(List<QueryParameter> query); List<OtherTemplate> getOtherList(List<QueryParameter> query); List<T> getList(QueryParameter... query); OtherTemplate getOther(QueryParameter... query); List<OtherTemplate> getOtherList(QueryParameter... query); void save(T... states); void update(T... states); void delete(T... states);  }
@Test public void testGetByIdsWithTransactionIsolation() { mockery.checking(new Expectations() { { exactly(6).of(txManager).getCurrentTransaction(); Transaction tx = mockery.mock(Transaction.class); will(returnValue(tx)); exactly(3).of(tx).isIsolatedTransaction(); will(returnValue(false)); for (DemoDomain domain : TEST_DOMAINS) { exactly(1).of(memCache).getValueForNonIsolatedTransaction(DemoDomain.class.getName(), domain.getId()); TransactionStoreKey key = mockery.mock(TransactionStoreKey.class, "tsk-" + domain.getId()); TransactionStoreValue val = mockery.mock(TransactionStoreValue.class, "tsv-" + domain.getId()); Pair<TransactionStoreKey, TransactionStoreValue> pair = new Pair<TransactionStoreKey, TransactionStoreValue>( key, val); will(returnValue(pair)); exactly(2).of(val).getOpState(); will(returnValue(OpState.UPDATE)); exactly(1).of(val).getCurrentState(); will(returnValue(domain)); } } }); Set<DemoDomain> domains = this.services.readDao.getByIds(Arrays.asList("1", "2", "3")); Assert.assertEquals(TEST_DOMAINS, new ArrayList(domains)); mockery.assertIsSatisfied(); }