@Override
    public synchronized void registerProvider(VirtualProvider virtualProvider) {
        checkNotNull(virtualProvider, "Provider cannot be null");
        checkState(!providers.containsKey(virtualProvider.id()),
                   "Provider %s already registered", virtualProvider.id());

        // If the provider is a primary one, check for a conflict.
        ProviderId pid = virtualProvider.id();
        checkState(pid.isAncillary() || !providersByScheme.containsKey(pid.scheme()),
                   "A primary provider with id %s is already registered",
                   providersByScheme.get(pid.scheme()));

        providers.put(virtualProvider.id(), virtualProvider);

        // Register the provider by URI scheme only if it is not ancillary.
        if (!pid.isAncillary()) {
            providersByScheme.put(pid.scheme(), virtualProvider);
        }
    }
@Test
    public void registerProviderTest() {
        TestProvider1 provider1 = new TestProvider1();
        virtualProviderManager.registerProvider(provider1);

        assertEquals("The number of registered provider did not match.", 1,
                     virtualProviderManager.getProviders().size());

        assertEquals("The registered provider did not match", provider1,
                     virtualProviderManager.getProvider(TEST_SCHEME1));

        virtualProviderManager.unregisterProvider(provider1);

        TestProvider2 provider2 = new TestProvider2();
        virtualProviderManager.registerProvider(provider2);

        assertEquals("The number of registered provider did not match.", 1,
                     virtualProviderManager.getProviders().size());

        virtualProviderManager.unregisterProvider(provider2);

        assertEquals("The number of registered provider did not match.", 0,
                     virtualProviderManager.getProviders().size());
    }