Ejemplo n.º 1
0
  @Test
  public void getAddedAndRemoved() {
    final EObject obj00 = EcoreUtil.create(eClass0);
    final EObject obj1 = EcoreUtil.create(eClass1);
    final EObject obj01 = EcoreUtil.create(eClass0);
    final EObject obj02 = EcoreUtil.create(eClass0);
    final List<Notification> messages = new ArrayList<Notification>();
    obj1.eAdapters()
        .add(
            new AdapterImpl() {
              @Override
              public void notifyChanged(Notification msg) {
                messages.add(msg);
              }
            });

    // Add
    obj1.eSet(multiRef, Arrays.asList(new EObject[] {obj00, obj01}));
    EMFUtils.setOrAdd(obj1, multiRef, obj02);

    // Remove
    final List list = (List) obj1.eGet(multiRef);
    list.remove(obj00);
    list.removeAll(Arrays.asList(new EObject[] {obj01, obj02}));

    final List<EObject> addedObjects = new ArrayList<EObject>();
    final List<EObject> removedObjects = new ArrayList<EObject>();
    for (Notification msg : messages) {
      addedObjects.addAll(EMFUtils.getAddedObjects(msg, obj00.getClass()));
      removedObjects.addAll(EMFUtils.getRemovedObjects(msg, obj00.getClass()));
    }

    assertEquals(Arrays.asList(new EObject[] {obj00, obj01, obj02}), addedObjects);
    assertEquals(Arrays.asList(new EObject[] {obj00, obj01, obj02}), removedObjects);
  }
Ejemplo n.º 2
0
 @Test
 public void set() {
   EObject obj0 = EcoreUtil.create(eClass0);
   EObject obj1 = EcoreUtil.create(eClass1);
   EMFUtils.setOrAdd(obj0, singleRef, obj1);
   assertEquals(obj1, obj0.eGet(singleRef));
 }
Ejemplo n.º 3
0
 @Test
 public void containingListAndIndex() {
   EObject obj0 = EcoreUtil.create(eClass0);
   assertNull(EMFUtils.getContainingList(obj0));
   assertEquals(-1, EMFUtils.getIndexWithinParent(obj0));
   EObject obj1 = EcoreUtil.create(eClass1);
   assertNull(EMFUtils.getContainingList(obj1));
   assertEquals(-1, EMFUtils.getIndexWithinParent(obj1));
   EMFUtils.setOrAdd(obj1, multiRef, obj0);
   assertTrue(obj1.eGet(multiRef) == EMFUtils.getContainingList(obj0));
   assertEquals(0, EMFUtils.getIndexWithinParent(obj0));
 }