Skip to content

Commit ea02800

Browse files
Christopher-HermannBeckerWdf
authored andcommitted
[Sticky Scrolling] Fix instable test
Asserting on magic number for the control width is very error prone. To avoid this problem, it's asserted that the control is resized.
1 parent c1f4567 commit ea02800

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

tests/org.eclipse.ui.editors.tests/src/org/eclipse/ui/internal/texteditor/stickyscroll/StickyScrollingControlTest.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.hamcrest.Matchers.greaterThan;
1818
import static org.junit.Assert.assertEquals;
1919
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertNotEquals;
2021

2122
import java.util.List;
2223

@@ -31,13 +32,13 @@
3132
import org.eclipse.swt.graphics.Font;
3233
import org.eclipse.swt.graphics.FontData;
3334
import org.eclipse.swt.graphics.Point;
35+
import org.eclipse.swt.graphics.Rectangle;
3436
import org.eclipse.swt.layout.FillLayout;
3537
import org.eclipse.swt.widgets.Canvas;
3638
import org.eclipse.swt.widgets.Composite;
3739
import org.eclipse.swt.widgets.Control;
3840
import org.eclipse.swt.widgets.Display;
3941
import org.eclipse.swt.widgets.Event;
40-
import org.eclipse.swt.widgets.ScrollBar;
4142
import org.eclipse.swt.widgets.Shell;
4243

4344
import org.eclipse.jface.text.Document;
@@ -176,18 +177,21 @@ public void testLayoutStickyLinesCanvasOnResize() {
176177
stickyScrollingControl.setStickyLines(stickyLines);
177178

178179
Canvas stickyControlCanvas = getStickyControlCanvas(shell);
179-
assertEquals(0, stickyControlCanvas.getBounds().x);
180-
assertEquals(0, stickyControlCanvas.getBounds().y);
181-
assertEquals(getExpectedWitdh(200), stickyControlCanvas.getBounds().width);
182-
assertThat(stickyControlCanvas.getBounds().height, greaterThan(0));
180+
Rectangle boundsBeforeResize = stickyControlCanvas.getBounds();
181+
assertEquals(0, boundsBeforeResize.x);
182+
assertEquals(0, boundsBeforeResize.y);
183+
assertThat(boundsBeforeResize.width, greaterThan(0));
184+
assertThat(boundsBeforeResize.height, greaterThan(0));
183185

184186
sourceViewer.getTextWidget().setBounds(0, 0, 150, 200);
185187

186188
stickyControlCanvas = getStickyControlCanvas(shell);
187-
assertEquals(0, stickyControlCanvas.getBounds().x);
188-
assertEquals(0, stickyControlCanvas.getBounds().y);
189-
assertEquals(getExpectedWitdh(150), stickyControlCanvas.getBounds().width);
190-
assertThat(stickyControlCanvas.getBounds().height, greaterThan(0));
189+
Rectangle boundsAfterResize = stickyControlCanvas.getBounds();
190+
assertEquals(0, boundsAfterResize.x);
191+
assertEquals(0, boundsAfterResize.y);
192+
assertThat(boundsAfterResize.width, greaterThan(0));
193+
assertNotEquals(boundsAfterResize.width, boundsBeforeResize.width);
194+
assertEquals(boundsAfterResize.height, boundsBeforeResize.height);
191195
}
192196

193197
@Test
@@ -268,13 +272,4 @@ private StyledText getStickyLineText() {
268272
return (StyledText) canvas.getChildren()[1];
269273
}
270274

271-
private int getExpectedWitdh(int textWidgetWitdth) {
272-
ScrollBar verticalBar = sourceViewer.getTextWidget().getVerticalBar();
273-
if (verticalBar.isVisible()) {
274-
return textWidgetWitdth - verticalBar.getSize().x + 1;
275-
} else {
276-
return textWidgetWitdth + 1;
277-
}
278-
}
279-
280275
}

0 commit comments

Comments
 (0)