### Question:
FusionIndexProvider extends IndexProvider { @Override public String getPopulationFailure( StoreIndexDescriptor descriptor ) throws IllegalStateException { StringBuilder builder = new StringBuilder(); providers.forAll( p -> writeFailure( p.getClass().getSimpleName(), builder, p, descriptor ) ); String failure = builder.toString(); if ( !failure.isEmpty() ) { return failure; } throw new IllegalStateException( "None of the indexes were in a failed state" ); } FusionIndexProvider(
            // good to be strict with specific providers here since this is dev facing
            IndexProvider stringProvider,
            IndexProvider numberProvider,
            IndexProvider spatialProvider,
            IndexProvider temporalProvider,
            IndexProvider luceneProvider,
            SlotSelector slotSelector,
            IndexProviderDescriptor descriptor,
            IndexDirectoryStructure.Factory directoryStructure,
            FileSystemAbstraction fs,
            boolean archiveFailedIndex ); @Override IndexPopulator getPopulator( StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig, ByteBufferFactory bufferFactory ); @Override IndexAccessor getOnlineAccessor( StoreIndexDescriptor descriptor, IndexSamplingConfig samplingConfig ); @Override String getPopulationFailure( StoreIndexDescriptor descriptor ); @Override InternalIndexState getInitialState( StoreIndexDescriptor descriptor ); @Override IndexCapability getCapability( StoreIndexDescriptor descriptor ); @Override StoreMigrationParticipant storeMigrationParticipant( FileSystemAbstraction fs, PageCache pageCache );  }### Answer:
@Test public void getPopulationFailureMustThrowIfNoFailure() { IllegalStateException failure = new IllegalStateException( "not failed" ); for ( IndexProvider provider : aliveProviders ) { when( provider.getPopulationFailure( any( StoreIndexDescriptor.class ) ) ).thenThrow( failure ); } try { fusionIndexProvider.getPopulationFailure( AN_INDEX ); fail( "Should have failed" ); } catch ( IllegalStateException e ) { } }
@Test public void getPopulationFailureMustReportFailureWhenAnyFailed() { for ( IndexProvider failingProvider : aliveProviders ) { String failure = "failure"; IllegalStateException exception = new IllegalStateException( "not failed" ); for ( IndexProvider provider : aliveProviders ) { if ( provider == failingProvider ) { when( provider.getPopulationFailure( any( StoreIndexDescriptor.class ) ) ).thenReturn( failure ); } else { when( provider.getPopulationFailure( any( StoreIndexDescriptor.class ) ) ).thenThrow( exception ); } } assertThat( fusionIndexProvider.getPopulationFailure( AN_INDEX ), containsString( failure ) ); } }
@Test public void getPopulationFailureMustReportFailureWhenMultipleFail() { List<String> failureMessages = new ArrayList<>(); for ( IndexProvider aliveProvider : aliveProviders ) { String failureMessage = "FAILURE[" + aliveProvider + "]"; failureMessages.add( failureMessage ); when( aliveProvider.getPopulationFailure( any( StoreIndexDescriptor.class ) ) ).thenReturn( failureMessage ); } String populationFailure = fusionIndexProvider.getPopulationFailure( AN_INDEX ); for ( String failureMessage : failureMessages ) { assertThat( populationFailure, containsString( failureMessage ) ); } }