MonitorExample { public void demoTryEnterIf() throws InterruptedException { if (monitor.tryEnterIf(conditionGuard)) { try { simulatedWork(); taskDoneCounter++; } finally { monitor.leave(); } } else { taskSkippedCounter.incrementAndGet(); } }  void demoTryEnterIf(); void demoEnterIf(); void demoEnterWhen(); int getStopTaskCount(); void setStopTaskCount(int stopTaskCount); void setCondition(boolean condition); int getTaskSkippedCounter(); int getTaskDoneCounter();  }
@Test public void testDemoTryEnterIf() throws Exception { setUpThreadsForTestingMethod("demoTryEnterIf"); startAllThreadsForTest(); waitForTestThreadsToFinish(); int expectedTaskCount = 1; int expectedSkippedTasks = 9; assertThat(monitorExample.getTaskDoneCounter(), is(expectedTaskCount)); assertThat(monitorExample.getTaskSkippedCounter(), is(expectedSkippedTasks)); }