Skip to content

Commit

Permalink
Unify event triggering in ContentProviderTests3
Browse files Browse the repository at this point in the history
Currently non trivial code is used in ContentProviderTests3 to trigger a
delta event in 5 places. In one of them it is even done wrong where the
assert is part of the eventloop because of missing brackets.
  • Loading branch information
laeubi committed Jan 10, 2025
1 parent d0cf1a5 commit 29344f6
Showing 1 changed file with 15 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,30 +200,31 @@ public void testGetParentMidLevelFragment() throws Exception{
public void testDeleteBottomLevelFragmentFolding() throws Exception {

//send a delta indicating fragment deleted
IElementChangedListener listener= (IElementChangedListener) fProvider;
IJavaElementDelta delta= TestDelta.createDelta(fPack4, IJavaElementDelta.REMOVED);
listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));

//force events from dispaly
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch())
sendEvent(delta);

assertTrue(fMyPart.hasRefreshHappened(), "Refresh happened"); //$NON-NLS-1$
assertTrue(fMyPart.wasObjectRefreshed(fRoot1), "Correct Refresh"); //$NON-NLS-1$
assertEquals(1, fMyPart.getRefreshedObject().size(), "Single refresh"); //$NON-NLS-1$
}

@Test
public void testAddBottomLevelFragmentFolding() throws Exception {
IPackageFragment test= fRoot1.createPackageFragment("test", true, null); //$NON-NLS-1$

//send a delta indicating fragment deleted
protected void sendEvent(IJavaElementDelta delta) {
IElementChangedListener listener= (IElementChangedListener) fProvider;
IJavaElementDelta delta= TestDelta.createDelta(test, IJavaElementDelta.ADDED);
listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));

//force events from dispaly
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
}
}

@Test
public void testAddBottomLevelFragmentFolding() throws Exception {
IPackageFragment test= fRoot1.createPackageFragment("test", true, null); //$NON-NLS-1$

//send a delta indicating fragment deleted
IJavaElementDelta delta= TestDelta.createDelta(test, IJavaElementDelta.ADDED);
sendEvent(delta);

assertFalse(fMyPart.hasAddHappened(), "No add happened"); //$NON-NLS-1$
assertTrue(fMyPart.hasRefreshHappened(), "Refresh happened"); //$NON-NLS-1$
Expand All @@ -234,27 +235,17 @@ public void testAddBottomLevelFragmentFolding() throws Exception {
@Test
public void testChangedTopLevelPackageFragmentFolding() throws Exception {
//send a delta indicating fragment deleted
IElementChangedListener listener= (IElementChangedListener) fProvider;
IJavaElementDelta delta= TestDelta.createDelta(fPack3, IJavaElementDelta.CHANGED);
listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));

//force events from dispaly
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
}
sendEvent(delta);

assertEquals(0, fMyPart.getRefreshedObject().size(), "No refreshs"); //$NON-NLS-1$
}

@Test
public void testChangeBottomLevelPackageFragmentFolding() throws Exception {
//send a delta indicating fragment deleted
IElementChangedListener listener= (IElementChangedListener) fProvider;
IJavaElementDelta delta= TestDelta.createDelta(fPack6, IJavaElementDelta.CHANGED);
listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));

//force events from dispaly
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
}
sendEvent(delta);

assertEquals(0,fMyPart.getRefreshedObject().size(), "No refreshs"); //$NON-NLS-1$
}
Expand All @@ -263,13 +254,8 @@ public void testChangeBottomLevelPackageFragmentFolding() throws Exception {
public void testRemoveCUsFromPackageFragment() throws Exception{

//send a delta indicating fragment deleted
IElementChangedListener listener= (IElementChangedListener) fProvider;
IJavaElementDelta delta= TestDelta.createCUDelta(new ICompilationUnit[] { fCU2, fCU3 }, fPack6, IJavaElementDelta.REMOVED);
listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));

//force events from display
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
}
sendEvent(delta);

// removing more than one CU now results in a refresh.
assertEquals(1, fMyPart.getRefreshedObject().size(), "One refresh"); //$NON-NLS-1$
Expand All @@ -279,13 +265,8 @@ public void testRemoveCUsFromPackageFragment() throws Exception{
public void testRemoveCUFromPackageFragment() throws Exception {

//send a delta indicating fragment deleted
IElementChangedListener listener= (IElementChangedListener) fProvider;
IJavaElementDelta delta= TestDelta.createCUDelta(new ICompilationUnit[]{fCU2}, fPack6, IJavaElementDelta.REMOVED);
listener.elementChanged(new ElementChangedEvent(delta, ElementChangedEvent.POST_CHANGE));

//force events from display
while(fMyPart.getTreeViewer().getControl().getDisplay().readAndDispatch()) {
}
sendEvent(delta);

assertTrue(fMyPart.hasRemoveHappened(), "Remove happened"); //$NON-NLS-1$
assertTrue(fMyPart.getRemovedObjects().contains(fCU2), "Correct refresh"); //$NON-NLS-1$
Expand Down

0 comments on commit 29344f6

Please sign in to comment.