Skip to content

Commit

Permalink
[test] improve TableViewerTest eclipse-platform#1005
Browse files Browse the repository at this point in the history
move "fViewer.getControl().update();" to front
eclipse-platform#1005
  • Loading branch information
EcljpseB0T committed Dec 7, 2023
1 parent 8abe1b1 commit d802377
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.junit.Assert.assertTrue;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Collectors;

import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ColumnViewer;
Expand Down Expand Up @@ -196,14 +198,23 @@ public void testRemove() {
@Test
public void testContains() {
TableViewer tViewer = (TableViewer) fViewer;
fViewer.getControl().update();
String elements = toString(tViewer);
// some random element.
assertFalse("element must not be available on the viewer", tViewer.contains(""));
assertFalse("random element must not be available on the viewer. All Elements: " + elements,
tViewer.contains(""));

// first child of root.
assertTrue("element must be available on the viewer", tViewer.contains(fRootElement.getFirstChild()));
assertTrue("first element must be available on the viewer. All Elements: " + elements,
tViewer.contains(fRootElement.getFirstChild()));

// last child of the root
assertTrue("element must be available on the viewer", tViewer.contains(fRootElement.getLastChild()));
assertTrue("last element must be available on the viewer. All Elements: " + elements,
tViewer.contains(fRootElement.getLastChild()));
}

String toString(TableViewer viewer) {
TableItem[] items = viewer.getTable().getItems();
return Arrays.asList(items).stream().map(item -> item.getText()).collect(Collectors.joining(",", "'", "'"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,16 @@ public void testRenameWithSorter() {
// Call update to make sure the viewer is in a correct state
// At least on MacOSX I get failures without this call
((TableViewer) fViewer).getControl().update();
assertEquals("unsorted", "0-0 name-0", getItemText(0));
fViewer.setComparator(new TestLabelComparator());
assertEquals("sorted", "0-9 name-9", getItemText(0));
((TableViewer) fViewer).getControl().update(); // before getFirstChild()!
TestElement first = fRootElement.getFirstChild();
first.setLabel("name-9999");
String newElementLabel = first.toString();
((TableViewer) fViewer).getControl().update();
assertEquals("sorted first", newElementLabel, getItemText(0));
assertEquals("label updated", "0-0 name-9999", newElementLabel);
((TableViewer) fViewer).getControl().update(); // before getItemText()!
assertEquals("item updated", "0-0 name-9999", getItemText(0));
}

@Override
Expand Down

0 comments on commit d802377

Please sign in to comment.