@Test
public void testBackwardsClock() {

    int numIterations = 10000;
    Set<Long> idSet = new HashSet<Long>(numIterations);
    // Time provider which jumps 5ms back in time every 109 calls.
    TimeProvider tp = new TimeProvider() {
            private int counter = 0;
            @Override
            public long getTimeInMillis() {
                if ((counter++ % 109) == 0) {
                    return System.currentTimeMillis() - 5;
                }
                return System.currentTimeMillis();
            }
        };
    IdGenerator idgen = new IdGenerator(0L, tp);
    for (int i = 0; i < numIterations; ++i) {
        assertTrue(idSet.add(idgen.getNextId()));
    }
    assertEquals(numIterations, idSet.size());
}