### Question:
ProcessMergingObserver { public synchronized void update(AbbyyProcess finishedSubProcess) { finishedSubProcess.setFinished(); for (AbbyyProcess sub : subProcesses) { boolean currentFinished = sub.hasFinished(); if (!currentFinished) { return; } } for (AbbyyProcess sub : subProcesses) { if(sub.hasFailed()) { logger.error("Could not merge process: " + parentProcess.getName()); throw new IllegalStateException("Subprocess failed: " + sub.getName()); } } fileAccess = beanProvider.getFileAccess(); mergeAllFormats(); }  void setParentProcess(AbbyyProcess process); void addSubProcess(AbbyyProcess subProcess); synchronized void update(AbbyyProcess finishedSubProcess);  }### Answer:
@Test public void shouldDoNothingWhenAllSubprocessesNotFinished() { when(subProcessMock1.hasFinished()).thenReturn(false); when(subProcessMock2.hasFinished()).thenReturn(false); observerSut.update(subProcessMock2); verifyZeroInteractions(parentProcessMock, mergerMock, fileAccessMock); }
@Test public void shouldDoNothingWhenOneSubprocessNotFinished() { when(subProcessMock1.hasFinished()).thenReturn(false); when(subProcessMock2.hasFinished()).thenReturn(true); observerSut.update(subProcessMock2); verifyZeroInteractions(parentProcessMock, mergerMock, fileAccessMock); }
@Test(expected=IllegalStateException.class) public void shouldBreakUpWhenOneFails() { when(subProcessMock1.hasFailed()).thenReturn(true); observerSut.update(subProcessMock1); }
@SuppressWarnings("unchecked") @Test public void shouldMergeIntoOneAndDeleteTheParts() throws URISyntaxException, IOException { Set<OcrFormat> formats = new HashSet<OcrFormat>(); formats.add(OcrFormat.TXT); when(parentProcessMock.getAllOutputFormats()).thenReturn(formats); when(subProcessMock1.getOutputUriForFormat(OcrFormat.TXT)).thenReturn(new URI("file:/part1.txt")); when(subProcessMock2.getOutputUriForFormat(OcrFormat.TXT)).thenReturn(new URI("file:/part2.txt")); when(parentProcessMock.getOutputUriForFormat(OcrFormat.TXT)).thenReturn(new URI("file:/result.txt")); observerSut.update(subProcessMock2); verify(mergerMock).mergeBuffered(any(List.class), any(OutputStream.class)); verify(fileAccessMock).deleteFile(new File("/part1.txt")); verify(fileAccessMock).deleteFile(new File("/part2.txt")); }