### Question:
InfrastructureFactory { public Consumer<Throwable> configureErrorHandler() { return errorHandler.orElse(DEFAULT_ERROR_HANDLER); } InfrastructureFactory(Optional<Path> logfilePath, Optional<PrintStream> loggerOutput, Optional<Boolean> storeStackTracesInFilesystem, Optional<Path> stackTraceStoragePath, Optional<DiagnosticContextSupplier> correlationIdSupplier, Optional<Consumer<Throwable>> errorHandler); Destination<T> configureDestination(); Consumer<Throwable> configureErrorHandler(); DiagnosticContextSupplier configureContextSupplier(); Optional<Path> getLogfilePath(); Optional<PrintStream> getLoggerOutput(); Optional<Boolean> getStoreStackTracesInFilesystem(); Optional<Path> getStackTraceStoragePath(); Optional<DiagnosticContextSupplier> getContextSupplier(); Optional<Consumer<Throwable>> getErrorHandler(); static final Consumer<Throwable> DEFAULT_ERROR_HANDLER; static final DiagnosticContextSupplier EMPTY_CONTEXT_SUPPLIER; }### Answer:
@Test public void configureErrorHandler_shouldReturnTheProvidedErrorHAndler_whenOneIsProvided() throws Exception { Consumer<Throwable> expectedErrorHandler = t -> {}; InfrastructureFactory factory = new InfrastructureFactory( SAMPLE_LOGFILE_PATH, SAMPLE_LOGGER_OUTPUT, SAMPLE_STORE_STACK_TRACES_IN_FILESYSTEM, SAMPLE_STACK_TRACE_STORAGE_PATH, SAMPLE_CONTEXT_SUPPLIER, Optional.of(expectedErrorHandler)); Consumer<Throwable> actualErrorHandler = factory.configureErrorHandler(); assertSame(expectedErrorHandler, actualErrorHandler); }
@Test public void configureErrorHandler_shouldReturnTheDefaultErrorHAndle_whenOneIsNotProvided() throws Exception { InfrastructureFactory factory = new InfrastructureFactory( SAMPLE_LOGFILE_PATH, SAMPLE_LOGGER_OUTPUT, SAMPLE_STORE_STACK_TRACES_IN_FILESYSTEM, SAMPLE_STACK_TRACE_STORAGE_PATH, SAMPLE_CONTEXT_SUPPLIER, Optional.empty()); Consumer<Throwable> actualErrorHandler = factory.configureErrorHandler(); assertSame(InfrastructureFactory.DEFAULT_ERROR_HANDLER, actualErrorHandler); }