### Question:
Jar { public boolean takeBean() { var success = false; try { lock.acquire(); success = beans > 0; if (success) { beans = beans - 1; } } catch (Exception e) { e.printStackTrace(); } finally { lock.release(); } return success; } Jar(int beans, Lock lock); boolean takeBean();  }### Answer:
@Test public void testTakeBeans() { var mutex = new Mutex(); var jar = new Jar(10, mutex); IntStream.range(0, 10).mapToObj(i -> jar.takeBean()).forEach(Assertions::assertTrue); assertFalse(jar.takeBean()); }