### Question:
OpsLoggerFactory { @SuppressWarnings("unchecked") public <T extends Enum<T> & LogMessage> OpsLogger<T> build() throws UncheckedIOException { if (!cachedInstance.isPresent()) { cachedInstance = Optional.of(buildNewInstance()); } return (OpsLogger<T>) cachedInstance.get(); }  OpsLoggerFactory setDestination(PrintStream printStream); OpsLoggerFactory setPath(Path path); OpsLoggerFactory setStoreStackTracesInFilesystem(boolean store); OpsLoggerFactory setStackTraceStoragePath(Path directory); OpsLoggerFactory setErrorHandler(Consumer<Throwable> handler); @Deprecated OpsLoggerFactory setCorrelationIdSupplier(Supplier<Map<String,String>> supplier); OpsLoggerFactory setGlobalDiagnosticContextSupplier(DiagnosticContextSupplier supplier); OpsLoggerFactory setAsync(boolean async); @SuppressWarnings("unchecked") OpsLogger<T> build();  }### Answer:
@Test public void build_shouldReturnACorrectlyConfiguredBasicOpsLoggerToSystemOut_whenNoConfigurationIsPerformed() throws Exception { OpsLogger<TestMessages> logger = new OpsLoggerFactory().build(); BasicOpsLogger<TestMessages> basicLogger = (BasicOpsLogger<TestMessages>) logger; assertThat(basicLogger.getDestination(), instanceOf(OutputStreamDestination.class)); assertEquals(InfrastructureFactory.EMPTY_CONTEXT_SUPPLIER, basicLogger.getDiagnosticContextSupplier()); OutputStreamDestination<TestMessages> destination = (OutputStreamDestination<TestMessages>) basicLogger.getDestination(); assertSame(System.out, destination.getOutput()); assertThat(destination.getStackTraceProcessor(), instanceOf(SimpleStackTraceProcessor.class)); ensureCorrectlyConfigured(basicLogger); }
@Test public void build_shouldDelegateToTheBasicOpsLoggerFactory_whenTheDefaultAsyncValueIsUsed() throws Exception { BasicOpsLogger<TestMessages> expectedResult = createMockBasicOpsLogger(); when(basicOpsLoggerFactoryMock.build(Mockito.any())).thenAnswer(invocation -> expectedResult); OpsLogger<TestMessages> result = factory.build(); verify(basicOpsLoggerFactoryMock).build(any(InfrastructureFactory.class)); verifyZeroInteractions(asyncOpsLoggerFactoryMock); assertSame(expectedResult, result); }
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes") @Test public void build_shouldPassSensibleDefaultsToTheFactory_givenNothingChosen() throws Exception { factory.build(); InfrastructureFactory capturedFactory = captureProvidedInfrastructureFactory(); assertEquals(Optional.empty(), capturedFactory.getLoggerOutput()); assertEquals(Optional.empty(), capturedFactory.getLogfilePath()); assertEquals(Optional.empty(), capturedFactory.getStoreStackTracesInFilesystem()); assertEquals(Optional.empty(), capturedFactory.getStackTraceStoragePath()); assertEquals(Optional.empty(), capturedFactory.getErrorHandler()); assertEquals(Optional.empty(), capturedFactory.getContextSupplier()); }
@Test public void build_shouldReuseInstances_whenNoChangesHaveBeenMade() throws Exception { OpsLogger<TestMessages> first = factory.build(); OpsLogger<TestMessages> second = factory.build(); assertSame(first, second); }