/** * Test that only the root of an insertion is given child notifications. */ @SuppressWarnings("unchecked") // Generic mocks. public void testRecursiveInsertion() { final Doc.E parent = elmOne; final DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); final ElementListener<Doc.E> childListener = mock(ElementListener.class); ElementListener<Doc.E> parentListener = mock(ElementListener.class); final ElementListener<Doc.E> secondParentListener = mock(ElementListener.class); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) throws Throwable { Doc.E child = (Doc.E) invocation.getArguments()[0]; router.addChildListener(child, childListener); router.addChildListener(parent, secondParentListener); return null; } }).when(parentListener).onElementAdded(anyElement()); router.addChildListener(parent, parentListener); Doc.E child = doc.insertXml(Point.start(doc, parent), XmlStringBuilder.createEmpty().wrap("a").wrap("b")); verify(parentListener).onElementAdded(child); verifyNoMoreInteractions(parentListener); verifyZeroInteractions(childListener); verifyZeroInteractions(secondParentListener); }
/** * Test that only the root of an insertion is given child notifications. */ @SuppressWarnings("unchecked") // Generic mocks. public void testRecursiveInsertion() { final Doc.E parent = elmOne; final DocumentEventRouter<Doc.N, Doc.E, ?> router = createRouter(doc); final ElementListener<Doc.E> childListener = mock(ElementListener.class); ElementListener<Doc.E> parentListener = mock(ElementListener.class); final ElementListener<Doc.E> secondParentListener = mock(ElementListener.class); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) throws Throwable { Doc.E child = (Doc.E) invocation.getArguments()[0]; router.addChildListener(child, childListener); router.addChildListener(parent, secondParentListener); return null; } }).when(parentListener).onElementAdded(anyElement()); router.addChildListener(parent, parentListener); Doc.E child = doc.insertXml(Point.start(doc, parent), XmlStringBuilder.createEmpty().wrap("a").wrap("b")); verify(parentListener).onElementAdded(child); verifyNoMoreInteractions(parentListener); verifyZeroInteractions(childListener); verifyZeroInteractions(secondParentListener); }