### Question:
LuceneExplicitIndexUpgrader { public void upgradeIndexes() throws ExplicitIndexMigrationException { try { if ( !Files.exists( indexRootPath ) ) { return; } monitor.starting( (int) Files.walk( indexRootPath ).count() ); try ( Stream<Path> pathStream = Files.walk( indexRootPath ); IndexUpgraderWrapper lucene4Upgrader = createIndexUpgrader( getLucene4JarPaths() ); IndexUpgraderWrapper lucene5Upgrader = createIndexUpgrader( getLucene5JarPaths() ) ) { List<Path> indexPaths = pathStream.filter( getIndexPathFilter() ).collect( Collectors.toList() ); for ( Path indexPath : indexPaths ) { try { lucene4Upgrader.upgradeIndex( indexPath ); lucene5Upgrader.upgradeIndex( indexPath ); monitor.migrated( indexPath.toFile().getName() ); } catch ( Throwable e ) { throw new ExplicitIndexMigrationException( indexPath.getFileName().toString(), "Migration of explicit index at path:" + indexPath + " failed.", e ); } } } } catch ( ExplicitIndexMigrationException ime ) { throw ime; } catch ( Exception e ) { throw new RuntimeException( "Lucene explicit indexes migration failed.", e ); } } LuceneExplicitIndexUpgrader( Path indexRootPath, Monitor monitor ); void upgradeIndexes(); static final Monitor NO_MONITOR; }### Answer:
@Test public void ignoreFoldersWithoutIndexes() throws URISyntaxException, ExplicitIndexMigrationException { Path indexFolder = createPathForResource("notIndexFolder"); TrackingLuceneExplicitIndexUpgrader indexUpgrader = new TrackingLuceneExplicitIndexUpgrader( indexFolder ); indexUpgrader.upgradeIndexes(); assertTrue(indexUpgrader.getMigratedIndexes().isEmpty()); }
@Test public void migrateValidIndexes() throws URISyntaxException, ExplicitIndexMigrationException { Path indexFolder = createPathForResource("indexFolder"); TrackingLuceneExplicitIndexUpgrader indexUpgrader = new TrackingLuceneExplicitIndexUpgrader( indexFolder ); indexUpgrader.upgradeIndexes(); assertThat(indexUpgrader.getMigratedIndexes(), Matchers.contains("index1", "index2")); }
@Test public void pointIncorrectIndexOnMigrationFailure() throws URISyntaxException, ExplicitIndexMigrationException { Path indexFolder = createPathForResource("indexFolder"); TrackingLuceneExplicitIndexUpgrader indexUpgrader = new TrackingLuceneExplicitIndexUpgrader( indexFolder, true ); expectedException.expect( ExplicitIndexMigrationException.class ); expectedException.expect( new ExplicitIndexMigrationExceptionBaseMatcher( "index1", "index2" ) ); indexUpgrader.upgradeIndexes(); }