/**
   * Test method for {@link
   * org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory#newDiagram()}.
   */
  @Test
  public void testNewDiagram() {
    NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();

    Diagram diagram1 = factory.newDiagram();

    assertNotNull("diagram1 created", diagram1);
  }
  /** Test */
  @Test
  public void testNewProperty() {
    NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();

    Diagram diagram1 = factory.newDiagram();
    Class c1 = factory.newClass(diagram1, "C1");
    Property p1 = factory.newProperty(c1, "p1");

    assertNotNull("property created", p1);
  }
  /** Test list sync */
  @Test
  public void testSyncWhenViewIsRemoved() {

    // Create variables
    NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
    Diagram diagram1 = factory.newDiagram();

    int expectedSize = 3;
    List<View> list = new ArrayList<View>();
    DiagramViewToListSynchronizer listSynchronizer =
        new DiagramViewToListSynchronizer(diagram1, list);

    Class C1 = factory.newClass(diagram1, "C1");
    View shape1 = factory.lookupViewFor(diagram1, C1);
    Class C2 = factory.newClass(diagram1, "C2");
    View shape2 = factory.lookupViewFor(diagram1, C2);
    Class C3 = factory.newClass(diagram1, "C3");
    View shape3 = factory.lookupViewFor(diagram1, C3);

    // assert before
    assertEquals("listSize", expectedSize, list.size());
    assertTrue("list contain expected view", list.contains(shape2));

    // Action
    factory.remove(diagram1, C2);
    // assert
    assertEquals("listSize", expectedSize - 1, list.size());
    assertFalse("list contain expected view", list.contains(shape2));
  }
  /**
   * Test method for {@link
   * org.eclipse.papyrus.layers.stackmodel.util.DiagramViewToListSynchronizer#DiagramViewToListSynchronizer(org.eclipse.gmf.runtime.notation.Diagram,
   * java.util.Collection)}.
   */
  @Test
  public void testDiagramViewToListSynchronizer() {

    // Create variables
    NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
    Diagram diagram1 = factory.newDiagram();

    List<View> list = new ArrayList<View>();

    //
    DiagramViewToListSynchronizer listSynchronizer =
        new DiagramViewToListSynchronizer(diagram1, list);

    // assert
    assertNotNull("object created", listSynchronizer);
  }
  /**
   * Test method for {@link
   * org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory#newClass(org.eclipse.gmf.runtime.notation.Diagram,
   * java.lang.String)}.
   */
  @Test
  public void testNewClass() {
    NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();

    // Action
    Diagram diagram1 = factory.newDiagram();
    Class c1 = factory.newClass(diagram1, "C1");
    Class c2 = factory.newClass(diagram1, "C2");

    // Lookup Shape
    View shape1 = factory.lookupViewFor(diagram1, c1);
    View shape2 = factory.lookupViewFor(diagram1, c2);

    // Assert
    assertNotNull("class created", c1);
    assertNotNull("shape created", shape2);
    assertNotNull("shape created", shape1);
  }
  /**
   * Test method for {@link
   * org.eclipse.papyrus.layers.stackmodel.util.NotationAndUmlModelsFactory#remove(org.eclipse.gmf.runtime.notation.Diagram,
   * java.lang.String)}.
   */
  @Test
  public void testRemove() {
    NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();

    Diagram diagram1 = factory.newDiagram();
    Class c1 = factory.newClass(diagram1, "C1");
    Class c2 = factory.newClass(diagram1, "C2");

    // Lookup Shape
    View shape1 = factory.lookupViewFor(diagram1, c1);
    View shape2 = factory.lookupViewFor(diagram1, c2);

    // Action
    View removedShape = factory.remove(diagram1, c1);
    View lookupResult = factory.lookupViewFor(diagram1, c1);

    // Assert
    assertNotNull("object removed found", removedShape);
    assertSame("Right object removed", shape1, removedShape);

    assertNull("lookupResult null after remove", lookupResult);
  }
  /**
   * Test method for {@link
   * org.eclipse.papyrus.layers.stackmodel.util.DiagramViewToListSynchronizer#setDiagram(org.eclipse.gmf.runtime.notation.Diagram)}.
   */
  @Test
  public void testSetDiagram() {
    // Create variables
    NotationAndUmlModelsFactory factory = new NotationAndUmlModelsFactory();
    Diagram diagram1 = factory.newDiagram();
    Class C1 = factory.newClass(diagram1, "C1");
    View shape1 = factory.lookupViewFor(diagram1, C1);
    Class C2 = factory.newClass(diagram1, "C2");
    View shape2 = factory.lookupViewFor(diagram1, C2);
    Class C3 = factory.newClass(diagram1, "C3");
    View shape3 = factory.lookupViewFor(diagram1, C3);

    List<View> expectedViews1 = Lists.newArrayList(shape1, shape2, shape3);

    // Check if the list is set on init
    List<View> list = new ArrayList<View>();
    DiagramViewToListSynchronizer listSynchronizer =
        new DiagramViewToListSynchronizer(diagram1, list);
    int expectedSize = 3;
    // Assert
    assertEquals("list size", expectedSize, list.size());
    assertTrue("list correctly set", list.containsAll(expectedViews1));

    // Now, change the diagram
    Diagram diagram2 = factory.newDiagram();
    Class C21 = factory.newClass(diagram2, "C1");
    View shape21 = factory.lookupViewFor(diagram2, C21);
    Class C22 = factory.newClass(diagram2, "C2");
    View shape22 = factory.lookupViewFor(diagram2, C22);
    Class C23 = factory.newClass(diagram2, "C3");
    View shape23 = factory.lookupViewFor(diagram2, C23);
    List<View> expectedViews2 = Lists.newArrayList(shape21, shape22, shape23);
    int expectedSize2 = 3;

    // Action
    listSynchronizer.setDiagram(diagram2);
    // Assert
    assertEquals("list size", expectedSize2, list.size());
    assertTrue("list correctly set", list.containsAll(expectedViews2));
  }