### Question:
Sampler { public boolean select() { return rand.nextDouble() < threshold; } Sampler(float selectPercent);  Sampler(float selectPercent, Random rand); boolean select();  }### Answer:
@Test public void testThresholdWorks() { for (int i = 0; i <= 100; i++) { expect(random.nextDouble()).andReturn(0.01 * i); } control.replay(); Sampler sampler = new Sampler(25, random); for (int i = 0; i <= 100; i++) { assertThat(sampler.select(), is(i < 25)); } }