### Question:
RotatingFileOutputStreamSupplier implements Supplier<OutputStream>, Closeable { @Override public OutputStream get() { if ( !closed.get() && !rotating.get() ) { if ( rotationDelayExceeded() && rotationThresholdExceeded() || !fileSystem.fileExists( outputFile ) ) { rotate(); } } return this.streamWrapper; } RotatingFileOutputStreamSupplier( FileSystemAbstraction fileSystem, File outputFile,
            long rotationThresholdBytes, long rotationDelay, int maxArchives, Executor rotationExecutor );  RotatingFileOutputStreamSupplier( FileSystemAbstraction fileSystem, File outputFile,
            long rotationThresholdBytes, long rotationDelay, int maxArchives, Executor rotationExecutor,
            RotationListener rotationListener );   RotatingFileOutputStreamSupplier( LongSupplier currentTimeSupplier, FileSystemAbstraction fileSystem,
            File outputFile, long rotationThresholdBytes, long rotationDelay, int maxArchives,
            Executor rotationExecutor, RotationListener rotationListener ); @Override OutputStream get(); @Override void close(); static List<File> getAllArchives( FileSystemAbstraction fileSystem,  File outputFile );  }### Answer:
@Test void shouldNotifyListenerOnRotationErrorDuringJobExecution() throws Exception { RotationListener rotationListener = mock( RotationListener.class ); Executor executor = mock( Executor.class ); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier( fileSystem, logFile, 10, 0, 10, executor, rotationListener ); OutputStream outputStream = supplier.get(); RejectedExecutionException exception = new RejectedExecutionException( "text exception" ); doThrow( exception ).when( executor ).execute( any( Runnable.class ) ); write( supplier, "A string longer than 10 bytes" ); assertThat( supplier.get(), is( outputStream ) ); verify( rotationListener ).rotationError( exception, outputStream ); }
@Test void shouldReattemptRotationAfterExceptionDuringJobExecution() throws Exception { RotationListener rotationListener = mock( RotationListener.class ); Executor executor = mock( Executor.class ); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier( fileSystem, logFile, 10, 0, 10, executor, rotationListener ); OutputStream outputStream = supplier.get(); RejectedExecutionException exception = new RejectedExecutionException( "text exception" ); doThrow( exception ).when( executor ).execute( any( Runnable.class ) ); write( supplier, "A string longer than 10 bytes" ); assertThat( supplier.get(), is( outputStream ) ); assertThat( supplier.get(), is( outputStream ) ); verify( rotationListener, times( 2 ) ).rotationError( exception, outputStream ); }
@Test void shouldNotifyListenerOnRotationErrorDuringRotationIO() throws Exception { RotationListener rotationListener = mock( RotationListener.class ); FileSystemAbstraction fs = spy( fileSystem ); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier( fs, logFile, 10, 0, 10, DIRECT_EXECUTOR, rotationListener ); OutputStream outputStream = supplier.get(); IOException exception = new IOException( "text exception" ); doThrow( exception ).when( fs ).renameFile( any( File.class ), any( File.class ) ); write( supplier, "A string longer than 10 bytes" ); assertThat( supplier.get(), is( outputStream ) ); verify( rotationListener ).rotationError( eq( exception ), any( OutputStream.class ) ); }