### Question:
IdGenerator { @NotNull public String next() { long now = System.currentTimeMillis(); while (true) { long lastTime = lastId.get(); if (lastTime >= now) { now = lastTime + 1; } if (lastId.compareAndSet(lastTime, now)) { return String.valueOf(now); } } }  @NotNull String next();  }### Answer:
@Test public void testGenerate() { IdGenerator generator = new IdGenerator(); String lastId = ""; long d = System.currentTimeMillis(); for (int i = 0; i < 10; i++) { String newId = generator.next(); System.out.println(lastId + "/" + newId); Assert.assertNotEquals(lastId, newId); Assert.assertTrue(d <= Long.parseLong(newId)); lastId = newId; } }