ObjectPool { public T getObject() { synchronized (pool) { if (pool.size() > 0) { return pool.remove(pool.size()-1); } } return factory.create(); } ObjectPool(ObjectFactory<T> factory, int poolSize); T getObject(); void recycle(T object);  }
@Test public void testGetsObject() throws Exception { ObjectFactory<MirageRequest> factory = Mockito.mock(ObjectFactory.class); Mockito.when(factory.create()).thenReturn(Mockito.mock(MirageRequest.class)); ObjectPool<MirageRequest> pool = new ObjectPool<>(factory, 3); Assert.assertNotNull(pool.getObject()); }