ConnectionPartition implements Serializable { protected int getCreatedConnections() { try{ this.statsLock.readLock().lock(); return this.createdConnections; } finally { this.statsLock.readLock().unlock(); } } ConnectionPartition(BoneCP pool); int getRemainingCapacity(); @Override String toString();  }
@Test public void testGetCreatedConnections() throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{ ReentrantReadWriteLock mockLock = createNiceMock(ReentrantReadWriteLock.class); ReadLock mockReadLock = createNiceMock(ReadLock.class); Field field = testClass.getClass().getDeclaredField("statsLock"); field.setAccessible(true); ReentrantReadWriteLock oldLock = (ReentrantReadWriteLock) field.get(testClass); field.set(testClass, mockLock); expect(mockLock.readLock()).andThrow(new RuntimeException()).once().andReturn(mockReadLock).once(); mockReadLock.lock(); expectLastCall().once(); replay(mockLock, mockReadLock); try{ testClass.getCreatedConnections(); fail("Should have thrown an exception"); } catch (Throwable t){ } verify(mockLock); field.set(testClass, oldLock); }