### Question:
NetworkSamplesGenerator { public Stream<NetworkSample> stream() { StatusBar statusBar = statusBarSupplier.get(); dropSamples(dropCount, statusBar); final AtomicInteger sampleNumber = new AtomicInteger(0); return Stream.generate(() -> { sampleNumber.getAndIncrement(); for (int i = 0; i < downSampleInterval - 1; i++) { algorithm.step(); } NetworkSample sample = algorithm.sample(); statusBar.setMessage(String.format("Sample #%,d completed", sampleNumber.get())); return sample; }).onClose(statusBar::finish); } NetworkSamplesGenerator(SamplingAlgorithm algorithm, Supplier<StatusBar> statusBarSupplier); int getDropCount(); NetworkSamplesGenerator dropCount(int dropCount); int getDownSampleInterval(); NetworkSamplesGenerator downSampleInterval(int downSampleInterval); NetworkSamples generate(final int totalSampleCount); Stream<NetworkSample> stream();  }### Answer:
@Test public void doesUpdateProgressAndFinishProgressWhenStreaming() { StatusBar progressBar = mock(StatusBar.class); TestSamplingAlgorithm algorithm = new TestSamplingAlgorithm(new AtomicInteger(0), new AtomicInteger(0)); Stream<NetworkSample> sampleStream = new NetworkSamplesGenerator(algorithm, () -> progressBar).stream(); sampleStream.limit(10).count(); sampleStream.close(); Mockito.verify(progressBar, times(10)).setMessage(anyString()); Mockito.verify(progressBar).finish(); }