RandomModel extends AbstractModel<RandomUser> { @Override public boolean register(RandomUser element) { final RngProvider provider = new RngProvider(); element.setRandomGenerator(provider); provider.invalidate(); return true; } RandomModel(RandomGenerator rng); @Override boolean register(RandomUser element); @Override @Nonnull U get(Class<U> clazz); @Override boolean unregister(RandomUser element); @CheckReturnValue static Builder builder(); static final long DEFAULT_SEED; }
@Test public void testMaster() { model.register(new RandomUser() { @Override public void setRandomGenerator(RandomProvider provider) { final RandomGenerator rng = provider.masterInstance(); assertSame(model.masterRandomGenerator, rng); testUnmodifiable(rng); } }); }
@Test public void testNewInstance() { model.register(new RandomUser() { @Override public void setRandomGenerator(RandomProvider provider) { assertNotSame(model.masterRandomGenerator, provider.newInstance()); } }); }
@Test public void testNotUsing() { model.register(new RandomUser() { @Override public void setRandomGenerator(RandomProvider provider) {} }); }
@Test public void testMaxUsage() { model.register(new RandomUser() { @Override public void setRandomGenerator(RandomProvider provider) { provider.getSeed(); boolean fail = false; try { provider.getSeed(); } catch (final IllegalStateException e) { fail = true; } assertTrue(fail); fail = false; try { provider.masterInstance(); } catch (final IllegalStateException e) { fail = true; } assertTrue(fail); fail = false; try { provider.newInstance(); } catch (final IllegalStateException e) { fail = true; } assertTrue(fail); fail = false; try { provider.sharedInstance(Object.class); } catch (final IllegalStateException e) { fail = true; } assertTrue(fail); } }); }