public void testGetContext() {
    StructureMetaData structure = createDefault();
    assertEmpty(structure.getContexts());

    assertNull(structure.getContext("one"));
    assertNull(structure.getContext("two"));

    ContextInfo one = createContext("one");
    ContextInfo two = createContext("two");
    structure.addContext(one);
    structure.addContext(two);

    assertEquals(one, structure.getContext("one"));
    assertEquals(two, structure.getContext("two"));

    structure.removeContext("one");
    assertNull(structure.getContext("one"));
    assertEquals(two, structure.getContext("two"));

    structure.removeContext("two");
    assertNull(structure.getContext("one"));
    assertNull(structure.getContext("two"));

    structure.addContext(one);
    assertEquals(one, structure.getContext("one"));
    assertNull(structure.getContext("two"));
  }
  public void testEqualsAndHashCode() {
    StructureMetaData one = createDefault();
    StructureMetaData two = createDefault();
    assertEquals(one, two);
    assertEquals(two, one);
    assertEquals(one.hashCode(), two.hashCode());

    ContextInfo context1 = createContext("one");
    ContextInfo context2 = createContext("two");

    one.addContext(context1);
    two.addContext(context1);
    assertEquals(one, two);
    assertEquals(two, one);
    assertEquals(one.hashCode(), two.hashCode());

    one.addContext(context2);
    two.addContext(context2);
    assertEquals(one, two);
    assertEquals(two, one);
    assertEquals(one.hashCode(), two.hashCode());
    one.removeContext(context2);
    two.removeContext(context2);

    ContextInfo another1 = createContext("one");
    two.removeContext(context1);
    two.addContext(another1);
    assertEquals(one, two);
    assertEquals(two, one);
    assertEquals(one.hashCode(), two.hashCode());

    two.removeContext(context1);
    assertNotSame(one, two);
    assertNotSame(two, one);
    assertNotSame(one.hashCode(), two.hashCode());

    two.addContext(context2);
    assertNotSame(one, two);
    assertNotSame(two, one);
    assertNotSame(one.hashCode(), two.hashCode());

    one = createDefault();
    two = createDefault();
    one.addContext(context1);
    one.addContext(context2);
    two.addContext(context2);
    two.addContext(context1);
    assertNotSame(one, two);
    assertNotSame(two, one);
    assertNotSame(one.hashCode(), two.hashCode());
  }
  public void testRemoveContextByNameErrors() {
    StructureMetaData structure = createDefault();
    assertEmpty(structure.getContexts());

    try {
      String name = null;
      structure.removeContext(name);
      fail("Should not be here!");
    } catch (Exception e) {
      checkThrowable(IllegalArgumentException.class, e);
    }
  }
  public void testRemoveContextsByName() {
    StructureMetaData structure = createDefault();
    assertEmpty(structure.getContexts());

    ContextInfo one = createContext("one");
    ContextInfo two = createContext("two");
    ContextInfo three = createContext("three");
    structure.addContext(one);
    structure.addContext(two);
    structure.addContext(three);
    assertEquals(getExpected(one, two, three), structure.getContexts());
    assertEquals(one, structure.getContext("one"));
    assertEquals(two, structure.getContext("two"));
    assertEquals(three, structure.getContext("three"));

    structure.removeContext("one");
    assertEquals(getExpected(two, three), structure.getContexts());
    assertNull(structure.getContext("one"));
    assertEquals(two, structure.getContext("two"));
    assertEquals(three, structure.getContext("three"));

    structure.removeContext("two");
    assertEquals(getExpected(three), structure.getContexts());
    assertNull(structure.getContext("one"));
    assertNull(structure.getContext("two"));
    assertEquals(three, structure.getContext("three"));

    structure.removeContext("three");
    assertEquals(getExpected(), structure.getContexts());
    assertNull(structure.getContext("one"));
    assertNull(structure.getContext("two"));
    assertNull(structure.getContext("three"));

    structure.addContext(one);
    assertEquals(getExpected(one), structure.getContexts());
    assertEquals(one, structure.getContext("one"));

    // Removing a context not present is ok
    structure.removeContext("two");
  }
  public void testRemoveContextByName() {
    StructureMetaData structure = createDefault();
    assertEmpty(structure.getContexts());

    ContextInfo one = createContext("one");
    structure.addContext(one);
    assertEquals(getExpected(one), structure.getContexts());
    assertEquals(one, structure.getContext("one"));

    structure.removeContext("one");
    assertEquals(getExpected(), structure.getContexts());
    assertNull(structure.getContext("one"));

    structure.addContext(one);
    assertEquals(getExpected(one), structure.getContexts());
    assertEquals(one, structure.getContext("one"));
  }