### Question:
ServiceConfigProviderFactoryImpl implements ServiceConfigProviderFactory { @Override @SuppressWarnings("unchecked") public <C extends SelfServiceConsoleConfig> ServiceConfigProvider<C> getProvider(C config) { String providerClassName = config.getConfigProviderClass(); ServiceConfigProvider<?> provider = providers.get(providerClassName); if (provider == null) { provider = constructNewProvider(providerClassName); ServiceConfigProvider<?> old = providers.putIfAbsent(providerClassName, provider); if (old != null) { provider = old; } } return (ServiceConfigProvider<C>) provider; } @Inject  ServiceConfigProviderFactoryImpl(Injector injector); @Override @SuppressWarnings("unchecked") ServiceConfigProvider<C> getProvider(C config);  }### Answer:
@Test public void retrievesValidProviderInstance() { SelfServiceConsoleConfig config = mock(SelfServiceConsoleConfig.class); given(config.getConfigProviderClass()).willReturn(MockConfigProvider.class.getName()); MockConfigProvider provider = new MockConfigProvider(); given(injector.getInstance(MockConfigProvider.class)).willReturn(provider); ServiceConfigProvider<SelfServiceConsoleConfig> providerResult = providerFactory.getProvider(config); assertThat(providerResult).isEqualTo(provider); }
@Test public void retrievesSameInstance() { SelfServiceConsoleConfig config = mock(SelfServiceConsoleConfig.class); given(config.getConfigProviderClass()).willReturn(MockConfigProvider.class.getName()); MockConfigProvider provider = new MockConfigProvider(); given(injector.getInstance(MockConfigProvider.class)).willReturn(provider); ServiceConfigProvider<SelfServiceConsoleConfig> providerResultA = providerFactory.getProvider(config); ServiceConfigProvider<SelfServiceConsoleConfig> providerResultB = providerFactory.getProvider(config); assertThat(providerResultA).isEqualTo(provider); assertThat(providerResultA).isEqualTo(providerResultB); }