### Question:
StandardProviderFactory implements ProviderFactory, DisposableBean { @Bean @Override public synchronized FlowPersistenceProvider getFlowPersistenceProvider() { if (flowPersistenceProvider == null) { if (providersHolder.get() == null) { throw new ProviderFactoryException("ProviderFactory must be initialized before obtaining a Provider"); } final Providers providers = providersHolder.get(); final org.apache.nifi.registry.provider.generated.Provider jaxbFlowProvider = providers.getFlowPersistenceProvider(); final String flowProviderClassName = jaxbFlowProvider.getClazz(); try { final ClassLoader classLoader = extensionManager.getExtensionClassLoader(flowProviderClassName); if (classLoader == null) { throw new IllegalStateException("Extension not found in any of the configured class loaders: " + flowProviderClassName); } final Class<?> rawFlowProviderClass = Class.forName(flowProviderClassName, true, classLoader); final Class<? extends FlowPersistenceProvider> flowProviderClass = rawFlowProviderClass.asSubclass(FlowPersistenceProvider.class); final Constructor constructor = flowProviderClass.getConstructor(); flowPersistenceProvider = (FlowPersistenceProvider) constructor.newInstance(); performMethodInjection(flowPersistenceProvider, flowProviderClass); LOGGER.info("Instantiated FlowPersistenceProvider with class name {}", new Object[]{flowProviderClassName}); } catch (Exception e) { LOGGER.error(e.getMessage(), e); throw new ProviderFactoryException("Error creating FlowPersistenceProvider with class name: " + flowProviderClassName, e); } final ProviderConfigurationContext configurationContext = createConfigurationContext(jaxbFlowProvider.getProperty()); flowPersistenceProvider.onConfigured(configurationContext); LOGGER.info("Configured FlowPersistenceProvider with class name {}", new Object[]{flowProviderClassName}); } return flowPersistenceProvider; } @Autowired  StandardProviderFactory(final NiFiRegistryProperties properties, final ExtensionManager extensionManager, final DataSource dataSource); @PostConstruct @Override synchronized void initialize(); @Bean @Override synchronized FlowPersistenceProvider getFlowPersistenceProvider(); @Bean @Override List<EventHookProvider> getEventHookProviders(); @Bean @Override synchronized BundlePersistenceProvider getBundlePersistenceProvider(); @Override void destroy();  }### Answer:
@Test(expected = ProviderFactoryException.class) public void testGetFlowProviderBeforeInitializingShouldThrowException() { final NiFiRegistryProperties props = new NiFiRegistryProperties(); props.setProperty(NiFiRegistryProperties.PROVIDERS_CONFIGURATION_FILE, "src/test/resources/provider/providers-good.xml"); final ExtensionManager extensionManager = Mockito.mock(ExtensionManager.class); when(extensionManager.getExtensionClassLoader(any(String.class))) .thenReturn(new ExtensionClassLoader("/tmp", new URL[0],this.getClass().getClassLoader())); final DataSource dataSource = Mockito.mock(DataSource.class); final ProviderFactory providerFactory = new StandardProviderFactory(props, extensionManager, dataSource); providerFactory.getFlowPersistenceProvider(); }