### Question:
PooledItemSourceFactory implements ItemSourceFactory { @Override public ItemSource createEmptySource() { try { return bufferedItemSourcePool.getPooled(); } catch (PoolResourceException e) { throw new IllegalStateException(e); } } protected  PooledItemSourceFactory(ItemSourcePool bufferedItemSourcePool); @Override final boolean isBuffered(); @Override ItemSource create(Object source, ObjectWriter objectWriter); @Override ItemSource createEmptySource(); @PluginBuilderFactory static PooledItemSourceFactory.Builder newBuilder(); @Override void start(); @Override void stop(); @Override boolean isStarted(); @Override boolean isStopped(); static final String PLUGIN_NAME; }### Answer:
@Test public void throwsWhenCreateEmptySourceCantGetPooledElement() throws PoolResourceException { ItemSourcePool mockedPool = mock(ItemSourcePool.class); String expectedMessage = UUID.randomUUID().toString(); when(mockedPool.getPooled()).thenThrow(new PoolResourceException(expectedMessage)); PooledItemSourceFactory pooledItemSourceFactory = new PooledItemSourceFactory(mockedPool); expectedException.expect(IllegalStateException.class); expectedException.expectMessage(expectedMessage); pooledItemSourceFactory.createEmptySource(); }
@Test public void createEmptySourceRemovesFromPool() throws PoolResourceException { ItemSourcePool mockedPool = mock(ItemSourcePool.class); PooledItemSourceFactory pooledItemSourceFactory = new PooledItemSourceFactory(mockedPool); pooledItemSourceFactory.createEmptySource(); verify(mockedPool).getPooled(); }