public class TestCachingHTableFactory {
@Test
public void testCacheCorrectlyExpiresTable() throws Exception {
// setup the mocks for the tables we will request
HTableFactory delegate = Mockito.mock(HTableFactory.class);
ImmutableBytesPtr t1 = new ImmutableBytesPtr(Bytes.toBytes("t1"));
ImmutableBytesPtr t2 = new ImmutableBytesPtr(Bytes.toBytes("t2"));
ImmutableBytesPtr t3 = new ImmutableBytesPtr(Bytes.toBytes("t3"));
HTableInterface table1 = Mockito.mock(HTableInterface.class);
HTableInterface table2 = Mockito.mock(HTableInterface.class);
HTableInterface table3 = Mockito.mock(HTableInterface.class);
Mockito.when(delegate.getTable(t1)).thenReturn(table1);
Mockito.when(delegate.getTable(t2)).thenReturn(table2);
Mockito.when(delegate.getTable(t3)).thenReturn(table3);
// setup our factory with a cache size of 2
CachingHTableFactory factory = new CachingHTableFactory(delegate, 2);
factory.getTable(t1);
factory.getTable(t2);