TimeoutChecker { public boolean check(final T current) { final long nowNanos = System.nanoTime(); if (current != pending) { pending = current; timestamp = nowNanos; return false; } return nowNanos - timestamp > timeoutNanos; } TimeoutChecker(final TimeUnit unit, final long timeout); boolean check(final T current); static TimeoutChecker<T> create(final TimeUnit unit, final long timeout);  }
@Test public void testTimeout() throws Exception { assertFalse(sut.check("foo")); assertFalse(sut.check("foo")); Thread.sleep(200); assertTrue(sut.check("foo")); }
@Test public void testNullNoTimeout() throws Exception { assertFalse(sut.check("foo")); assertFalse(sut.check(null)); }
@Test public void testNewTaskNoTimeout() throws Exception { assertFalse(sut.check("foo")); Thread.sleep(200); assertFalse(sut.check("bar")); Thread.sleep(200); assertFalse(sut.check("baz")); }