source: class InventoryTest {
  
    private InMemoryAppender appender;
    private static final int THREAD_COUNT;
    private static final int INVENTORY_SIZE;
  
    @Test(timeout = 10000)
    public void testAddItem() throws Exception {
  
target:     // Create a new inventory with a limit of 1000 items and put some load on the add method
      final Inventory inventory = new Inventory(INVENTORY_SIZE);
      final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT);
      for (int i = 0; i < THREAD_COUNT; i++) {
        executorService.execute(() -> {
          while (inventory.addItem(new Item())) {};
        });
      }
  
      // Wait until all threads have finished
      executorService.shutdown();
      executorService.awaitTermination(5, TimeUnit.SECONDS);
  
      // Check the number of items in the inventory. It should not have exceeded the allowed maximum
      final List<Item> items = inventory.getItems();
      assertNotNull(items);
      assertEquals(INVENTORY_SIZE, items.size());
  
      assertEquals(INVENTORY_SIZE, appender.getLogSize());
  
      // ... and check if the inventory size is increasing continuously
      for (int i = 0; i < items.size(); i++) {
        assertTrue(appender.log.get(i).getFormattedMessage().contains("items.size()=" + (i + 1)));
      }
    }
  
  }