ThreadSafetyChecker { public void checkCurrentThread() { Thread currentThread = Thread.currentThread(); if (currentThread == lastThread) { return; } lastThread = currentThread; fullCheck(currentThread); }  void checkCurrentThread();  }
@Test public void is_silent_when_called_from_just_one_thread() throws Throwable { runInNewThread("T1", () -> { checker.checkCurrentThread(); checker.checkCurrentThread(); }); }
@Test public void fails_at_most_once_per_thread() throws Throwable { runInNewThread("T1", checker::checkCurrentThread); try { checker.checkCurrentThread(); } catch (AssertionError e) { } checker.checkCurrentThread(); }