### Question:
NetworkSamplesGenerator { public NetworkSamples generate(final int totalSampleCount) { Preconditions.checkArgument(dropCount < totalSampleCount, "Cannot drop more samples than requested or all of the samples. Samples requested %s and dropping %s", totalSampleCount, dropCount ); StatusBar statusBar = statusBarSupplier.get(); Map<VariableReference, List<?>> samplesByVariable = new HashMap<>(); List<Double> logOfMasterPForEachSample = new ArrayList<>(); dropSamples(dropCount, statusBar); PercentageComponent statusPercentage = newPercentageComponentAndAddToStatusBar(statusBar); RemainingTimeComponent remainingTimeComponent = new RemainingTimeComponent(totalSampleCount); statusBar.addComponent(remainingTimeComponent); statusBar.setMessage("Sampling..."); int sampleCount = 0; int samplesLeft = totalSampleCount - dropCount; for (int i = 0; i < samplesLeft; i++) { if (i % downSampleInterval == 0) { algorithm.sample(samplesByVariable, logOfMasterPForEachSample); sampleCount++; } else { algorithm.step(); } remainingTimeComponent.step(); statusPercentage.progress((double) (i + 1) / samplesLeft); } statusBar.finish(); return new NetworkSamples(samplesByVariable, logOfMasterPForEachSample, sampleCount); } 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 doesUpdateStatusAndFinishStatusOnGeneration() { AtomicInteger stepCount = new AtomicInteger(0); AtomicInteger sampleCount = new AtomicInteger(0); StatusBar statusBar = mock(StatusBar.class); TestSamplingAlgorithm algorithm = new TestSamplingAlgorithm(stepCount, sampleCount); NetworkSamplesGenerator unitUnderTest = new NetworkSamplesGenerator(algorithm, () -> statusBar); unitUnderTest.generate(10); Mockito.verify(statusBar, times(1)).setMessage(anyString()); Mockito.verify(statusBar).finish(); }
@Test public void doesCreateNewStatusBarOnGenerationFinish() { AtomicInteger stepCount = new AtomicInteger(0); AtomicInteger sampleCount = new AtomicInteger(0); StatusBar statusBar1 = mock(StatusBar.class); StatusBar statusBar2 = mock(StatusBar.class); AtomicInteger statusBarCreationCount = new AtomicInteger(0); TestSamplingAlgorithm algorithm = new TestSamplingAlgorithm(stepCount, sampleCount); NetworkSamplesGenerator unitUnderTest = new NetworkSamplesGenerator(algorithm, () -> { int callNumber = statusBarCreationCount.getAndIncrement(); if (callNumber == 0) { return statusBar1; } else { return statusBar2; } }); unitUnderTest.generate(10); Mockito.verify(statusBar1, times(1)).setMessage(anyString()); Mockito.verify(statusBar1).finish(); unitUnderTest.generate(8); Mockito.verify(statusBar2, times(1)).setMessage(anyString()); Mockito.verify(statusBar2).finish(); }