Pool implements IPool { public void onAvailable(final IPoorAction action) { try { if (freeItemsCounter.get() > 0) { action.execute(); return; } this.taskQueue.add(action); } catch (ActionExecuteException e) { throw new RuntimeException("Failed to execute PoorAction", e); } } Pool(final Integer maxItems, final Supplier<Object>  func); Object take(); void put(final Object item); void onAvailable(final IPoorAction action);  }
@Test public void Should_executePoorActionWhenFreeItemsAreExists() throws Exception { Supplier<Object> createFunc = mock(Supplier.class); when(createFunc.get()).thenReturn(new Object()); Pool pool = new Pool(1, createFunc); IPoorAction pAction = mock(IPoorAction.class); pool.onAvailable(pAction); verify(pAction).execute(); }