### Question:
Segments implements AutoCloseable { @Override public synchronized void close() { RuntimeException error = null; for ( SegmentFile segment : allSegments ) { try { segment.close(); } catch ( RuntimeException ex ) { if ( error == null ) { error = ex; } else { error.addSuppressed( ex ); } } } if ( error != null ) { throw error; } } Segments( FileSystemAbstraction fileSystem, FileNames fileNames, ReaderPool readerPool, List<SegmentFile> allSegments,
            ChannelMarshal<ReplicatedContent> contentMarshal, LogProvider logProvider, long currentVersion ); synchronized SegmentFile prune( long pruneIndex ); @Override synchronized void close();  }### Answer:
@Test public void shouldCloseTheSegments() { Segments segments = new Segments( fsa, fileNames, readerPool, segmentFiles, contentMarshal, logProvider, -1 ); segments.close(); for ( SegmentFile file : segmentFiles ) { verify( file ).close(); } }
@Test public void shouldNotSwallowExceptionOnClose() { doThrow( new RuntimeException() ).when( fileA ).close(); doThrow( new RuntimeException() ).when( fileB ).close(); Segments segments = new Segments( fsa, fileNames, readerPool, segmentFiles, contentMarshal, logProvider, -1 ); try { segments.close(); fail( "should have thrown" ); } catch ( RuntimeException ex ) { Throwable[] suppressed = ex.getSuppressed(); assertEquals( 1, suppressed.length ); assertTrue( suppressed[0] instanceof RuntimeException ); } }