### Question:
ProviderServiceImpl implements ProviderService { @Override public void createProvider(final ProviderType providerType, final ProviderConfiguration configuration) { checkNotNull("providerType", providerType); checkNotNull("providerType.providerTypeKey", providerType.getKey()); checkNotNull("configuration", configuration); checkNotEmpty("configuration.values", configuration.getValues()); validateForCreateProvider(configuration); @SuppressWarnings("unchecked") final ProviderConfig providerConfig = (ProviderConfig) providerConverterFactory.getProviderConfigConverter(providerType.getKey()).toDomain(configuration); runtimeProvisioningService.registerProvider(providerConfig); } ProviderServiceImpl(); @Inject  ProviderServiceImpl(final RuntimeProvisioningServiceBackend runtimeProvisioningService,
                               final ProviderConverterFactory providerConverterFactory); @Override Collection<Provider> getProviders(final ProviderType providerType); @Override Collection<ProviderKey> getProvidersKey(final ProviderType providerType); @Override void createProvider(final ProviderType providerType,
                               final ProviderConfiguration configuration); @Override void deleteProvider(final ProviderKey providerKey); @Override Provider getProvider(final ProviderKey providerKey);  }### Answer:
@Test public void testCreateProvider() { prepareConfigurationForCreate(); when(providerConfiguration.getId()).thenReturn(PROVIDER_ID); service.createProvider(providerType, providerConfiguration); verify(runtimeProvisioningService, times(1)).registerProvider(providerConfig); }
@Test public void testCreateProviderExisting() { prepareConfigurationForCreate(); String existingId = providers.get(1).getKey().getId(); when(providerConfiguration.getId()).thenReturn(existingId); expectedException.expectMessage("A provider with the given name already exists: " + existingId); service.createProvider(providerType, providerConfiguration); verify(runtimeProvisioningService, never()).registerProvider(any(ProviderConfig.class)); }