### Question:
Inventory { public boolean addItem(Item item) { if (items.size() < inventorySize) { lock.lock(); try { if (items.size() < inventorySize) { items.add(item); var thread = Thread.currentThread(); LOGGER.info("{}: items.size()={}, inventorySize={}", thread, items.size(), inventorySize); return true; } } finally { lock.unlock(); } } return false; } Inventory(int inventorySize); boolean addItem(Item item); final List<Item> getItems();  }### Answer:
@Test public void testAddItem() throws Exception { assertTimeout(ofMillis(10000), () -> { final var inventory = new Inventory(INVENTORY_SIZE); final var executorService = Executors.newFixedThreadPool(THREAD_COUNT); IntStream.range(0, THREAD_COUNT).<Runnable>mapToObj(i -> () -> { while (inventory.addItem(new Item())) ; }).forEach(executorService::execute); executorService.shutdown(); executorService.awaitTermination(5, TimeUnit.SECONDS); final var items = inventory.getItems(); assertNotNull(items); assertEquals(INVENTORY_SIZE, items.size()); assertEquals(INVENTORY_SIZE, appender.getLogSize()); IntStream.range(0, items.size()) .mapToObj(i -> appender.log.get(i).getFormattedMessage() .contains("items.size()=" + (i + 1))) .forEach(Assertions::assertTrue); }); }