/**
  * Tests that the names in the current state are exactly the same as the ones in the reported
  * sources.
  */
 @Test
 public void testNames() {
   final Map<String, Object> currentState = myProvider.getCurrentState();
   final List<String> providedSourceNames = Arrays.asList(myProvider.getProvidedSourceNames());
   for (final String n : providedSourceNames) {
     assertTrue("Variable " + n, currentState.containsKey(n));
   }
   for (final String n : currentState.keySet()) {
     assertTrue("Variable " + n, providedSourceNames.contains(n));
   }
   assertEquals(providedSourceNames.size(), currentState.size());
 }
  /**
   * Tests that the {@link ISourceProviderService} return the correct source provider for all the
   * sources offered.
   */
  @Test
  public void testISourceProviderServiceNames() {
    final Map<String, Object> currentState = myProvider.getCurrentState();
    final IServiceLocator locator = myContext.getServiceLocator();

    final ISourceProviderService sourceProviders =
        (ISourceProviderService) locator.getService(ISourceProviderService.class);

    for (final String n : myProvider.getProvidedSourceNames()) {
      assertEquals(
          "Wrong source provider for " + n, myProvider, sourceProviders.getSourceProvider(n));
    }
  }
  /** Tests that the services extension point for {@link BindingSourceProvider} is correct. */
  @Test
  public void testServicesExtension() {
    boolean found = false;
    final Map<String, Object> currentState = myProvider.getCurrentState();
    final List<String> providedSourceNames = Arrays.asList(myProvider.getProvidedSourceNames());

    final IExtensionRegistry registry = Platform.getExtensionRegistry();
    for (final IConfigurationElement ce :
        registry.getConfigurationElementsFor("org.eclipse.ui.services")) {
      if (!ce.getContributor().getName().equals(Activator.ID)) {
        continue;
      }
      assertEquals("sourceProvider", ce.getName());
      if (!ce.getAttribute("provider").equals(BindingSourceProvider.class.getName())) {
        continue;
      }

      /*
       * Only one declaration
       */
      assertTrue(!found);
      found = true;

      final IConfigurationElement[] children = ce.getChildren("variable");
      final List<String> childrenVariables = new ArrayList<String>();
      for (final IConfigurationElement cce : children) {
        final String name = cce.getAttribute("name");
        assertFalse(name + " listed twice", childrenVariables.contains(name));
        childrenVariables.add(name);
        assertTrue(name + " not in current state", currentState.containsKey(name));
        if (name.equals(Constants.SOURCES_THE_MANAGER)) {
          assertEquals(name + " priority", "workbench", cce.getAttribute("priorityLevel"));
        } else {
          assertEquals(name + " priority", "activeSite", cce.getAttribute("priorityLevel"));
        }
      }
      for (final String name : childrenVariables) {
        assertTrue(name + " not in provider names", providedSourceNames.contains(name));
      }
      assertEquals(providedSourceNames.size(), children.length);
    }

    assertTrue(found);
  }
  public void assertSource(String name, Object value) {
    final Map<String, Object> currentState = myProvider.getCurrentState();

    assertEquals("variable " + name, value, currentState.get(name));
  }