### Question:
BrowsableOutputDirectoryField extends BrowsableDirectoryField implements TaskParametersBuildStep<MultipleOutputTaskParametersBuilder<?>> { @Override public void apply(MultipleOutputTaskParametersBuilder<? extends SingleOrMultipleOutputTaskParameters> builder, Consumer<String> onError) { getTextField().validate(); if (getTextField().getValidationState() == ValidationState.VALID) { Path output = Paths.get(getTextField().getText()); if (!Files.exists(output)) { eventStudio().broadcast(new NonExistingOutputDirectoryEvent(output)); } if (Files.isDirectory(output)) { builder.output(directory(output.toFile())); } else { onError.accept(DefaultI18nContext.getInstance().i18n("An existing output directory is required")); } } else { onError.accept(DefaultI18nContext.getInstance().i18n("The output directory is required")); } } BrowsableOutputDirectoryField(); @Override void apply(MultipleOutputTaskParametersBuilder<? extends SingleOrMultipleOutputTaskParameters> builder,
            Consumer<String> onError);  }### Answer:
@Test public void valid() throws IOException { BrowsableOutputDirectoryField victim = new BrowsableOutputDirectoryField(); File value = folder.newFolder(); victim.getTextField().setText(value.getAbsolutePath()); victim.apply(builder, onError); verify(builder).output(argThat(hasProperty("destination", equalTo(value)))); verify(onError, never()).accept(anyString()); }
@Test public void validUTFSpecialChars() throws IOException { BrowsableOutputDirectoryField victim = new BrowsableOutputDirectoryField(); File value = folder.newFolder("संसकरण_test"); victim.getTextField().setText(value.getAbsolutePath()); victim.apply(builder, onError); verify(builder).output(argThat(hasProperty("destination", equalTo(value)))); verify(onError, never()).accept(anyString()); }
@Test public void invalidBlank() { BrowsableOutputDirectoryField victim = new BrowsableOutputDirectoryField(); victim.getTextField().setText(" "); victim.apply(builder, onError); verify(builder, never()).output(any()); verify(onError).accept(anyString()); }
@Test public void invalidFile() throws IOException { BrowsableOutputDirectoryField victim = new BrowsableOutputDirectoryField(); File value = folder.newFile(); victim.getTextField().setText(value.getAbsolutePath()); victim.apply(builder, onError); verify(builder, never()).output(any()); verify(onError).accept(anyString()); }
@Test public void validNonExisting() throws IOException { HitTestListener<NonExistingOutputDirectoryEvent> listener = new HitTestListener<>(); eventStudio().add(NonExistingOutputDirectoryEvent.class, listener); BrowsableOutputDirectoryField victim = new BrowsableOutputDirectoryField(); File value = folder.newFolder(); victim.getTextField().setText(value.getAbsolutePath()); folder.delete(); victim.apply(builder, onError); assertTrue(listener.isHit()); }