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