RandomIdNoLuhnProvider implements SessionIdProvider { @Override public String newId() { final byte[] bytes = new byte[length]; random.nextBytes(bytes); return new String(encode(bytes)); } RandomIdNoLuhnProvider();   RandomIdNoLuhnProvider(int length); @Override String newId(); @Override String readId(String value); @Override void configure(SessionConfiguration configuration);  }
@Test public void testNewId() { RandomIdNoLuhnProvider provider = new RandomIdNoLuhnProvider(); assertEquals(40, provider.newId().length()); assertThat(provider.newId(), RegexMatchers.matchesPattern("[A-Za-z0-9_\\-]{40}")); }
@Test public void testNewIdWith40Characters() { RandomIdNoLuhnProvider provider = new RandomIdNoLuhnProvider(40); assertEquals(56, provider.newId().length()); assertThat(provider.newId(), RegexMatchers.matchesPattern("[A-Za-z0-9_\\-]{56}")); }