### Question:
EntryBasedLogPruningStrategy implements CoreLogPruningStrategy { @Override public long getIndexToKeep( Segments segments ) { SegmentVisitor visitor = new SegmentVisitor(); segments.visitBackwards( visitor ); if ( visitor.visitedCount == 0 ) { log.warn( "No log files found during the prune operation. This state should resolve on its own, but" + " if this warning continues, you may want to look for other errors in the user log." ); } return visitor.prevIndex; } EntryBasedLogPruningStrategy( long entriesToKeep, LogProvider logProvider ); @Override long getIndexToKeep( Segments segments );  }### Answer:
@Test public void indexToKeepTest() { files = createSegmentFiles( 10 ); EntryBasedLogPruningStrategy strategy = new EntryBasedLogPruningStrategy( 6, mock( LogProvider.class ) ); long indexToKeep = strategy.getIndexToKeep( segments ); assertEquals( 2, indexToKeep ); }
@Test public void pruneStrategyExceedsNumberOfEntriesTest() { files = createSegmentFiles( 10 ).subList( 5, 10 ); EntryBasedLogPruningStrategy strategy = new EntryBasedLogPruningStrategy( 7, mock( LogProvider.class ) ); long indexToKeep = strategy.getIndexToKeep( segments ); assertEquals( 4, indexToKeep ); }
@Test public void onlyFirstActiveLogFileTest() { files = createSegmentFiles( 1 ); EntryBasedLogPruningStrategy strategy = new EntryBasedLogPruningStrategy( 6, mock( LogProvider.class ) ); long indexToKeep = strategy.getIndexToKeep( segments ); assertEquals( -1, indexToKeep ); }
@Test public void onlyOneActiveLogFileTest() { files = createSegmentFiles( 6 ).subList( 4, 6 ); EntryBasedLogPruningStrategy strategy = new EntryBasedLogPruningStrategy( 6, mock( LogProvider.class ) ); long indexToKeep = strategy.getIndexToKeep( segments ); assertEquals( 3, indexToKeep ); }