/** * Inserts a last-child element. */ private void remoteInsertRedundantValue(String value) { doc.createChildElement(doc.getDocumentElement(), TAG, CollectionUtils.immutableMap(ATTR, value)); }
/** * Inserts a last-child element. */ private void remoteInsertRedundantValue(String value) { doc.createChildElement(doc.getDocumentElement(), TAG, CollectionUtils.immutableMap(ATTR, value)); }
/** * 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); }
super.setUp(); this.realDoc = createDocument(); elmOne = realDoc.createChildElement(realDoc.getDocumentElement(), "a", noAttribs()); elmTwo = realDoc.createChildElement(realDoc.getDocumentElement(), "b", noAttribs()); this.doc = spy(realDoc); doAnswer(new Answer<Void>() {
/** * 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); }
super.setUp(); this.realDoc = createDocument(); elmOne = realDoc.createChildElement(realDoc.getDocumentElement(), "a", noAttribs()); elmTwo = realDoc.createChildElement(realDoc.getDocumentElement(), "b", noAttribs()); this.doc = spy(realDoc); doAnswer(new Answer<Void>() {
/** * 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); }
Doc.E childOne = realDoc.createChildElement(parent, "a", noAttribs()); Doc.E childTwo = realDoc.createChildElement(parent, "b", noAttribs()); DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); SelfRemovalListener util = new SelfRemovalListener();
Doc.E childOne = realDoc.createChildElement(parent, "a", noAttribs()); Doc.E childTwo = realDoc.createChildElement(parent, "b", noAttribs()); DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); SelfRemovalListener util = new SelfRemovalListener();