IdGenerators { public static IdGenerator decrementingLongs() { AtomicLong longs = new AtomicLong(); return () -> Long.toString(longs.decrementAndGet()); }  static IdGenerator incrementingLongs(); static IdGenerator decrementingLongs();  }
@Test public void decrementing() { IdGenerator gen = IdGenerators.decrementingLongs(); assertThat(gen.getId(), equalTo("-1")); assertThat(gen.getId(), equalTo("-2")); }
@Test public void decrementingIndependent() { IdGenerator gen = IdGenerators.decrementingLongs(); IdGenerator otherGen = IdGenerators.decrementingLongs(); assertThat(gen.getId(), equalTo("-1")); assertThat(gen.getId(), equalTo("-2")); assertThat(otherGen.getId(), equalTo("-1")); }