@Override public void clear() { // Delete non-canonical elements first so no events are generated. cleanup(); // Then delete the canonical, which will remove currentValue. Doc.E element = findCanonicalElement(); if (element != null) { getDocument().deleteNode(element); } assert currentElement == null; assert currentValue == null; }
private void remoteRemoveCanonicalValue() { Doc.E canonical = DocHelper.getElementWithTagName(doc, TAG); doc.deleteNode(canonical); }
private void remoteRemoveCanonicalValue() { Doc.E canonical = DocHelper.getElementWithTagName(doc, TAG); doc.deleteNode(canonical); }
/** * Deletes all non-canonical elements from the document. */ private void cleanup() { Doc.E canonical = findCanonicalElement(); Doc.E toDelete = DocHelper.getLastElementWithTagName(getDocument(), valueTagName, container); while (toDelete != canonical) { getDocument().deleteNode(toDelete); toDelete = DocHelper.getLastElementWithTagName(getDocument(), valueTagName, container); } }
/** * Test that child listeners are called as appropriate. */ @SuppressWarnings("unchecked") public void testChildListeners() { DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); ElementListener<Doc.E> elmListenerOne = mock(ElementListener.class); ElementListener<Doc.E> elmListenerTwo = mock(ElementListener.class); router.addChildListener(elmOne, elmListenerOne); router.addChildListener(elmTwo, elmListenerTwo); Doc.E childOne = realDoc.createChildElement(elmOne, "x", noAttribs()); verify(elmListenerOne).onElementAdded(childOne); verify(elmListenerTwo, never()).onElementAdded(anyElement()); Doc.E childTwo = realDoc.createChildElement(elmTwo, "y", noAttribs()); verify(elmListenerOne).onElementAdded(childOne); verify(elmListenerTwo).onElementAdded(childTwo); realDoc.deleteNode(childTwo); verify(elmListenerOne, never()).onElementRemoved(anyElement()); verify(elmListenerTwo).onElementRemoved(childTwo); realDoc.deleteNode(childOne); verify(elmListenerOne).onElementRemoved(childOne); verify(elmListenerTwo).onElementRemoved(childTwo); verifyNoMoreInteractions(elmListenerOne); verifyNoMoreInteractions(elmListenerTwo); }
/** * Test that child listeners are called as appropriate. */ @SuppressWarnings("unchecked") public void testChildListeners() { DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); ElementListener<Doc.E> elmListenerOne = mock(ElementListener.class); ElementListener<Doc.E> elmListenerTwo = mock(ElementListener.class); router.addChildListener(elmOne, elmListenerOne); router.addChildListener(elmTwo, elmListenerTwo); Doc.E childOne = realDoc.createChildElement(elmOne, "x", noAttribs()); verify(elmListenerOne).onElementAdded(childOne); verify(elmListenerTwo, never()).onElementAdded(anyElement()); Doc.E childTwo = realDoc.createChildElement(elmTwo, "y", noAttribs()); verify(elmListenerOne).onElementAdded(childOne); verify(elmListenerTwo).onElementAdded(childTwo); realDoc.deleteNode(childTwo); verify(elmListenerOne, never()).onElementRemoved(anyElement()); verify(elmListenerTwo).onElementRemoved(childTwo); realDoc.deleteNode(childOne); verify(elmListenerOne).onElementRemoved(childOne); verify(elmListenerTwo).onElementRemoved(childTwo); verifyNoMoreInteractions(elmListenerOne); verifyNoMoreInteractions(elmListenerTwo); }
private void remoteClearValue() { Doc.E toDelete = DocHelper.getLastElementWithTagName(doc, TAG, doc.getDocumentElement()); while (toDelete != null) { doc.deleteNode(toDelete); toDelete = DocHelper.getLastElementWithTagName(doc, TAG, doc.getDocumentElement()); } }
private void remoteClearValue() { Doc.E toDelete = DocHelper.getLastElementWithTagName(doc, TAG, doc.getDocumentElement()); while (toDelete != null) { doc.deleteNode(toDelete); toDelete = DocHelper.getLastElementWithTagName(doc, TAG, doc.getDocumentElement()); } }
/** * Test that only the root of a deletion is given child notifications, not * children of parents that are themselves being deleted. */ @SuppressWarnings("unchecked") public void testRecursiveDeletion() { Doc.E parent = elmOne; final Doc.E child = realDoc.createChildElement(parent, "c", noAttribs()); Doc.E grandChild = realDoc.createChildElement(child, "d", noAttribs()); DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); ElementListener<Doc.E> childRemovedListener = mock(ElementListener.class); router.addChildListener(parent, childRemovedListener); ElementListener<Doc.E> grandChildRemovedListener = mock(ElementListener.class); router.addChildListener(child, grandChildRemovedListener); realDoc.deleteNode(child); verify(childRemovedListener).onElementRemoved(same(child)); verifyNoMoreInteractions(childRemovedListener); verifyZeroInteractions(grandChildRemovedListener); }
/** * Test that only the root of a deletion is given child notifications, not * children of parents that are themselves being deleted. */ @SuppressWarnings("unchecked") public void testRecursiveDeletion() { Doc.E parent = elmOne; final Doc.E child = realDoc.createChildElement(parent, "c", noAttribs()); Doc.E grandChild = realDoc.createChildElement(child, "d", noAttribs()); DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); ElementListener<Doc.E> childRemovedListener = mock(ElementListener.class); router.addChildListener(parent, childRemovedListener); ElementListener<Doc.E> grandChildRemovedListener = mock(ElementListener.class); router.addChildListener(child, grandChildRemovedListener); realDoc.deleteNode(child); verify(childRemovedListener).onElementRemoved(same(child)); verifyNoMoreInteractions(childRemovedListener); verifyZeroInteractions(grandChildRemovedListener); }
private void remoteRemoveRedundantValues() { Doc.E canonical = DocHelper.getElementWithTagName(doc, TAG); Doc.E toDelete = DocHelper.getLastElementWithTagName(doc, TAG, doc.getDocumentElement()); while (toDelete != canonical) { doc.deleteNode(toDelete); toDelete = DocHelper.getLastElementWithTagName(doc, TAG, doc.getDocumentElement()); } }
private void remoteRemoveRedundantValues() { Doc.E canonical = DocHelper.getElementWithTagName(doc, TAG); Doc.E toDelete = DocHelper.getLastElementWithTagName(doc, TAG, doc.getDocumentElement()); while (toDelete != canonical) { doc.deleteNode(toDelete); toDelete = DocHelper.getLastElementWithTagName(doc, TAG, doc.getDocumentElement()); } }
/** * Test that removing a node removes all associated listeners and, if possible, * unregisters the router from the document. */ @SuppressWarnings("unchecked") public void testRemoveListenersWhenDeleted() { assertEquals(0, docListeners.size()); DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); assertEquals(0, docListeners.size()); router.addAttributeListener(elmOne, mock(AttributeListener.class)); router.addAttributeListener(elmOne, mock(AttributeListener.class)); router.addDeletionListener(elmOne, mock(DeletionListener.class)); router.addDeletionListener(elmOne, mock(DeletionListener.class)); router.addChildListener(elmOne, mock(ElementListener.class)); router.addChildListener(elmOne, mock(ElementListener.class)); assertEquals(1, docListeners.size()); realDoc.deleteNode(elmOne); assertEquals(0, docListeners.size()); }
/** * Test that removing a node removes all associated listeners and, if possible, * unregisters the router from the document. */ @SuppressWarnings("unchecked") public void testRemoveListenersWhenDeleted() { assertEquals(0, docListeners.size()); DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); assertEquals(0, docListeners.size()); router.addAttributeListener(elmOne, mock(AttributeListener.class)); router.addAttributeListener(elmOne, mock(AttributeListener.class)); router.addDeletionListener(elmOne, mock(DeletionListener.class)); router.addDeletionListener(elmOne, mock(DeletionListener.class)); router.addChildListener(elmOne, mock(ElementListener.class)); router.addChildListener(elmOne, mock(ElementListener.class)); assertEquals(1, docListeners.size()); realDoc.deleteNode(elmOne); assertEquals(0, docListeners.size()); }
DeletionListener deleteListenerTwo = mock(DeletionListener.class); router.addDeletionListener(elmTwo, deleteListenerTwo); realDoc.deleteNode(elmTwo); verify(deleteListenerOne, never()).onDeleted(); verify(deleteListenerTwo).onDeleted(); realDoc.deleteNode(elmOne); verify(deleteListenerOne).onDeleted(); verify(deleteListenerTwo).onDeleted();
DeletionListener deleteListenerTwo = mock(DeletionListener.class); router.addDeletionListener(elmTwo, deleteListenerTwo); realDoc.deleteNode(elmTwo); verify(deleteListenerOne, never()).onDeleted(); verify(deleteListenerTwo).onDeleted(); realDoc.deleteNode(elmOne); verify(deleteListenerOne).onDeleted(); verify(deleteListenerTwo).onDeleted();
util.reg = router.addChildListener(parent, util); assertEquals(0, util.removeCallCount); realDoc.deleteNode(childTwo); assertEquals(1, util.removeCallCount); realDoc.deleteNode(childOne); assertEquals(1, util.removeCallCount);
util.reg = router.addChildListener(parent, util); assertEquals(0, util.removeCallCount); realDoc.deleteNode(childTwo); assertEquals(1, util.removeCallCount); realDoc.deleteNode(childOne); assertEquals(1, util.removeCallCount);