### Question:
OverwriteDialogController { @EventListener(priority = Integer.MIN_VALUE) public void request(TaskExecutionRequestEvent event) { AbstractParameters params = event.getParameters(); try { if (params.getExistingOutputPolicy() != ExistingOutputPolicy.OVERWRITE) { event.getParameters().getOutput().accept(new TaskOutputDispatcher() { @Override public void dispatch(FileOrDirectoryTaskOutput output) { onDirectory(params, output.getDestination()); } @Override public void dispatch(DirectoryTaskOutput output) { onDirectory(params, output.getDestination()); } @Override public void dispatch(FileTaskOutput output) { onFile(params, output.getDestination()); } }); } } catch (TaskOutputVisitException e) { LOG.warn("Unable to show overwrite confirmation dialog", e); } } @Inject  OverwriteDialogController(Provider<OverwriteConfirmationDialog> dialog); @EventListener(priority = Integer.MIN_VALUE) void request(TaskExecutionRequestEvent event);  }### Answer:
@Test public void isOverwrite() throws TaskOutputVisitException { MergeParameters parameters = new MergeParameters(); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); FileTaskOutput output = mock(FileTaskOutput.class); parameters.setOutput(output); injector.instance(OverwriteDialogController.class).request(new TaskExecutionRequestEvent("id", parameters)); verify(output, never()).accept(any()); }
@Test public void fileDoesntExists() { MergeParameters parameters = new MergeParameters(); parameters.setExistingOutputPolicy(ExistingOutputPolicy.FAIL); FileTaskOutput output = mock(FileTaskOutput.class); File file = mock(File.class); when(file.exists()).thenReturn(Boolean.FALSE); when(output.getDestination()).thenReturn(file); parameters.setOutput(output); injector.instance(OverwriteDialogController.class).request(new TaskExecutionRequestEvent("id", parameters)); OverwriteConfirmationDialog dialog = injector.instance(OverwriteConfirmationDialog.class); verify(dialog, never()).title(anyString()); verify(dialog, never()).messageContent(anyString()); verify(dialog, never()).messageTitle(anyString()); verify(dialog, never()).response(); }
@Test public void directoryIsEmpty() { SimpleSplitParameters parameters = new SimpleSplitParameters(PredefinedSetOfPages.ALL_PAGES); parameters.setExistingOutputPolicy(ExistingOutputPolicy.FAIL); FileOrDirectoryTaskOutput output = mock(FileOrDirectoryTaskOutput.class); File file = mock(File.class); when(file.listFiles()).thenReturn(new File[0]); when(output.getDestination()).thenReturn(file); parameters.setOutput(output); injector.instance(OverwriteDialogController.class).request(new TaskExecutionRequestEvent("id", parameters)); OverwriteConfirmationDialog dialog = injector.instance(OverwriteConfirmationDialog.class); verify(dialog, never()).title(anyString()); verify(dialog, never()).messageContent(anyString()); verify(dialog, never()).messageTitle(anyString()); verify(dialog, never()).response(); }